From ae80a27db95b0701a8621bfb158ece2c95720823 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 9 Dec 2022 10:01:57 +0100 Subject: [PATCH] Allow to reset customizations --- app/build.gradle | 2 +- .../android/helper/SpannableHelper.java | 2 +- .../settings/FragmentThemingSettings.java | 35 +++++++++++++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_custom_dark.xml | 50 +++---------------- app/src/main/res/xml/pref_custom_light.xml | 49 +++--------------- app/src/main/res/xml/pref_theming.xml | 6 +++ 7 files changed, 59 insertions(+), 87 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3e592ea7..50d97fa2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,7 +82,7 @@ dependencies { implementation 'com.google.android.material:material:1.7.0' - implementation "com.github.skydoves:colorpickerpreference:2.0.6" + implementation 'com.jaredrummler:colorpicker:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "com.google.code.gson:gson:2.9.1" diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index 1eb8492e..8db48cc4 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -121,7 +121,7 @@ public class SpannableHelper { linkColor = link_color; } } else { - linkColor = linkColor; + linkColor = ThemeHelper.getAttColor(context, R.attr.linkColor); } SpannableString initialContent; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java index 7141514a..b6b407e5 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java @@ -18,6 +18,7 @@ package app.fedilab.android.ui.fragment.settings; import android.content.SharedPreferences; import android.os.Bundle; +import androidx.appcompat.app.AlertDialog; import androidx.navigation.NavOptions; import androidx.navigation.Navigation; import androidx.preference.ListPreference; @@ -113,6 +114,40 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements return true; }); } + + Preference SET_RESET_CUSTOM_COLOR = findPreference(getString(R.string.SET_RESET_CUSTOM_COLOR)); + if (SET_RESET_CUSTOM_COLOR != null) { + SET_RESET_CUSTOM_COLOR.getContext().setTheme(Helper.dialogStyle()); + SET_RESET_CUSTOM_COLOR.setOnPreferenceClickListener(preference -> { + AlertDialog.Builder resetConfirm = new AlertDialog.Builder(requireActivity(), Helper.dialogStyle()); + resetConfirm.setMessage(getString(R.string.reset_color)); + resetConfirm.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss()); + resetConfirm.setPositiveButton(R.string.reset, (dialog, which) -> { + SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); + if (sharedPreferences != null) { + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_BACKGROUND)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_BOOST_HEADER)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_DISPLAY_NAME)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_USERNAME)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_TEXT)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_LINK)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_LIGHT_ICON)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_BACKGROUND)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_BOOST_HEADER)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_DISPLAY_NAME)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_USERNAME)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_TEXT)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_LINK)).apply(); + sharedPreferences.edit().remove(getString(R.string.SET_DARK_ICON)).apply(); + + } + + dialog.dismiss(); + }); + resetConfirm.show(); + return true; + }); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6a907bf..20d9ede7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1302,6 +1302,8 @@ SET_CUSTOMIZE_LIGHT_COLORS_ACTION SET_CUSTOMIZE_DARK_COLORS SET_CUSTOMIZE_DARK_COLORS_ACTION + SET_RESET_CUSTOM_COLOR + SET_THEME_DEFAULT_LIGHT SET_THEME_DEFAULT_DARK diff --git a/app/src/main/res/xml/pref_custom_dark.xml b/app/src/main/res/xml/pref_custom_dark.xml index f9135bf9..2d1c82f8 100644 --- a/app/src/main/res/xml/pref_custom_dark.xml +++ b/app/src/main/res/xml/pref_custom_dark.xml @@ -4,82 +4,46 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - diff --git a/app/src/main/res/xml/pref_custom_light.xml b/app/src/main/res/xml/pref_custom_light.xml index 70d33cc6..f33def95 100644 --- a/app/src/main/res/xml/pref_custom_light.xml +++ b/app/src/main/res/xml/pref_custom_light.xml @@ -4,82 +4,47 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - diff --git a/app/src/main/res/xml/pref_theming.xml b/app/src/main/res/xml/pref_theming.xml index f8ba554f..3751a455 100644 --- a/app/src/main/res/xml/pref_theming.xml +++ b/app/src/main/res/xml/pref_theming.xml @@ -86,4 +86,10 @@ app:iconSpaceReserved="false" app:key="@string/SET_CUSTOMIZE_DARK_COLORS_ACTION" /> +