Merge pull request #6109 from ByteHamster/home-only-greater-zero

Tweak Queue section on home screen
This commit is contained in:
ByteHamster 2022-10-14 19:03:09 +02:00 committed by GitHub
commit 504002c48f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -113,14 +113,24 @@ public class QueueSection extends HomeSection {
if (listAdapter == null) { if (listAdapter == null) {
return; return;
} }
boolean foundCurrentlyPlayingItem = false;
boolean currentlyPlayingItemIsFirst = true;
for (int i = 0; i < listAdapter.getItemCount(); i++) { for (int i = 0; i < listAdapter.getItemCount(); i++) {
HorizontalItemViewHolder holder = (HorizontalItemViewHolder) HorizontalItemViewHolder holder = (HorizontalItemViewHolder)
viewBinding.recyclerView.findViewHolderForAdapterPosition(i); viewBinding.recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) { if (holder == null) {
continue;
}
if (holder.isCurrentlyPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event); holder.notifyPlaybackPositionUpdated(event);
foundCurrentlyPlayingItem = true;
currentlyPlayingItemIsFirst = (i == 0);
break; break;
} }
} }
if (!foundCurrentlyPlayingItem || !currentlyPlayingItemIsFirst) {
loadItems();
}
} }
@Override @Override

View File

@ -96,7 +96,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder {
} }
public boolean isCurrentlyPlayingItem() { 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) { public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) {

View File

@ -828,6 +828,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
break; break;
case PLAYING: case PLAYING:
PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus());
saveCurrentPosition(true, null, INVALID_TIME);
updateNotificationAndMediaSession(newInfo.playable); updateNotificationAndMediaSession(newInfo.playable);
setupPositionObserver(); setupPositionObserver();
stateManager.validStartCommandWasReceived(); stateManager.validStartCommandWasReceived();

View File

@ -1005,7 +1005,10 @@ public class PodDBAdapter {
+ " INNER JOIN " + TABLE_NAME_FEED_ITEMS + " INNER JOIN " + TABLE_NAME_FEED_ITEMS
+ " ON " + SELECT_KEY_ITEM_ID + " = " + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM + " ON " + SELECT_KEY_ITEM_ID + " = " + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM
+ JOIN_FEED_ITEM_AND_MEDIA + 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 + TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME + " DESC , " + TABLE_NAME_QUEUE + "." + KEY_ID
+ " LIMIT " + limit; + " LIMIT " + limit;
return db.rawQuery(query, null); return db.rawQuery(query, null);