summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java15
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java19
2 files changed, 20 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
index 159f64792..569390e65 100644
--- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
+++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
@@ -123,6 +123,14 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
}
}
+ private final SharedPreferences.OnSharedPreferenceChangeListener gpoddernetListener =
+ (sharedPreferences, key) -> {
+ if (GpodnetPreferences.PREF_LAST_SYNC_ATTEMPT_TIMESTAMP.equals(key)) {
+ updateLastGpodnetSyncReport(GpodnetPreferences.getLastSyncAttemptResult(),
+ GpodnetPreferences.getLastSyncAttemptTimestamp());
+ }
+ };
+
/**
* Returns the preference activity that should be used on this device.
*
@@ -436,15 +444,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
setParallelDownloadsText(UserPreferences.getParallelDownloads());
setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize());
setDataFolderText();
- GpodnetPreferences.setSyncAttemptListener(() -> ui.getActivity().runOnUiThread(
- () -> updateLastGpodnetSyncReport(
- GpodnetPreferences.getLastSyncAttemptResult(),
- GpodnetPreferences.getLastSyncAttemptTimestamp())));
+ GpodnetPreferences.registerOnSharedPreferenceChangeListener(gpoddernetListener);
updateGpodnetPreferenceScreen();
}
public void onPause() {
- GpodnetPreferences.setSyncAttemptListener(null);
+ GpodnetPreferences.unregisterOnSharedPreferenceChangeListener(gpoddernetListener);
}
@SuppressLint("NewApi")
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
index 0062647ed..f14c9e36c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
@@ -62,14 +62,22 @@ public class GpodnetPreferences {
private static boolean lastSyncAttemptResult;
- private static Runnable syncAttemptListener;
-
private static boolean preferencesLoaded = false;
private static SharedPreferences getPreferences() {
return ClientConfig.applicationCallbacks.getApplicationInstance().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
+ public static void registerOnSharedPreferenceChangeListener(
+ SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ getPreferences().registerOnSharedPreferenceChangeListener(listener);
+ }
+
+ public static void unregisterOnSharedPreferenceChangeListener(
+ SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ getPreferences().unregisterOnSharedPreferenceChangeListener(listener);
+ }
+
private static synchronized void ensurePreferencesLoaded() {
if (!preferencesLoaded) {
SharedPreferences prefs = getPreferences();
@@ -178,9 +186,6 @@ public class GpodnetPreferences {
GpodnetPreferences.lastSyncAttemptTimestamp = timestamp;
writePreference(PREF_LAST_SYNC_ATTEMPT_RESULT, result);
writePreference(PREF_LAST_SYNC_ATTEMPT_TIMESTAMP, timestamp);
- if (timestamp != 0 && syncAttemptListener != null) {
- syncAttemptListener.run();
- }
}
public static String getHostname() {
@@ -309,10 +314,6 @@ public class GpodnetPreferences {
UserPreferences.setGpodnetNotificationsEnabled();
}
- public static void setSyncAttemptListener(Runnable listener) {
- syncAttemptListener = listener;
- }
-
private static Set<String> readListFromString(String s) {
Set<String> result = new HashSet<>();
for (String item : s.split(" ")) {