Only apply preferences when they actually changed

This commit is contained in:
Marvin W 2020-09-13 02:10:44 +02:00
parent da9a3e714d
commit a2afbe07fd
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
3 changed files with 6 additions and 0 deletions

View File

@ -67,7 +67,9 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL
}
public static void setEnabled(Context context, boolean newStatus) {
boolean changed = CheckinPrefs.get(context).isEnabled() != newStatus;
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(PREF_ENABLE_CHECKIN, newStatus).commit();
if (!changed) return;
if (newStatus) {
context.sendOrderedBroadcast(new Intent(context, TriggerReceiver.class), null);
}

View File

@ -218,7 +218,9 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
}
public static void setEnabled(Context context, boolean newStatus) {
boolean changed = GcmPrefs.get(context).isEnabled() != newStatus;
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, newStatus).commit();
if (!changed) return;
if (!newStatus) {
McsService.stop(context);
} else {

View File

@ -25,7 +25,9 @@ class ExposurePreferences(private val context: Context) {
var enabled
get() = preferences.getBoolean(PREF_SCANNER_ENABLED, false)
set(newStatus) {
val changed = enabled != newStatus
preferences.edit().putBoolean(PREF_SCANNER_ENABLED, newStatus).commit()
if (!changed) return
if (newStatus) {
context.sendOrderedBroadcast(Intent(context, ServiceTrigger::class.java), null)
} else {