From b0b95f0a05c216e8af62b21433658e2cc0c55441 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 30 Sep 2022 17:46:13 +0200 Subject: Reorder queue section when pressing play, not when pausing --- .../de/danoeh/antennapod/ui/home/sections/QueueSection.java | 12 +++++++++++- .../antennapod/view/viewholder/HorizontalItemViewHolder.java | 2 +- .../antennapod/core/service/playback/PlaybackService.java | 1 + .../de/danoeh/antennapod/storage/database/PodDBAdapter.java | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/QueueSection.java b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/QueueSection.java index efff7927e..57fc85192 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/QueueSection.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/QueueSection.java @@ -113,14 +113,24 @@ public class QueueSection extends HomeSection { if (listAdapter == null) { return; } + boolean foundCurrentlyPlayingItem = false; + boolean currentlyPlayingItemIsFirst = true; for (int i = 0; i < listAdapter.getItemCount(); i++) { HorizontalItemViewHolder holder = (HorizontalItemViewHolder) viewBinding.recyclerView.findViewHolderForAdapterPosition(i); - if (holder != null && holder.isCurrentlyPlayingItem()) { + if (holder == null) { + continue; + } + if (holder.isCurrentlyPlayingItem()) { holder.notifyPlaybackPositionUpdated(event); + foundCurrentlyPlayingItem = true; + currentlyPlayingItemIsFirst = (i == 0); break; } } + if (!foundCurrentlyPlayingItem || !currentlyPlayingItemIsFirst) { + loadItems(); + } } @Override 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 9723417ce..f2d8e628c 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 @@ -96,7 +96,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { } public boolean isCurrentlyPlayingItem() { - return item.getMedia() != null && FeedItemUtil.isCurrentlyPlaying(item.getMedia()); + return item != null && item.getMedia() != null && FeedItemUtil.isCurrentlyPlaying(item.getMedia()); } public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) { 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 08a01f0a7..391c2b75d 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 @@ -828,6 +828,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { break; case PLAYING: PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); + saveCurrentPosition(true, null, INVALID_TIME); updateNotificationAndMediaSession(newInfo.playable); setupPositionObserver(); stateManager.validStartCommandWasReceived(); diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java index c0ca018f1..39454a106 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java @@ -1005,7 +1005,10 @@ public class PodDBAdapter { + " INNER JOIN " + TABLE_NAME_FEED_ITEMS + " ON " + SELECT_KEY_ITEM_ID + " = " + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM + JOIN_FEED_ITEM_AND_MEDIA - + " ORDER BY " + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + " >= 1000 DESC , " + // In the front: Episodes that have a position >1sec, but also the episode that was just started + + " ORDER BY (" + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + " >= 1000" + + " OR " + TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME + + " >= " + (System.currentTimeMillis() - 30000) + ") DESC , " + TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME + " DESC , " + TABLE_NAME_QUEUE + "." + KEY_ID + " LIMIT " + limit; return db.rawQuery(query, null); -- cgit v1.2.3