From 4182f83367379f5da92ca3cf9bb53048fed71f74 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 19 Aug 2023 10:59:12 +0200 Subject: [PATCH] Sync on app start (#6589) --- .../java/de/danoeh/antennapod/activity/MainActivity.java | 3 +++ .../core/sync/queue/SynchronizationQueueSink.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index b66edc884..b42fb6d5f 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -37,6 +37,7 @@ import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.ThemeSwitcher; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; +import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink; import de.danoeh.antennapod.core.util.download.FeedUpdateManager; import de.danoeh.antennapod.dialog.RatingDialog; import de.danoeh.antennapod.event.EpisodeDownloadEvent; @@ -165,6 +166,8 @@ public class MainActivity extends CastEnabledActivity { sheetBehavior.setBottomSheetCallback(bottomSheetCallback); FeedUpdateManager.restartUpdateAlarm(this, false); + SynchronizationQueueSink.syncNowIfNotSyncedRecently(); + WorkManager.getInstance(this) .getWorkInfosByTagLiveData(FeedUpdateManager.WORK_TAG_FEED_UPDATE) .observe(this, workInfos -> { diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java index 55c415153..12559539f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java @@ -19,6 +19,12 @@ public class SynchronizationQueueSink { serviceStarterImpl.run(); } + public static void syncNowIfNotSyncedRecently() { + if (System.currentTimeMillis() - SynchronizationSettings.getLastSyncAttempt() > 1000 * 60 * 10) { + syncNow(); + } + } + public static void clearQueue(Context context) { LockingAsyncExecutor.executeLockedAsync(new SynchronizationQueueStorage(context)::clearQueue); }