Merge pull request #4687 from damoasda/cleanup-DBTasksCallbacks
Refactoring: Remove interface DBTasksCallbacks
This commit is contained in:
commit
3f31764f58
|
@ -4,14 +4,12 @@ import android.content.Context;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.DBTasksCallbacks;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.AutomaticDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import de.test.antennapod.ui.UITestUtils;
|
||||
|
@ -32,7 +30,7 @@ public class AutoDownloadTest {
|
|||
private Context context;
|
||||
private UITestUtils stubFeedsServer;
|
||||
|
||||
private DBTasksCallbacks dbTasksCallbacksOrig;
|
||||
private AutomaticDownloadAlgorithm automaticDownloadAlgorithmOrig;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -41,7 +39,7 @@ public class AutoDownloadTest {
|
|||
stubFeedsServer = new UITestUtils(context);
|
||||
stubFeedsServer.setup();
|
||||
|
||||
dbTasksCallbacksOrig = ClientConfig.dbTasksCallbacks;
|
||||
automaticDownloadAlgorithmOrig = ClientConfig.automaticDownloadAlgorithm;
|
||||
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
|
@ -50,7 +48,7 @@ public class AutoDownloadTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ClientConfig.dbTasksCallbacks = dbTasksCallbacksOrig;
|
||||
ClientConfig.automaticDownloadAlgorithm = automaticDownloadAlgorithmOrig;
|
||||
EspressoTestUtils.tryKillPlaybackService();
|
||||
stubFeedsServer.tearDown();
|
||||
}
|
||||
|
@ -79,7 +77,7 @@ public class AutoDownloadTest {
|
|||
// Setup: enable automatic download
|
||||
// it is not needed, as the actual automatic download is stubbed.
|
||||
StubDownloadAlgorithm stubDownloadAlgorithm = new StubDownloadAlgorithm();
|
||||
useDownloadAlgorithm(stubDownloadAlgorithm);
|
||||
ClientConfig.automaticDownloadAlgorithm = stubDownloadAlgorithm;
|
||||
|
||||
// Actual test
|
||||
// Play the first one in the queue
|
||||
|
@ -113,20 +111,6 @@ public class AutoDownloadTest {
|
|||
.until(() -> item.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
|
||||
}
|
||||
|
||||
private void useDownloadAlgorithm(final AutomaticDownloadAlgorithm downloadAlgorithm) {
|
||||
ClientConfig.dbTasksCallbacks = new DBTasksCallbacks() {
|
||||
@Override
|
||||
public AutomaticDownloadAlgorithm getAutomaticDownloadAlgorithm() {
|
||||
return downloadAlgorithm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpisodeCleanupAlgorithm getEpisodeCacheCleanupAlgorithm() {
|
||||
return dbTasksCallbacksOrig.getEpisodeCacheCleanupAlgorithm();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class StubDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
||||
private long currentlyPlaying = -1;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.danoeh.antennapod.config;
|
|||
|
||||
import de.danoeh.antennapod.BuildConfig;
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.storage.APDownloadAlgorithm;
|
||||
|
||||
/**
|
||||
* Configures the ClientConfig class of the core package.
|
||||
|
@ -15,7 +16,7 @@ class ClientConfigurator {
|
|||
ClientConfig.applicationCallbacks = new ApplicationCallbacksImpl();
|
||||
ClientConfig.downloadServiceCallbacks = new DownloadServiceCallbacksImpl();
|
||||
ClientConfig.playbackServiceCallbacks = new PlaybackServiceCallbacksImpl();
|
||||
ClientConfig.dbTasksCallbacks = new DBTasksCallbacksImpl();
|
||||
ClientConfig.automaticDownloadAlgorithm = new APDownloadAlgorithm();
|
||||
ClientConfig.castCallbacks = new CastCallbackImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package de.danoeh.antennapod.config;
|
||||
|
||||
import de.danoeh.antennapod.core.DBTasksCallbacks;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.APDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.AutomaticDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||
|
||||
public class DBTasksCallbacksImpl implements DBTasksCallbacks {
|
||||
|
||||
@Override
|
||||
public AutomaticDownloadAlgorithm getAutomaticDownloadAlgorithm() {
|
||||
return new APDownloadAlgorithm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EpisodeCleanupAlgorithm getEpisodeCacheCleanupAlgorithm() {
|
||||
return UserPreferences.getEpisodeCleanupAlgorithm();
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ 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.storage.AutomaticDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
|
||||
|
@ -32,7 +33,7 @@ public class ClientConfig {
|
|||
|
||||
public static PlaybackServiceCallbacks playbackServiceCallbacks;
|
||||
|
||||
public static DBTasksCallbacks dbTasksCallbacks;
|
||||
public static AutomaticDownloadAlgorithm automaticDownloadAlgorithm;
|
||||
|
||||
public static CastCallbacks castCallbacks;
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package de.danoeh.antennapod.core;
|
||||
|
||||
import de.danoeh.antennapod.core.storage.AutomaticDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||
|
||||
/**
|
||||
* Callbacks for the DBTasks class of the storage module.
|
||||
*/
|
||||
public interface DBTasksCallbacks {
|
||||
|
||||
/**
|
||||
* Returns the client's implementation of the AutomaticDownloadAlgorithm interface.
|
||||
*/
|
||||
AutomaticDownloadAlgorithm getAutomaticDownloadAlgorithm();
|
||||
|
||||
/**
|
||||
* Returns the client's implementation of the EpisodeCacheCleanupAlgorithm interface.
|
||||
*/
|
||||
EpisodeCleanupAlgorithm getEpisodeCacheCleanupAlgorithm();
|
||||
}
|
|
@ -429,7 +429,7 @@ public class DownloadService extends Service {
|
|||
+ ", cleanupMedia=" + cleanupMedia);
|
||||
|
||||
if (cleanupMedia) {
|
||||
ClientConfig.dbTasksCallbacks.getEpisodeCacheCleanupAlgorithm()
|
||||
UserPreferences.getEpisodeCleanupAlgorithm()
|
||||
.makeRoomForEpisodes(getApplicationContext(), requests.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ public final class DBTasks {
|
|||
*/
|
||||
public static Future<?> autodownloadUndownloadedItems(final Context context) {
|
||||
Log.d(TAG, "autodownloadUndownloadedItems");
|
||||
return autodownloadExec.submit(ClientConfig.dbTasksCallbacks.getAutomaticDownloadAlgorithm()
|
||||
return autodownloadExec.submit(ClientConfig.automaticDownloadAlgorithm
|
||||
.autoDownloadUndownloadedItems(context));
|
||||
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public final class DBTasks {
|
|||
* @param context Used for accessing the DB.
|
||||
*/
|
||||
public static void performAutoCleanup(final Context context) {
|
||||
ClientConfig.dbTasksCallbacks.getEpisodeCacheCleanupAlgorithm().performCleanup(context);
|
||||
UserPreferences.getEpisodeCleanupAlgorithm().performCleanup(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,7 @@ 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.storage.AutomaticDownloadAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
|
||||
|
@ -38,7 +39,7 @@ public class ClientConfig {
|
|||
|
||||
public static PlaybackServiceCallbacks playbackServiceCallbacks;
|
||||
|
||||
public static DBTasksCallbacks dbTasksCallbacks;
|
||||
public static AutomaticDownloadAlgorithm automaticDownloadAlgorithm;
|
||||
|
||||
public static CastCallbacks castCallbacks;
|
||||
|
||||
|
|
Loading…
Reference in New Issue