Decouple sync service from other classes

This commit is contained in:
ByteHamster 2022-11-05 13:04:07 +01:00
parent 70a847f6ba
commit d08b9e196e
3 changed files with 17 additions and 6 deletions

View File

@ -6,6 +6,8 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import de.danoeh.antennapod.core.preferences.UsageStatistics;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.sync.SyncService;
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.download.NetworkConnectionChangeHandler;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
@ -28,6 +30,7 @@ public class ClientConfigurator {
SslProviderInstaller.install(context);
NetworkUtils.init(context);
NetworkConnectionChangeHandler.init(context);
SynchronizationQueueSink.setServiceStarterImpl(() -> SyncService.sync(context));
AntennapodHttpClient.setCacheDirectory(new File(context.getCacheDir(), "okhttp"));
AntennapodHttpClient.setProxyConfig(UserPreferences.getProxyConfig());
SleepTimerPreferences.init(context);

View File

@ -35,7 +35,6 @@ import de.danoeh.antennapod.event.FeedListUpdateEvent;
import de.danoeh.antennapod.event.MessageEvent;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.model.download.DownloadStatus;
import de.danoeh.antennapod.core.sync.SyncService;
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
import de.danoeh.antennapod.model.download.DownloadError;
import de.danoeh.antennapod.core.util.LongList;
@ -119,7 +118,7 @@ public final class DBTasks {
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
prefs.edit().putLong(PREF_LAST_REFRESH, System.currentTimeMillis()).apply();
SyncService.sync(context);
SynchronizationQueueSink.syncNow();
// Note: automatic download of episodes will be done but not here.
// Instead it is done after all feeds have been refreshed (asynchronously),
// in DownloadService.onDestroy()

View File

@ -3,12 +3,21 @@ package de.danoeh.antennapod.core.sync.queue;
import android.content.Context;
import de.danoeh.antennapod.core.sync.LockingAsyncExecutor;
import de.danoeh.antennapod.core.sync.SyncService;
import de.danoeh.antennapod.core.sync.SynchronizationSettings;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.net.sync.model.EpisodeAction;
public class SynchronizationQueueSink {
// To avoid a dependency loop of every class to SyncService, and from SyncService back to every class.
private static Runnable serviceStarterImpl = () -> { };
public static void setServiceStarterImpl(Runnable serviceStarter) {
serviceStarterImpl = serviceStarter;
}
public static void syncNow() {
serviceStarterImpl.run();
}
public static void clearQueue(Context context) {
LockingAsyncExecutor.executeLockedAsync(new SynchronizationQueueStorage(context)::clearQueue);
@ -20,7 +29,7 @@ public class SynchronizationQueueSink {
}
LockingAsyncExecutor.executeLockedAsync(() -> {
new SynchronizationQueueStorage(context).enqueueFeedAdded(downloadUrl);
SyncService.sync(context);
syncNow();
});
}
@ -30,7 +39,7 @@ public class SynchronizationQueueSink {
}
LockingAsyncExecutor.executeLockedAsync(() -> {
new SynchronizationQueueStorage(context).enqueueFeedRemoved(downloadUrl);
SyncService.sync(context);
syncNow();
});
}
@ -40,7 +49,7 @@ public class SynchronizationQueueSink {
}
LockingAsyncExecutor.executeLockedAsync(() -> {
new SynchronizationQueueStorage(context).enqueueEpisodeAction(action);
SyncService.sync(context);
syncNow();
});
}