1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 14:21:16 +00:00

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.
This commit is contained in:
Felix Ableitner 2017-09-29 03:21:55 +09:00
parent 32be8ba207
commit 84ae6953da
3 changed files with 16 additions and 17 deletions

View file

@ -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,6 +108,10 @@ public class SettingsActivity extends SyncthingActivity {
mSyncOnlyOnSSIDs.setEnabled(mSyncOnlyWifi.isChecked());
ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE);
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());
@ -114,6 +120,7 @@ public class SettingsActivity extends SyncthingActivity {
languages.forceChangeLanguage(getActivity(), (String) o);
return false;
});
}
mDeviceName = (EditTextPreference) findPreference("deviceName");
mListenAddresses = (EditTextPreference) findPreference("listenAddresses");

View file

@ -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;

View file

@ -33,6 +33,7 @@
</PreferenceScreen>
<PreferenceScreen
android:key="category_behaviour"
android:title="@string/category_behaviour">
<CheckBoxPreference