diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-11-06 10:54:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 10:54:18 +0100 |
commit | be8c8cef4d974f7ecaee858591182065651dca93 (patch) | |
tree | 9be7a7363dfc3a168efb5647c5d23121cdd27173 /app | |
parent | 546c8841db829a6ac57e8508a91d5734fb4d1ddf (diff) | |
parent | 11292b598cc6867e32f4f313dfd6eff1197efdd3 (diff) | |
download | AntennaPod-be8c8cef4d974f7ecaee858591182065651dca93.zip |
Merge pull request #6176 from ByteHamster/decouple
Decouple some classes
Diffstat (limited to 'app')
20 files changed, 66 insertions, 78 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/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java index 8ce894684..66ce4adc6 100644 --- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java +++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java @@ -10,8 +10,11 @@ import com.joanzapata.iconify.fonts.FontAwesomeModule; import com.joanzapata.iconify.fonts.MaterialModule; import de.danoeh.antennapod.activity.SplashActivity; +import de.danoeh.antennapod.config.ApplicationCallbacksImpl; +import de.danoeh.antennapod.config.DownloadServiceCallbacksImpl; import de.danoeh.antennapod.core.ApCoreEventBusIndex; import de.danoeh.antennapod.core.ClientConfig; +import de.danoeh.antennapod.core.ClientConfigurator; import de.danoeh.antennapod.error.CrashReportWriter; import de.danoeh.antennapod.error.RxJavaErrorHandlerSetup; import de.danoeh.antennapod.spa.SPAUtil; @@ -20,15 +23,6 @@ import org.greenrobot.eventbus.EventBus; /** Main application class. */ public class PodcastApp extends MultiDexApplication { - // make sure that ClientConfigurator executes its static code - static { - try { - Class.forName("de.danoeh.antennapod.config.ClientConfigurator"); - } catch (Exception e) { - throw new RuntimeException("ClientConfigurator not found", e); - } - } - private static PodcastApp singleton; public static PodcastApp getInstance() { @@ -38,6 +32,9 @@ public class PodcastApp extends MultiDexApplication { @Override public void onCreate() { super.onCreate(); + ClientConfig.USER_AGENT = "AntennaPod/" + BuildConfig.VERSION_NAME; + ClientConfig.applicationCallbacks = new ApplicationCallbacksImpl(); + ClientConfig.downloadServiceCallbacks = new DownloadServiceCallbacksImpl(); Thread.setDefaultUncaughtExceptionHandler(new CrashReportWriter()); RxJavaErrorHandlerSetup.setupRxJavaErrorHandler(); @@ -55,7 +52,7 @@ public class PodcastApp extends MultiDexApplication { singleton = this; - ClientConfig.initialize(this); + ClientConfigurator.initialize(this); Iconify.with(new FontAwesomeModule()); Iconify.with(new MaterialModule()); 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 3a979d95d..03b802328 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,8 @@ 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; import de.danoeh.antennapod.event.PlayerStatusEvent; @@ -44,7 +46,6 @@ import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.service.download.HttpDownloader; -import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.net.discovery.CombinedSearcher; @@ -452,7 +453,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; @@ -462,7 +463,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { viewBinding.stopPreviewButton.setOnClickListener(v -> { PlaybackPreferences.writeNoMediaPlaying(); - IntentUtils.sendLocalBroadcast(this, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); + IntentUtils.sendLocalBroadcast(this, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE); }); if (UserPreferences.isEnableAutodownload()) { 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/ItemActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java index 5581ca0c6..3b3567789 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java @@ -8,10 +8,10 @@ import androidx.annotation.StringRes; import android.view.View; import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.util.FeedItemUtil; public abstract class ItemActionButton { FeedItem item; @@ -40,7 +40,7 @@ public abstract class ItemActionButton { } final boolean isDownloadingMedia = DownloadService.isDownloadingFile(media.getDownload_url()); - if (FeedItemUtil.isCurrentlyPlaying(media)) { + if (PlaybackStatus.isCurrentlyPlaying(media)) { return new PauseActionButton(item); } else if (item.getFeed().isLocalFeed()) { return new PlayLocalActionButton(item); 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/adapter/actionbutton/PauseActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java index 5e9a2e9f3..90025d9a2 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/PauseActionButton.java @@ -6,9 +6,9 @@ import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; +import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.util.FeedItemUtil; public class PauseActionButton extends ItemActionButton { @@ -35,7 +35,7 @@ public class PauseActionButton extends ItemActionButton { return; } - if (FeedItemUtil.isCurrentlyPlaying(media)) { + if (PlaybackStatus.isCurrentlyPlaying(media)) { context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_PAUSE)); } } diff --git a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java deleted file mode 100644 index 1f4f657b1..000000000 --- a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.danoeh.antennapod.config; - -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.core.ClientConfig; - -/** - * Configures the ClientConfig class of the core package. - */ -class ClientConfigurator { - - private ClientConfigurator() { - } - - static { - ClientConfig.USER_AGENT = "AntennaPod/" + BuildConfig.VERSION_NAME; - ClientConfig.applicationCallbacks = new ApplicationCallbacksImpl(); - ClientConfig.downloadServiceCallbacks = new DownloadServiceCallbacksImpl(); - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 17f8abf82..3037a8554 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -41,6 +41,7 @@ import de.danoeh.antennapod.core.event.DownloadEvent; import de.danoeh.antennapod.core.event.DownloaderUpdate; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.event.FeedItemEvent; import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; @@ -53,7 +54,6 @@ import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.DateFormatter; -import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.ui.common.CircularProgressBar; import de.danoeh.antennapod.ui.common.ThemeUtils; import de.danoeh.antennapod.core.util.playback.PlaybackController; @@ -332,7 +332,7 @@ public class ItemFragment extends Fragment { txtvDuration.setContentDescription( Converter.getDurationStringLocalized(getContext(), media.getDuration())); } - if (FeedItemUtil.isCurrentlyPlaying(media)) { + if (PlaybackStatus.isCurrentlyPlaying(media)) { actionButton1 = new PauseActionButton(item); } else if (item.getFeed().isLocalFeed()) { actionButton1 = new PlayLocalActionButton(item); 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/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index c52db0500..9e8d7da46 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -17,12 +17,13 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; -import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.sync.SynchronizationSettings; import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.IntentUtils; +import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.dialog.ShareDialog; import de.danoeh.antennapod.model.feed.FeedItem; @@ -52,7 +53,7 @@ public class FeedItemMenuHandler { return false; } final boolean hasMedia = selectedItem.getMedia() != null; - final boolean isPlaying = hasMedia && FeedItemUtil.isPlaying(selectedItem.getMedia()); + final boolean isPlaying = hasMedia && PlaybackStatus.isPlaying(selectedItem.getMedia()); final boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE); final boolean fileDownloaded = hasMedia && selectedItem.getMedia().fileExists(); final boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE); @@ -187,7 +188,7 @@ public class FeedItemMenuHandler { selectedItem.getMedia().setPosition(0); if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == selectedItem.getMedia().getId()) { PlaybackPreferences.writeNoMediaPlaying(); - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); + IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE); } DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true); } else if (menuItemId == R.id.visit_website_item) { diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java index 8cb5a7cdf..3d7344b9b 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java @@ -7,8 +7,8 @@ import android.net.ConnectivityManager; import android.text.TextUtils; import android.util.Log; -import de.danoeh.antennapod.core.ClientConfig; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.core.ClientConfigurator; +import de.danoeh.antennapod.core.util.download.NetworkConnectionChangeHandler; public class ConnectivityActionReceiver extends BroadcastReceiver { private static final String TAG = "ConnectivityActionRecvr"; @@ -18,8 +18,8 @@ public class ConnectivityActionReceiver extends BroadcastReceiver { if (TextUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) { Log.d(TAG, "Received intent"); - ClientConfig.initialize(context); - NetworkUtils.networkChangedDetected(); + ClientConfigurator.initialize(context); + NetworkConnectionChangeHandler.networkChangedDetected(); } } } 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 34ce83489..ed873b300 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java @@ -5,9 +5,9 @@ import android.content.Context; import android.content.Intent; import android.util.Log; -import de.danoeh.antennapod.core.ClientConfig; +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 @@ -24,7 +24,7 @@ public class PowerConnectionReceiver extends BroadcastReceiver { Log.d(TAG, "charging intent: " + action); - ClientConfig.initialize(context); + ClientConfigurator.initialize(context); if (Intent.ACTION_POWER_CONNECTED.equals(action)) { Log.d(TAG, "charging, starting auto-download"); // we're plugged in, this is a great time to auto-download if everything else is @@ -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 d1636dcff..0ed60b23e 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java @@ -10,9 +10,9 @@ import android.widget.Toast; import java.util.Arrays; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.ClientConfig; -import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.ClientConfigurator; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; +import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.Feed; /** @@ -41,10 +41,10 @@ public class SPAReceiver extends BroadcastReceiver{ return; } Log.d(TAG, "Received feeds list: " + Arrays.toString(feedUrls)); - ClientConfig.initialize(context); + 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(); } diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java index 22b46492f..4b83f70ef 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java @@ -23,6 +23,8 @@ import de.danoeh.antennapod.adapter.CoverLoader; import de.danoeh.antennapod.adapter.actionbutton.ItemActionButton; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.core.util.PlaybackStatus; +import de.danoeh.antennapod.core.util.download.MediaSizeLoader; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.core.util.DateFormatter; import de.danoeh.antennapod.model.feed.FeedItem; @@ -31,7 +33,6 @@ import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.Converter; -import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.ui.common.CircularProgressBar; @@ -139,7 +140,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { isVideo.setVisibility(media.getMediaType() == MediaType.VIDEO ? View.VISIBLE : View.GONE); duration.setVisibility(media.getDuration() > 0 ? View.VISIBLE : View.GONE); - if (FeedItemUtil.isCurrentlyPlaying(media)) { + if (PlaybackStatus.isCurrentlyPlaying(media)) { itemView.setBackgroundColor(ThemeUtils.getColorFromAttr(activity, R.attr.currently_playing_background)); } else { itemView.setBackgroundResource(ThemeUtils.getDrawableFromAttr(activity, R.attr.selectableItemBackground)); @@ -158,7 +159,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { duration.setText(Converter.getDurationStringLong(media.getDuration())); duration.setContentDescription(activity.getString(R.string.chapter_duration, Converter.getDurationStringLocalized(activity, media.getDuration()))); - if (FeedItemUtil.isPlaying(item.getMedia()) || item.isInProgress()) { + if (PlaybackStatus.isPlaying(item.getMedia()) || item.isInProgress()) { int progress = (int) (100.0 * media.getPosition() / media.getDuration()); int remainingTime = Math.max(media.getDuration() - media.getPosition(), 0); progressBar.setProgress(progress); @@ -182,7 +183,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { } else if (NetworkUtils.isEpisodeHeadDownloadAllowed() && !media.checkedOnSizeButUnknown()) { size.setText("{fa-spinner}"); Iconify.addIcons(size); - NetworkUtils.getFeedMediaSizeObservable(media).subscribe( + MediaSizeLoader.getFeedMediaSizeObservable(media).subscribe( sizeValue -> { if (sizeValue > 0) { size.setText(Formatter.formatShortFileSize(activity, sizeValue)); @@ -246,7 +247,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { } public boolean isCurrentlyPlayingItem() { - return item.getMedia() != null && FeedItemUtil.isCurrentlyPlaying(item.getMedia()); + return item.getMedia() != null && PlaybackStatus.isCurrentlyPlaying(item.getMedia()); } public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) { diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java index f2d8e628c..60422d74f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java @@ -15,7 +15,7 @@ import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.util.DateFormatter; -import de.danoeh.antennapod.core.util.FeedItemUtil; +import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; @@ -96,7 +96,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { } public boolean isCurrentlyPlayingItem() { - return item != null && item.getMedia() != null && FeedItemUtil.isCurrentlyPlaying(item.getMedia()); + return item != null && item.getMedia() != null && PlaybackStatus.isCurrentlyPlaying(item.getMedia()); } public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) { |