From d930dcd9fa19c8fb8f8ced12a3d96bd488f8bb4f Mon Sep 17 00:00:00 2001 From: Anton Chekulaev Date: Wed, 26 Aug 2020 23:12:01 +1000 Subject: [PATCH] Manual day night switch button for settings activity. --- res/drawable/ic_baseline_palette_24.xml | 10 +++++ res/layout/activity_settings.xml | 11 ----- res/menu/settings_general.xml | 6 +++ .../loki/activities/SettingsActivity.kt | 41 +++++++++---------- 4 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 res/drawable/ic_baseline_palette_24.xml diff --git a/res/drawable/ic_baseline_palette_24.xml b/res/drawable/ic_baseline_palette_24.xml new file mode 100644 index 0000000000..4bf1550859 --- /dev/null +++ b/res/drawable/ic_baseline_palette_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/res/layout/activity_settings.xml b/res/layout/activity_settings.xml index 25ff078486..b1e5f4df2b 100644 --- a/res/layout/activity_settings.xml +++ b/res/layout/activity_settings.xml @@ -111,17 +111,6 @@ android:layout_marginTop="@dimen/large_spacing" android:background="?android:dividerHorizontal" /> - - + + = Build.VERSION_CODES.Q) + return true } @@ -115,7 +112,19 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { return when (item.itemId) { R.id.action_qr_code -> { showQRCode() - return true + true + } + R.id.action_change_theme -> { + // A temporary demo code that manually switches between day/night themes. + // The effect is reset after the app restart. + val currentUiMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val nightMode: Int = when(currentUiMode) { + Configuration.UI_MODE_NIGHT_YES -> AppCompatDelegate.MODE_NIGHT_NO + else -> AppCompatDelegate.MODE_NIGHT_YES + } + AppCompatDelegate.setDefaultNightMode(nightMode) + recreate() + true } else -> super.onOptionsItemSelected(item) } @@ -288,18 +297,6 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() { } // endregion - //TODO Remove it. - private fun isDarkTheme(): Boolean { - val themeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - return themeFlag == Configuration.UI_MODE_NIGHT_YES; - } - - //TODO Remove it. - private fun setDarkTheme(darkTheme: Boolean) { -// AppCompatDelegate.setDefaultNightMode(if (darkTheme) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO ) - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) - } - private inner class DisplayNameEditActionModeCallback: ActionMode.Callback { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {