From 6f3a9b16764a57e43994ccbeeada5224dee93f44 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 29 Mar 2024 17:45:14 +0100 Subject: Create module for sync service and move DBWriter to database module (#7040) --- .../serviceinterface/AutoDownloadManager.java | 39 ++++++++++++++++++++++ .../serviceinterface/FeedUpdateManager.java | 30 +++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/AutoDownloadManager.java create mode 100644 net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/FeedUpdateManager.java (limited to 'net/download') diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/AutoDownloadManager.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/AutoDownloadManager.java new file mode 100644 index 000000000..2eb1d1b56 --- /dev/null +++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/AutoDownloadManager.java @@ -0,0 +1,39 @@ +package de.danoeh.antennapod.net.download.serviceinterface; + +import android.content.Context; + +import java.util.concurrent.Future; + +public abstract class AutoDownloadManager { + private static AutoDownloadManager instance; + + public static AutoDownloadManager getInstance() { + return instance; + } + + public static void setInstance(AutoDownloadManager instance) { + AutoDownloadManager.instance = instance; + } + + /** + * Looks for non-downloaded episodes in the queue or list of unread items and request a download if + * 1. Network is available + * 2. The device is charging or the user allows auto download on battery + * 3. There is free space in the episode cache + * This method is executed on an internal single thread executor. + * + * @param context Used for accessing the DB. + * @return A Future that can be used for waiting for the methods completion. + */ + public abstract Future autodownloadUndownloadedItems(final Context context); + + /** + * Removed downloaded episodes outside of the queue if the episode cache is full. Episodes with a smaller + * 'playbackCompletionDate'-value will be deleted first. + *

+ * This method should NOT be executed on the GUI thread. + * + * @param context Used for accessing the DB. + */ + public abstract void performAutoCleanup(final Context context); +} diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/FeedUpdateManager.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/FeedUpdateManager.java new file mode 100644 index 000000000..25a8f42d3 --- /dev/null +++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/FeedUpdateManager.java @@ -0,0 +1,30 @@ +package de.danoeh.antennapod.net.download.serviceinterface; + +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import de.danoeh.antennapod.model.feed.Feed; + +public abstract class FeedUpdateManager { + private static FeedUpdateManager instance; + + public static FeedUpdateManager getInstance() { + return instance; + } + + public static void setInstance(FeedUpdateManager instance) { + FeedUpdateManager.instance = instance; + } + + public abstract void restartUpdateAlarm(Context context, boolean replace); + + public abstract void runOnce(Context context); + + public abstract void runOnce(Context context, Feed feed); + + public abstract void runOnce(Context context, Feed feed, boolean nextPage); + + public abstract void runOnceOrAsk(@NonNull Context context); + + public abstract void runOnceOrAsk(@NonNull Context context, @Nullable Feed feed); +} -- cgit v1.2.3