diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 8c391422..5c89ab99 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -387,7 +387,8 @@ public class MainActivity extends BaseActivity key.equals(getString(R.string.settings_key_enable_screenshot)) || key.equals(getString(R.string.settings_key_tag_functionality)) || key.equals(getString(R.string.settings_key_label_highlight_token)) || - key.equals(getString(R.string.settings_key_card_layout))) { + key.equals(getString(R.string.settings_key_card_layout)) || + key.equals(getString(R.string.settings_key_theme_mode))) { recreate(); } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java index b2fd7f18..c015d7da 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java @@ -27,6 +27,7 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; @@ -123,7 +124,8 @@ public class SettingsActivity extends BaseActivity if (key.equals(getString(R.string.settings_key_theme)) || key.equals(getString(R.string.settings_key_locale)) || - key.equals(getString(R.string.settings_key_special_features))) { + key.equals(getString(R.string.settings_key_special_features)) || + key.equals(getString(R.string.settings_key_theme_mode))) { recreate(); } else if(key.equals(getString(R.string.settings_key_encryption))) { if (settings.getEncryption() != EncryptionType.PASSWORD) { @@ -240,6 +242,7 @@ public class SettingsActivity extends BaseActivity public static class SettingsFragment extends PreferenceFragment { PreferenceCategory catSecurity; + PreferenceCategory catUI; Settings settings; ListPreference encryption; @@ -249,6 +252,8 @@ public class SettingsActivity extends BaseActivity OpenPgpAppPreference pgpProvider; EditTextPreference pgpEncryptionKey; OpenPgpKeyPreference pgpSigningKey; + ListPreference themeMode; + ListPreference theme; public void encryptionChangeWithDialog(final EncryptionType encryptionType) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); @@ -292,7 +297,10 @@ public class SettingsActivity extends BaseActivity // Authentication catSecurity = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_security)); + catUI = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_ui)); encryption = (ListPreference) findPreference(getString(R.string.settings_key_encryption)); + themeMode = (ListPreference) findPreference(getString(R.string.settings_key_theme_mode)); + theme = (ListPreference) findPreference(getString(R.string.settings_key_theme)); encryption.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override @@ -395,11 +403,21 @@ public class SettingsActivity extends BaseActivity }); builder.create().show(); - return false; } }); } + //Remove Theme Mode selection option for devices below Android 10. Disable theme selection if Theme Mode is set auto + //TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29 + if(Build.VERSION.SDK_INT < 29) { + catUI.removePreference(themeMode); + } else { + if(sharedPref.getString(getString(R.string.settings_key_theme_mode),getString(R.string.settings_default_theme_mode)).equals("auto")) { + theme.setEnabled(false); + } else { + theme.setEnabled(true); + } + } } } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java index 909b4470..a6517bc2 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java @@ -24,6 +24,8 @@ package org.shadowice.flocke.andotp.Utilities; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; import android.preference.PreferenceManager; import android.util.Base64; @@ -332,16 +334,34 @@ public class Settings { } public int getTheme() { - String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme); - int theme = R.style.AppTheme_NoActionBar; + String themeMode = getString(R.string.settings_key_theme_mode, R.string.settings_default_theme_mode); - if (themeName.equals("light")) { - theme = R.style.AppTheme_NoActionBar; - } else if (themeName.equals("dark")) { - theme = R.style.AppTheme_Dark_NoActionBar; - } else if (themeName.equals("black")) { - theme = R.style.AppTheme_Black_NoActionBar; + //TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29 + if(Build.VERSION.SDK_INT >= 29 && themeMode.equals("auto")){ + switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) { + //Dark Mode + case Configuration.UI_MODE_NIGHT_YES: + theme = R.style.AppTheme_Dark_NoActionBar; + break; + //Light Mode / Undefined mode / Default mode + case Configuration.UI_MODE_NIGHT_NO: + case Configuration.UI_MODE_NIGHT_UNDEFINED: + default: + theme = R.style.AppTheme_NoActionBar; + break; + } + } else { + + String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme); + + if (themeName.equals("light")) { + theme = R.style.AppTheme_NoActionBar; + } else if (themeName.equals("dark")) { + theme = R.style.AppTheme_Dark_NoActionBar; + } else if (themeName.equals("black")) { + theme = R.style.AppTheme_Black_NoActionBar; + } } return theme; diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index a8f6f6ca..345c96d2 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -17,8 +17,10 @@ pref_panic pref_relock_screen_off + perf_cat_ui pref_lang pref_locale + perf_theme_mode pref_theme pref_label_size_sp pref_card_layout @@ -59,6 +61,7 @@ 30 keystore system + auto light 18 default @@ -131,6 +134,11 @@ zh_TW + + auto + manual + + light dark diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index 05396839..8eef0b71 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -18,6 +18,7 @@ Re-lock on screen off Language + Theme Mode Theme Card layout Label font size @@ -167,6 +168,11 @@ Tags + + Auto + Manual + + Light theme Dark theme diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 857415cf..cf076d48 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -51,7 +51,8 @@ + android:title="@string/settings_category_title_ui" + android:key="@string/settings_key_cat_ui"> + +