From b158d0131159a6be92b0cdd56295e912f5f93024 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 10 Jul 2022 11:34:41 +0200 Subject: [PATCH] Allow to reset language --- .../settings/FragmentLanguageSettings.java | 17 ++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_language.xml | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentLanguageSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentLanguageSettings.java index 7e1961227..1f99ccaf9 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentLanguageSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentLanguageSettings.java @@ -14,11 +14,14 @@ package app.fedilab.android.ui.fragment.settings; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import android.annotation.SuppressLint; import android.content.SharedPreferences; import android.os.Bundle; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; import app.fedilab.android.R; import app.fedilab.android.helper.Helper; @@ -31,16 +34,28 @@ public class FragmentLanguageSettings extends PreferenceFragmentCompat implement createPref(); } + @SuppressLint("ApplySharedPref") private void createPref() { ListPreference SET_DEFAULT_LOCALE_NEW = findPreference(getString(R.string.SET_DEFAULT_LOCALE_NEW)); if (SET_DEFAULT_LOCALE_NEW != null) { SET_DEFAULT_LOCALE_NEW.getContext().setTheme(Helper.dialogStyle()); } + + Preference SET_TRANSLATE_VALUES_RESET = findPreference(getString(R.string.SET_TRANSLATE_VALUES_RESET)); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + if (SET_TRANSLATE_VALUES_RESET != null) { + SET_TRANSLATE_VALUES_RESET.setOnPreferenceClickListener(preference -> { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(getString(R.string.SET_DEFAULT_LOCALE_NEW), null); + editor.commit(); + return true; + }); + } } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.compareToIgnoreCase(getString(R.string.SET_DEFAULT_LOCALE_NEW)) == 0) { + if (key.compareToIgnoreCase(getString(R.string.SET_DEFAULT_LOCALE_NEW)) == 0 || key.compareToIgnoreCase(getString(R.string.SET_TRANSLATE_VALUES_RESET)) == 0) { requireActivity().recreate(); Helper.recreateMainActivity(requireActivity()); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 776a82e55..c50d34396 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -779,6 +779,7 @@ SET_FEATURED_TAG_ACTION SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL + SET_TRANSLATE_VALUES_RESET en fr @@ -978,6 +979,7 @@ File cache size Clear cache Are you sure you want to delete cache? If you have drafts with media, the attached media will be lost. + Use the default system language diff --git a/app/src/main/res/xml/pref_language.xml b/app/src/main/res/xml/pref_language.xml index c15f0f1b5..ae608822c 100644 --- a/app/src/main/res/xml/pref_language.xml +++ b/app/src/main/res/xml/pref_language.xml @@ -11,4 +11,10 @@ app:summary="@string/set_push_notifications" app:title="@string/set_change_locale" app:useSimpleSummaryProvider="true" /> + + \ No newline at end of file