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
This commit is contained in:
Hans-Christoph Steiner 2018-02-13 16:58:17 +01:00
parent 30b00156db
commit 5c2e9305a8

View File

@ -285,8 +285,22 @@ public class FDroidApp extends Application {
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
Languages.setLanguage(this); Languages.setLanguage(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); UpdateService.forceUpdateRepo(this);
} }
atStartTime.edit().putString(lastLocaleKey, currentLocale).apply();
}
@Override @Override
public void onCreate() { public void onCreate() {
@ -435,7 +449,7 @@ public class FDroidApp extends Application {
Provisioner.scanAndProcess(getApplicationContext()); Provisioner.scanAndProcess(getApplicationContext());
// if the underlying OS version has changed, then fully rebuild the database // 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)) { if (Build.VERSION.SDK_INT != atStartTime.getInt("build-version", Build.VERSION.SDK_INT)) {
UpdateService.forceUpdateRepo(this); UpdateService.forceUpdateRepo(this);
} }
@ -483,6 +497,10 @@ public class FDroidApp extends Application {
return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter(); 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) { public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
return; return;