diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-10-14 19:03:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-14 19:03:09 +0200 |
commit | 504002c48f2760d4b62ef75b4806579358225e57 (patch) | |
tree | 66520f058aeeb2cb459b8984e6e5c04b9a30c1f0 | |
parent | 232a0266518dd21eb5bf3e05ca55cc20c6ee9386 (diff) | |
parent | b0b95f0a05c216e8af62b21433658e2cc0c55441 (diff) | |
download | AntennaPod-504002c48f2760d4b62ef75b4806579358225e57.zip |
Merge pull request #6109 from ByteHamster/home-only-greater-zero
Tweak Queue section on home screen
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 329c1e7b9..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 + ">0 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); |