diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java index cc01781e6..79a03ab71 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java @@ -1,7 +1,5 @@ package it.niedermann.nextcloud.deck.ui.settings; -import static it.niedermann.nextcloud.deck.DeckApplication.setAppTheme; - import android.app.Activity; import android.os.Bundle; import android.view.View; @@ -9,10 +7,13 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; +import androidx.lifecycle.ViewModelProvider; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import it.niedermann.nextcloud.deck.DeckApplication; +import java.util.stream.Stream; + +import it.niedermann.android.reactivelivedata.ReactiveLiveData; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.persistence.sync.SyncWorker; @@ -20,6 +21,7 @@ import it.niedermann.nextcloud.deck.ui.theme.ThemedSwitchPreference; public class SettingsFragment extends PreferenceFragmentCompat { + private PreferencesViewModel preferencesViewModel; private ThemedSwitchPreference wifiOnlyPref; private ThemedSwitchPreference compactPref; private ThemedSwitchPreference coverImagesPref; @@ -31,6 +33,8 @@ public class SettingsFragment extends PreferenceFragmentCompat { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.settings, rootKey); + preferencesViewModel = new ViewModelProvider(requireActivity()).get(PreferencesViewModel.class); + wifiOnlyPref = findPreference(getString(R.string.pref_key_wifi_only)); coverImagesPref = findPreference(getString(R.string.pref_key_cover_images)); compactPref = findPreference(getString(R.string.pref_key_compact)); @@ -61,7 +65,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { final var themePref = findPreference(getString(R.string.pref_key_dark_theme)); if (themePref != null) { themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { - setAppTheme(Integer.parseInt((String) newValue)); + preferencesViewModel.setAppTheme(Integer.parseInt((String) newValue)); requireActivity().setResult(Activity.RESULT_OK); ActivityCompat.recreate(requireActivity()); return true; @@ -75,13 +79,15 @@ public class SettingsFragment extends PreferenceFragmentCompat { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - DeckApplication.readCurrentAccountColor().observe(getViewLifecycleOwner(), (mainColor) -> { - wifiOnlyPref.applyTheme(mainColor); - compactPref.applyTheme(mainColor); - coverImagesPref.applyTheme(mainColor); - compressImageAttachmentsPref.applyTheme(mainColor); - debuggingPref.applyTheme(mainColor); - eTagPref.applyTheme(mainColor); - }); + new ReactiveLiveData<>(preferencesViewModel.getCurrentAccountId$()) + .flatMap(preferencesViewModel::getAccountColor) + .observe(getViewLifecycleOwner(), color -> Stream.of( + wifiOnlyPref, + compactPref, + coverImagesPref, + compressImageAttachmentsPref, + debuggingPref, + eTagPref) + .forEach(pref -> pref.applyTheme(color))); } } |