From 84ae6953da92ceb27fab4d0b7ac230da7d1209a7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Sep 2017 03:21:55 +0900 Subject: [PATCH] Hide language preference on Android 24+ (fixes #952) Reason copied from F-Droid: Android 24 and later provides tons of languages, and a way to rank multiple languages instead of choosing one. The Languages pref is a big hack and can be problematic, so its better to disable it when its not needed. This will make it so it is no longer possible to set F-Droid to a language that the system does not support. --- .../activities/SettingsActivity.java | 23 ++++++++++++------- .../syncthingandroid/util/Languages.java | 9 -------- src/main/res/xml/app_settings.xml | 1 + 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index e2331174..0ff66e29 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -4,11 +4,13 @@ import android.app.AlertDialog; import android.content.Intent; import android.content.pm.PackageManager; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; +import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.util.Log; @@ -106,14 +108,19 @@ public class SettingsActivity extends SyncthingActivity { mSyncOnlyOnSSIDs.setEnabled(mSyncOnlyWifi.isChecked()); ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE); - Languages languages = new Languages(getActivity()); - languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT); - languagePref.setEntries(languages.getAllNames()); - languagePref.setEntryValues(languages.getSupportedLocales()); - languagePref.setOnPreferenceChangeListener((p, o) -> { - languages.forceChangeLanguage(getActivity(), (String) o); - return false; - }); + if (Build.VERSION.SDK_INT >= 24) { + PreferenceScreen category = (PreferenceScreen) findPreference("category_behaviour"); + category.removePreference(languagePref); + } else { + Languages languages = new Languages(getActivity()); + languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT); + languagePref.setEntries(languages.getAllNames()); + languagePref.setEntryValues(languages.getSupportedLocales()); + languagePref.setOnPreferenceChangeListener((p, o) -> { + languages.forceChangeLanguage(getActivity(), (String) o); + return false; + }); + } mDeviceName = (EditTextPreference) findPreference("deviceName"); mListenAddresses = (EditTextPreference) findPreference("listenAddresses"); diff --git a/src/main/java/com/nutomic/syncthingandroid/util/Languages.java b/src/main/java/com/nutomic/syncthingandroid/util/Languages.java index 41e1a56e..4490436f 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/Languages.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/Languages.java @@ -68,11 +68,6 @@ public final class Languages { */ @TargetApi(17) public void setLanguage(Context context) { - if (Build.VERSION.SDK_INT >= 24) { - Log.d(TAG, "Languages.setLanguage() ignored on >= android-24"); - mPreferences.edit().remove(PREFERENCE_LANGUAGE).apply(); - return; - } String language = mPreferences.getString(PREFERENCE_LANGUAGE, null); Locale locale; if (TextUtils.equals(language, DEFAULT_LOCALE.getLanguage())) { @@ -111,10 +106,6 @@ public final class Languages { public void forceChangeLanguage(Activity activity, String newLanguage) { mPreferences.edit().putString(PREFERENCE_LANGUAGE, newLanguage).commit(); setLanguage(activity); - if (Build.VERSION.SDK_INT >= 24) { - Log.d(TAG, "Languages.forceChangeLanguage() ignored on >= android-24"); - return; - } Intent intent = activity.getIntent(); if (intent == null) { // when launched as LAUNCHER return; diff --git a/src/main/res/xml/app_settings.xml b/src/main/res/xml/app_settings.xml index 59d75e13..606a06ca 100644 --- a/src/main/res/xml/app_settings.xml +++ b/src/main/res/xml/app_settings.xml @@ -33,6 +33,7 @@