From 5c2e9305a8aad25e7621e1372546b352b971ee36 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 13 Feb 2018 16:58:17 +0100 Subject: [PATCH] only force index update when the locale actually changes This was forcing an index update on any config change, even just a simple screen rotation. Now it actually checks whether its needed. closes #1325 --- .../java/org/fdroid/fdroid/FDroidApp.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java index 2e899c75b..3306a32e9 100644 --- a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java +++ b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java @@ -285,7 +285,21 @@ public class FDroidApp extends Application { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Languages.setLanguage(this); - UpdateService.forceUpdateRepo(this); + + // update the descriptions based on the new language preferences + SharedPreferences atStartTime = getAtStartTimeSharedPreferences(); + final String lastLocaleKey = "lastLocale"; + String lastLocale = atStartTime.getString(lastLocaleKey, null); + String currentLocale; + if (Build.VERSION.SDK_INT < 24) { + currentLocale = newConfig.locale.toString(); + } else { + currentLocale = newConfig.getLocales().toString(); + } + if (!TextUtils.equals(lastLocale, currentLocale)) { + UpdateService.forceUpdateRepo(this); + } + atStartTime.edit().putString(lastLocaleKey, currentLocale).apply(); } @Override @@ -435,7 +449,7 @@ public class FDroidApp extends Application { Provisioner.scanAndProcess(getApplicationContext()); // if the underlying OS version has changed, then fully rebuild the database - SharedPreferences atStartTime = getSharedPreferences("at-start-time", Context.MODE_PRIVATE); + SharedPreferences atStartTime = getAtStartTimeSharedPreferences(); if (Build.VERSION.SDK_INT != atStartTime.getInt("build-version", Build.VERSION.SDK_INT)) { UpdateService.forceUpdateRepo(this); } @@ -483,6 +497,10 @@ public class FDroidApp extends Application { return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter(); } + private SharedPreferences getAtStartTimeSharedPreferences() { + return getSharedPreferences("at-start-time", Context.MODE_PRIVATE); + } + public void sendViaBluetooth(Activity activity, int resultCode, String packageName) { if (resultCode == Activity.RESULT_CANCELED) { return;