Sync on app start (#6589)

This commit is contained in:
ByteHamster 2023-08-19 10:59:12 +02:00 committed by GitHub
parent 5ae766b1a1
commit 4182f83367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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 -> {

View File

@ -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);
}