Only apply preferences when they actually changed

This commit is contained in:
Oizaro 2020-09-14 20:47:55 +02:00
parent c841a6dde1
commit f0a0369bbe
2 changed files with 4 additions and 0 deletions

View File

@ -68,7 +68,9 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL
} }
public static void setEnabled(Context context, boolean newStatus) { 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(); PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(PREF_ENABLE_CHECKIN, newStatus).commit();
if (!changed) return;
if (newStatus) { if (newStatus) {
context.sendOrderedBroadcast(new Intent(context, TriggerReceiver.class), null); context.sendOrderedBroadcast(new Intent(context, TriggerReceiver.class), null);
} }

View File

@ -219,7 +219,9 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
} }
public static void setEnabled(Context context, boolean newStatus) { 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(); PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, newStatus).commit();
if (!changed) return;
if (!newStatus) { if (!newStatus) {
McsService.stop(context); McsService.stop(context);
} else { } else {