diff options
author | ByteHamster <info@bytehamster.com> | 2022-01-06 12:36:06 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-01-06 12:36:11 +0100 |
commit | 485db9ebcd1a8799eed2036bf0d9c2ca210deecb (patch) | |
tree | 2088bc8e2c1730803a32bad80358b585bb992201 /core/src | |
parent | 38c470eacec8f083e5d1ab440edbe4ea617d7486 (diff) | |
download | AntennaPod-485db9ebcd1a8799eed2036bf0d9c2ca210deecb.zip |
Remove queue loading logic from PlaybackServiceTaskManager
This just causes problems with keeping the preloaded list up-to-date.
We only call the method from background threads anyway.
Diffstat (limited to 'core/src')
2 files changed, 3 insertions, 102 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 309bfc7bd..76fdc1040 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -367,7 +367,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { private void loadQueueForMediaSession() { Single.<List<MediaSessionCompat.QueueItem>>create(emitter -> { List<MediaSessionCompat.QueueItem> queueItems = new ArrayList<>(); - for (FeedItem feedItem : taskManager.getQueue()) { + for (FeedItem feedItem : DBReader.getQueue()) { if (feedItem.getMedia() != null) { MediaDescriptionCompat mediaDescription = feedItem.getMedia().getMediaItem().getDescription(); queueItems.add(new MediaSessionCompat.QueueItem(mediaDescription, feedItem.getId())); @@ -440,7 +440,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); if (parentId.equals(getResources().getString(R.string.app_name))) { mediaItems.add(createBrowsableMediaItem(R.string.queue_label, R.drawable.ic_playlist_black, - taskManager.getQueue().size())); + DBReader.getQueue().size())); mediaItems.add(createBrowsableMediaItem(R.string.downloads_label, R.drawable.ic_download_black, DBReader.getDownloadedItems().size())); List<Feed> feeds = DBReader.getFeedList(); @@ -452,7 +452,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { List<FeedItem> feedItems; if (parentId.equals(getResources().getString(R.string.queue_label))) { - feedItems = taskManager.getQueue(); + feedItems = DBReader.getQueue(); } else if (parentId.equals(getResources().getString(R.string.downloads_label))) { feedItems = DBReader.getDownloadedItems(); } else if (parentId.startsWith("FeedId:")) { @@ -1427,10 +1427,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { i.putExtra("album", info.playable.getFeedTitle()); i.putExtra("track", info.playable.getEpisodeTitle()); i.putExtra("playing", isPlaying); - final List<FeedItem> queue = taskManager.getQueueIfLoaded(); - if (queue != null) { - i.putExtra("ListSize", queue.size()); - } i.putExtra("duration", (long) info.playable.getDuration()); i.putExtra("position", (long) info.playable.getPosition()); sendBroadcast(i); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java index 9ca7b6647..19032ba18 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java @@ -13,20 +13,11 @@ import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.widget.WidgetUpdater; import io.reactivex.disposables.Disposable; import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import java.util.List; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import de.danoeh.antennapod.event.FeedItemEvent; -import de.danoeh.antennapod.event.QueueEvent; -import de.danoeh.antennapod.model.feed.FeedItem; -import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.model.playback.Playable; import io.reactivex.Completable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -59,7 +50,6 @@ public class PlaybackServiceTaskManager { private ScheduledFuture<?> positionSaverFuture; private ScheduledFuture<?> widgetUpdaterFuture; private ScheduledFuture<?> sleepTimerFuture; - private volatile Future<List<FeedItem>> queueFuture; private volatile Disposable chapterLoaderFuture; private SleepTimer sleepTimer; @@ -82,88 +72,6 @@ public class PlaybackServiceTaskManager { t.setPriority(Thread.MIN_PRIORITY); return t; }); - loadQueue(); - EventBus.getDefault().register(this); - } - - @Subscribe - public void onEvent(QueueEvent event) { - Log.d(TAG, "onEvent(QueueEvent " + event +")"); - cancelQueueLoader(); - loadQueue(); - } - - private synchronized boolean isQueueLoaderActive() { - return queueFuture != null && !queueFuture.isDone(); - } - - private synchronized void cancelQueueLoader() { - if (isQueueLoaderActive()) { - queueFuture.cancel(true); - } - } - - private synchronized void loadQueue() { - if (!isQueueLoaderActive()) { - queueFuture = schedExecutor.submit(() -> DBReader.getQueue()); - } - } - - @Subscribe - public void onEvent(FeedItemEvent event) { - // Use case: when an item in the queue has been downloaded, - // listening to the event to ensure the downloaded item will be used. - Log.d(TAG, "onEvent(FeedItemEvent " + event + ")"); - - for (FeedItem item : event.items) { - if (isItemInQueue(item.getId())) { - Log.d(TAG, "onEvent(FeedItemEvent) - some item (" + item.getId() + ") in the queue has been updated (usually downloaded). Refresh the queue."); - cancelQueueLoader(); - loadQueue(); - return; - } - } - } - - private boolean isItemInQueue(long itemId) { - List<FeedItem> queue = getQueueIfLoaded(); - if (queue != null) { - for (FeedItem item : queue) { - if (item.getId() == itemId) { - return true; - } - } - } - return false; - } - - /** - * Returns the queue if it is already loaded or null if it hasn't been loaded yet. - * In order to wait until the queue has been loaded, use getQueue() - */ - public synchronized List<FeedItem> getQueueIfLoaded() { - if (queueFuture.isDone()) { - try { - return queueFuture.get(); - } catch (InterruptedException | ExecutionException | CancellationException e) { - e.printStackTrace(); - } - } - return null; - } - - /** - * Returns the queue or waits until the PSTM has loaded the queue from the database. - */ - public List<FeedItem> getQueue() throws InterruptedException { - if (queueFuture == null) { - loadQueue(); - } - try { - return queueFuture.get(); - } catch (ExecutionException e) { - throw new IllegalArgumentException(e); - } } /** @@ -289,7 +197,6 @@ public class PlaybackServiceTaskManager { } } - /** * Returns true if the widget updater is currently running. */ @@ -338,7 +245,6 @@ public class PlaybackServiceTaskManager { cancelPositionSaver(); cancelWidgetUpdater(); disableSleepTimer(); - cancelQueueLoader(); if (chapterLoaderFuture != null) { chapterLoaderFuture.dispose(); @@ -351,7 +257,6 @@ public class PlaybackServiceTaskManager { * execution of this method. */ public void shutdown() { - EventBus.getDefault().unregister(this); cancelAllTasks(); schedExecutor.shutdownNow(); } |