diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java')
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java index 27ce4fc7..ccc046cf 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java @@ -1,24 +1,34 @@ package it.niedermann.owncloud.notes.android.fragment; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.util.Log; +import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.DarkModeSetting; +import it.niedermann.owncloud.notes.branding.Branded; +import it.niedermann.owncloud.notes.branding.BrandedSwitchPreference; +import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.persistence.SyncWorker; import it.niedermann.owncloud.notes.util.DeviceCredentialUtil; import it.niedermann.owncloud.notes.util.Notes; -public class PreferencesFragment extends PreferenceFragmentCompat { +public class PreferencesFragment extends PreferenceFragmentCompat implements Branded { private static final String TAG = PreferencesFragment.class.getSimpleName(); + private BrandedSwitchPreference fontPref; + private BrandedSwitchPreference lockPref; + private BrandedSwitchPreference wifiOnlyPref; + private BrandedSwitchPreference brandingPref; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -28,10 +38,26 @@ public class PreferencesFragment extends PreferenceFragmentCompat { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.preferences); - final SwitchPreference lockPref = findPreference(getString(R.string.pref_key_lock)); + fontPref = findPreference(getString(R.string.pref_key_font)); + + brandingPref = findPreference(getString(R.string.pref_key_branding)); + if (brandingPref != null) { + brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { + final Boolean branding = (Boolean) newValue; + Log.v(TAG, "branding: " + branding); + requireActivity().setResult(Activity.RESULT_OK); + requireActivity().recreate(); + return true; + }); + } else { + Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\""); + } + + lockPref = findPreference(getString(R.string.pref_key_lock)); if (lockPref != null) { if (!DeviceCredentialUtil.areCredentialsAvailable(requireContext())) { lockPref.setVisible(false); + findPreference(getString(R.string.pref_category_security)).setVisible(false); } else { lockPref.setOnPreferenceChangeListener((preference, newValue) -> { Notes.setLockedPreference((Boolean) newValue); @@ -51,7 +77,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat { return true; }); - final SwitchPreference wifiOnlyPref = findPreference(getString(R.string.pref_key_wifi_only)); + wifiOnlyPref = findPreference(getString(R.string.pref_key_wifi_only)); assert wifiOnlyPref != null; wifiOnlyPref.setOnPreferenceChangeListener((preference, newValue) -> { Log.i(TAG, "syncOnWifiOnly: " + newValue); @@ -66,4 +92,24 @@ public class PreferencesFragment extends PreferenceFragmentCompat { return true; }); } + + + @Override + public void onStart() { + super.onStart(); + @Nullable Context context = getContext(); + if (context != null) { + @ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context); + @ColorInt final int textColor = BrandingUtil.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + } + + @Override + public void applyBrand(int mainColor, int textColor) { + fontPref.applyBrand(mainColor, textColor); + lockPref.applyBrand(mainColor, textColor); + wifiOnlyPref.applyBrand(mainColor, textColor); + brandingPref.applyBrand(mainColor, textColor); + } } |