Commit b158d013 authored by Thomas's avatar Thomas
Browse files

Allow to reset language

parent a632618a
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -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 <http://www.gnu.org/licenses>. */

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());
        }
+2 −0
Original line number Diff line number Diff line
@@ -779,6 +779,7 @@
    <string name="SET_FEATURED_TAG_ACTION" translatable="false">SET_FEATURED_TAG_ACTION</string>
    <string name="SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL" translatable="false">SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL</string>

    <string name="SET_TRANSLATE_VALUES_RESET" translatable="false">SET_TRANSLATE_VALUES_RESET</string>
    <string-array name="SET_TRANSLATE_ENTRIES" translatable="false">
        <item>en</item>
        <item>fr</item>
@@ -978,6 +979,7 @@
    <string name="files_cache_size">File cache size</string>
    <string name="clear_cache">Clear cache</string>
    <string name="delete_cache_message">Are you sure you want to delete cache? If you have drafts with media, the attached media will be lost.</string>
    <string name="default_system_language">Use the default system language</string>

    <string-array name="photo_editor_emoji" translatable="false">
        <!--  Smiles  -->
+6 −0
Original line number Diff line number Diff line
@@ -11,4 +11,10 @@
        app:summary="@string/set_push_notifications"
        app:title="@string/set_change_locale"
        app:useSimpleSummaryProvider="true" />

    <Preference
        android:key="@string/SET_TRANSLATE_VALUES_RESET"
        android:summary="@string/default_system_language"
        android:title="@string/reset"
        app:iconSpaceReserved="false" />
</PreferenceScreen>
 No newline at end of file