Search in sources :

Example 1 with DarkMode

use of com.nextcloud.client.preferences.DarkMode in project android by nextcloud.

the class SettingsActivity method setupGeneralCategory.

private void setupGeneralCategory(int accentColor) {
    PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
    preferenceCategoryGeneral.setTitle(ThemeTextUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor));
    prefStoragePath = (ListPreference) findPreference(AppPreferencesImpl.STORAGE_PATH);
    if (prefStoragePath != null) {
        StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
        String[] entries = new String[storageOptions.length];
        String[] values = new String[storageOptions.length];
        for (int i = 0; i < storageOptions.length; ++i) {
            entries[i] = storageOptions[i].getDescription();
            values[i] = storageOptions[i].getPath();
        }
        prefStoragePath.setEntries(entries);
        prefStoragePath.setEntryValues(values);
        prefStoragePath.setOnPreferenceChangeListener((preference, newValue) -> {
            String newPath = (String) newValue;
            if (storagePath.equals(newPath)) {
                return true;
            }
            StorageMigration storageMigration = new StorageMigration(this, user, storagePath, newPath);
            storageMigration.setStorageMigrationProgressListener(this);
            storageMigration.migrate();
            return false;
        });
    }
    loadStoragePath();
    ListPreference themePref = (ListPreference) findPreference("darkMode");
    List<String> themeEntries = new ArrayList<>(3);
    themeEntries.add(getString(R.string.prefs_value_theme_light));
    themeEntries.add(getString(R.string.prefs_value_theme_dark));
    themeEntries.add(getString(R.string.prefs_value_theme_system));
    List<String> themeValues = new ArrayList<>(3);
    themeValues.add(DarkMode.LIGHT.name());
    themeValues.add(DarkMode.DARK.name());
    themeValues.add(DarkMode.SYSTEM.name());
    themePref.setEntries(themeEntries.toArray(new String[0]));
    themePref.setEntryValues(themeValues.toArray(new String[0]));
    if (TextUtils.isEmpty(themePref.getEntry())) {
        themePref.setValue(DarkMode.SYSTEM.name());
        themePref.setSummary(TextUtils.isEmpty(themePref.getEntry()) ? DarkMode.SYSTEM.name() : themePref.getEntry());
    }
    themePref.setOnPreferenceChangeListener((preference, newValue) -> {
        DarkMode mode = DarkMode.valueOf((String) newValue);
        preferences.setDarkThemeMode(mode);
        MainApp.setAppTheme(mode);
        return true;
    });
}
Also used : DarkMode(com.nextcloud.client.preferences.DarkMode) PreferenceCategory(android.preference.PreferenceCategory) StoragePoint(com.owncloud.android.datastorage.StoragePoint) ArrayList(java.util.ArrayList) ListPreference(android.preference.ListPreference) StoragePoint(com.owncloud.android.datastorage.StoragePoint)

Aggregations

ListPreference (android.preference.ListPreference)1 PreferenceCategory (android.preference.PreferenceCategory)1 DarkMode (com.nextcloud.client.preferences.DarkMode)1 StoragePoint (com.owncloud.android.datastorage.StoragePoint)1 ArrayList (java.util.ArrayList)1