diff options
author | ByteHamster <info@bytehamster.com> | 2022-11-05 13:40:44 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-11-05 20:44:53 +0100 |
commit | 11292b598cc6867e32f4f313dfd6eff1197efdd3 (patch) | |
tree | 7eaefa01a6295c0eb1cacc036efc96f5572676b2 /app/src | |
parent | ae3971a58ff00755148b036794b7e5dc1c57017a (diff) | |
download | AntennaPod-11292b598cc6867e32f4f313dfd6eff1197efdd3.zip |
Remove dependency from other classes to DownloadService
Diffstat (limited to 'app/src')
11 files changed, 31 insertions, 23 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java index 8aae95e69..4e255baeb 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java @@ -9,6 +9,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.test.antennapod.EspressoTestUtils; import org.awaitility.Awaitility; import org.awaitility.core.ConditionTimeoutException; @@ -80,7 +81,7 @@ public class DownloadServiceTest { public void tearDown() throws Exception { DownloadService.setDownloaderFactory(origFactory); Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); - DownloadService.cancelAll(context); + DownloadServiceInterface.get().cancelAll(context); context.stopService(new Intent(context, DownloadService.class)); EspressoTestUtils.tryKillDownloadService(); } @@ -113,7 +114,8 @@ public class DownloadServiceTest { assertFalse("The media in test should not yet been downloaded", DBReader.getFeedMedia(testMedia11.getId()).isDownloaded()); - DownloadService.download(InstrumentationRegistry.getInstrumentation().getTargetContext(), false, + DownloadServiceInterface.get() + .download(InstrumentationRegistry.getInstrumentation().getTargetContext(), false, DownloadRequestCreator.create(testMedia11).build()); Awaitility.await() .atMost(5000, TimeUnit.MILLISECONDS) @@ -158,7 +160,8 @@ public class DownloadServiceTest { } withFeedItemEventListener(feedItemEventListener -> { - DownloadService.download(InstrumentationRegistry.getInstrumentation().getTargetContext(), false, + DownloadServiceInterface.get() + .download(InstrumentationRegistry.getInstrumentation().getTargetContext(), false, DownloadRequestCreator.create(testMedia11).build()); withDownloadEventListener(downloadEventListener -> Awaitility.await("download is actually running") @@ -175,7 +178,7 @@ public class DownloadServiceTest { .atMost(2000, TimeUnit.MILLISECONDS) .until(() -> feedItemEventListener.getEvents().size() >= 1); } - DownloadService.cancel(context, testMedia11.getDownload_url()); + DownloadServiceInterface.get().cancel(context, testMedia11.getDownload_url()); final int totalNumEventsExpected = itemAlreadyInQueue ? 1 : 3; Awaitility.await("item dequeue event + download termination event") .atMost(2000, TimeUnit.MILLISECONDS) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index fb4c7c2d2..81756d6c8 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -4,7 +4,7 @@ import android.os.Bundle; import android.text.TextUtils; import androidx.appcompat.app.AppCompatActivity; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -62,7 +62,8 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(() -> { - DownloadService.download(DownloadAuthenticationActivity.this, false, request); + DownloadServiceInterface.get() + .download(DownloadAuthenticationActivity.this, false, request); finish(); }); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 008e28ae2..46d39f005 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -35,6 +35,7 @@ import de.danoeh.antennapod.core.event.DownloadEvent; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.core.util.DownloadErrorLabel; import de.danoeh.antennapod.event.FeedListUpdateEvent; @@ -455,7 +456,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { openFeed(); } else { Feed f = new Feed(selectedDownloadUrl, null, feed.getTitle()); - DownloadService.download(this, false, DownloadRequestCreator.create(f) + DownloadServiceInterface.get().download(this, false, DownloadRequestCreator.create(f) .withAuthentication(username, password) .build()); didPressSubscribe = true; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java index f92d422d0..62c4be051 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java @@ -28,8 +28,8 @@ import de.danoeh.antennapod.core.export.opml.OpmlElement; import de.danoeh.antennapod.core.export.opml.OpmlReader; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.databinding.OpmlSelectionBinding; import de.danoeh.antennapod.model.feed.Feed; import io.reactivex.Completable; @@ -96,7 +96,7 @@ public class OpmlImportActivity extends AppCompatActivity { } OpmlElement element = readElements.get(checked.keyAt(i)); Feed feed = new Feed(element.getXmlUrl(), null, element.getText()); - DownloadService.download(this, false, DownloadRequestCreator.create(feed).build()); + DownloadServiceInterface.get().download(this, false, DownloadRequestCreator.create(feed).build()); } }) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java index 914546ab2..4c46b6428 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; @@ -139,7 +139,8 @@ public class DownloadLogAdapter extends BaseAdapter { Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId()); return; } - DownloadService.download(context, true, DownloadRequestCreator.create(media).build()); + DownloadServiceInterface.get() + .download(context, true, DownloadRequestCreator.create(media).build()); ((MainActivity) context).showSnackbarAbovePlayer( R.string.status_downloading_label, Toast.LENGTH_SHORT); }); @@ -156,7 +157,7 @@ public class DownloadLogAdapter extends BaseAdapter { holder.secondaryActionButton.setVisibility(View.VISIBLE); holder.secondaryActionButton.setTag(downloader); holder.secondaryActionButton.setOnClickListener(v -> { - DownloadService.cancel(context, request.getSource()); + DownloadServiceInterface.get().cancel(context, request.getSource()); if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { FeedMedia media = DBReader.getFeedMedia(request.getFeedfileId()); FeedItem feedItem = media.getItem(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java index 636c974d9..18127d289 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java @@ -5,7 +5,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -32,7 +32,7 @@ public class CancelDownloadActionButton extends ItemActionButton { @Override public void onClick(Context context) { FeedMedia media = item.getMedia(); - DownloadService.cancel(context, media.getDownload_url()); + DownloadServiceInterface.get().cancel(context, media.getDownload_url()); if (UserPreferences.isEnableAutodownload()) { item.disableAutoDownload(); DBWriter.setFeedItem(item); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java index 553512882..60f55507d 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java @@ -11,6 +11,7 @@ import androidx.annotation.StringRes; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UsageStatistics; @@ -50,7 +51,8 @@ public class DownloadActionButton extends ItemActionButton { UsageStatistics.logAction(UsageStatistics.ACTION_DOWNLOAD); if (NetworkUtils.isEpisodeDownloadAllowed() || MobileDownloadHelper.userAllowedMobileDownloads()) { - DownloadService.download(context, false, DownloadRequestCreator.create(item.getMedia()).build()); + DownloadServiceInterface.get() + .download(context, false, DownloadRequestCreator.create(item.getMedia()).build()); } else if (MobileDownloadHelper.userChoseAddToQueue() && !item.isTagged(FeedItem.TAG_QUEUE)) { DBWriter.addQueueItem(context, item); Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java index 4c68a559d..dfabcd0d9 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java @@ -5,7 +5,7 @@ import android.content.Context; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; @@ -44,6 +44,6 @@ class MobileDownloadHelper { private static void downloadFeedItems(Context context, FeedItem item) { allowMobileDownloadTimestamp = System.currentTimeMillis(); - DownloadService.download(context, true, DownloadRequestCreator.create(item.getMedia()).build()); + DownloadServiceInterface.get().download(context, true, DownloadRequestCreator.create(item.getMedia()).build()); } }
\ No newline at end of file diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java index 0e7c019f1..1103a35d5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.model.feed.FeedItem; @@ -99,7 +99,7 @@ public class EpisodeMultiSelectActionHandler { requests.add(DownloadRequestCreator.create(episode.getMedia()).build()); } } - DownloadService.download(activity, true, requests.toArray(new DownloadRequest[0])); + DownloadServiceInterface.get().download(activity, true, requests.toArray(new DownloadRequest[0])); showMessage(R.plurals.downloading_batch_label, requests.size()); } diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java index db392523e..ed873b300 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java @@ -7,7 +7,7 @@ import android.util.Log; import de.danoeh.antennapod.core.ClientConfigurator; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.core.storage.DBTasks; // modified from http://developer.android.com/training/monitoring-device-state/battery-monitoring.html @@ -37,7 +37,7 @@ public class PowerConnectionReceiver extends BroadcastReceiver { // if we're not supposed to be auto-downloading when we're not charging, stop it if (!UserPreferences.isEnableAutodownloadOnBattery()) { Log.d(TAG, "not charging anymore, canceling auto-download"); - DownloadService.cancelAll(context); + DownloadServiceInterface.get().cancelAll(context); } else { Log.d(TAG, "not charging anymore, but the user allows auto-download " + "when on battery so we'll keep going"); diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java index 38dfc7061..0ed60b23e 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java @@ -11,8 +11,8 @@ import java.util.Arrays; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.ClientConfigurator; -import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.Feed; /** @@ -44,7 +44,7 @@ public class SPAReceiver extends BroadcastReceiver{ ClientConfigurator.initialize(context); for (String url : feedUrls) { Feed f = new Feed(url, null); - DownloadService.download(context, false, DownloadRequestCreator.create(f).build()); + DownloadServiceInterface.get().download(context, false, DownloadRequestCreator.create(f).build()); } Toast.makeText(context, R.string.sp_apps_importing_feeds_msg, Toast.LENGTH_LONG).show(); } |