|
70 | 70 | import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask; |
71 | 71 | import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment; |
72 | 72 | import com.owncloud.android.ui.helpers.FileOperationsHelper; |
| 73 | +import com.owncloud.android.ui.model.ExtendedSettingsActivityDialog; |
73 | 74 | import com.owncloud.android.utils.ClipboardUtil; |
74 | 75 | import com.owncloud.android.utils.DeviceCredentialUtils; |
75 | 76 | import com.owncloud.android.utils.DisplayUtils; |
|
80 | 81 | import com.owncloud.android.utils.theme.ViewThemeUtils; |
81 | 82 |
|
82 | 83 | import java.util.ArrayList; |
83 | | -import java.util.List; |
84 | 84 | import java.util.Objects; |
85 | 85 |
|
86 | 86 | import javax.inject.Inject; |
@@ -121,7 +121,6 @@ public class SettingsActivity extends PreferenceActivity |
121 | 121 | private static final int ACTION_REQUEST_CODE_DAVDROID_SETUP = 10; |
122 | 122 | private static final int ACTION_SHOW_MNEMONIC = 11; |
123 | 123 | private static final int ACTION_E2E = 12; |
124 | | - private static final int ACTION_SET_STORAGE_LOCATION = 13; |
125 | 124 | private static final int TRUE_VALUE = 1; |
126 | 125 |
|
127 | 126 | private static final String DAV_PATH = "/remote.php/dav"; |
@@ -879,41 +878,42 @@ private void setupGeneralCategory() { |
879 | 878 | prefDataLoc = findPreference(AppPreferencesImpl.DATA_STORAGE_LOCATION); |
880 | 879 | if (prefDataLoc != null) { |
881 | 880 | prefDataLoc.setOnPreferenceClickListener(p -> { |
882 | | - Intent intent = new Intent(MainApp.getAppContext(), ChooseStorageLocationActivity.class); |
883 | | - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); |
884 | | - startActivityForResult(intent, ACTION_SET_STORAGE_LOCATION); |
| 881 | + Intent intent = ExtendedSettingsActivity.Companion.createIntent(this, ExtendedSettingsActivityDialog.StorageLocation); |
| 882 | + startActivityForResult(intent, ExtendedSettingsActivityDialog.StorageLocation.getResultId()); |
885 | 883 | return true; |
886 | 884 | }); |
887 | 885 | } |
888 | 886 |
|
889 | | - ListPreference themePref = (ListPreference) findPreference("darkMode"); |
| 887 | + final var themePref = findPreference("darkMode"); |
| 888 | + if (themePref != null) { |
| 889 | + updateThemePreferenceSummary(preferences.getDarkThemeMode().name()); |
890 | 890 |
|
891 | | - List<String> themeEntries = new ArrayList<>(3); |
892 | | - themeEntries.add(getString(R.string.prefs_value_theme_light)); |
893 | | - themeEntries.add(getString(R.string.prefs_value_theme_dark)); |
894 | | - themeEntries.add(getString(R.string.prefs_value_theme_system)); |
895 | | - |
896 | | - List<String> themeValues = new ArrayList<>(3); |
897 | | - themeValues.add(DarkMode.LIGHT.name()); |
898 | | - themeValues.add(DarkMode.DARK.name()); |
899 | | - themeValues.add(DarkMode.SYSTEM.name()); |
| 891 | + themePref.setOnPreferenceClickListener(preference -> { |
| 892 | + Intent intent = ExtendedSettingsActivity.Companion.createIntent(this, ExtendedSettingsActivityDialog.ThemeSelection); |
| 893 | + startActivityForResult(intent, ExtendedSettingsActivityDialog.ThemeSelection.getResultId()); |
| 894 | + return true; |
| 895 | + }); |
| 896 | + } |
| 897 | + } |
900 | 898 |
|
901 | | - themePref.setEntries(themeEntries.toArray(new String[0])); |
902 | | - themePref.setEntryValues(themeValues.toArray(new String[0])); |
| 899 | + private void updateThemePreferenceSummary(String themeValue) { |
| 900 | + Preference themePref = findPreference("darkMode"); |
| 901 | + if (themePref == null) return; |
903 | 902 |
|
904 | | - if (TextUtils.isEmpty(themePref.getEntry())) { |
905 | | - themePref.setValue(DarkMode.SYSTEM.name()); |
906 | | - themePref.setSummary(TextUtils.isEmpty(themePref.getEntry()) ? DarkMode.SYSTEM.name() : themePref.getEntry()); |
| 903 | + DarkMode mode; |
| 904 | + try { |
| 905 | + mode = DarkMode.valueOf(themeValue); |
| 906 | + } catch (IllegalArgumentException e) { |
| 907 | + mode = DarkMode.SYSTEM; |
907 | 908 | } |
908 | 909 |
|
909 | | - themePref.setOnPreferenceChangeListener((preference, newValue) -> { |
910 | | - DarkMode mode = DarkMode.valueOf((String) newValue); |
911 | | - preferences.setDarkThemeMode(mode); |
912 | | - MainApp.setAppTheme(mode); |
913 | | - setListBackground(); |
| 910 | + String summary = switch (mode) { |
| 911 | + case LIGHT -> getString(R.string.prefs_value_theme_light); |
| 912 | + case DARK -> getString(R.string.prefs_value_theme_dark); |
| 913 | + default -> getString(R.string.prefs_value_theme_system); |
| 914 | + }; |
914 | 915 |
|
915 | | - return true; |
916 | | - }); |
| 916 | + themePref.setSummary(summary); |
917 | 917 | } |
918 | 918 |
|
919 | 919 | private void setListBackground() { |
@@ -1052,14 +1052,21 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
1052 | 1052 | } else if (requestCode == ACTION_E2E && data != null && data.getBooleanExtra(SetupEncryptionDialogFragment.SUCCESS, false)) { |
1053 | 1053 | Intent i = new Intent(this, SettingsActivity.class); |
1054 | 1054 | startActivity(i); |
1055 | | - } else if (requestCode == ACTION_SET_STORAGE_LOCATION && data != null) { |
1056 | | - String newPath = data.getStringExtra(ChooseStorageLocationActivity.KEY_RESULT_STORAGE_LOCATION); |
1057 | | - |
| 1055 | + } else if (requestCode == ExtendedSettingsActivityDialog.StorageLocation.getResultId() && data != null) { |
| 1056 | + String newPath = data.getStringExtra(ExtendedSettingsActivityDialog.StorageLocation.getKey()); |
1058 | 1057 | if (storagePath != null && !storagePath.equals(newPath)) { |
1059 | 1058 | StorageMigration storageMigration = new StorageMigration(this, user, storagePath, newPath, viewThemeUtils); |
1060 | 1059 | storageMigration.setStorageMigrationProgressListener(this); |
1061 | 1060 | storageMigration.migrate(); |
1062 | 1061 | } |
| 1062 | + } else if (requestCode == ExtendedSettingsActivityDialog.ThemeSelection.getResultId() && data != null) { |
| 1063 | + String selectedTheme = data.getStringExtra(ExtendedSettingsActivityDialog.ThemeSelection.getKey()); |
| 1064 | + if (selectedTheme != null) { |
| 1065 | + updateThemePreferenceSummary(selectedTheme); |
| 1066 | + |
| 1067 | + // needed for to change status bar color |
| 1068 | + recreate(); |
| 1069 | + } |
1063 | 1070 | } else if (requestCode == REQ_ALL_FILES_ACCESS) { |
1064 | 1071 | final PreferenceCategory preferenceCategorySync = (PreferenceCategory) findPreference("sync"); |
1065 | 1072 | setupAllFilesAccessPreference(preferenceCategorySync); |
|
0 commit comments