From 4a278ef102d65a2c1f67c7603781cba3a042f11b Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 11 Oct 2022 21:27:04 +0200 Subject: [PATCH] Hide play queue button in VideoDetailsFragment mini player when the play queue is empty Related PR introducing the button: #8946 --- .../fragments/detail/VideoDetailFragment.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index bf84c732545..580585d4e4a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -248,6 +248,7 @@ && isAutoplayEnabled() autoPlayEnabled = true; // forcefully start playing openVideoPlayerAutoFullscreen(); } + updateOverlayPlayQueueButtonVisibility(); } @Override @@ -337,6 +338,8 @@ public void onResume() { activity.sendBroadcast(new Intent(ACTION_VIDEO_FRAGMENT_RESUMED)); + updateOverlayPlayQueueButtonVisibility(); + setupBrightness(); if (tabSettingsChanged) { @@ -1820,6 +1823,14 @@ public void onQueueUpdate(final PlayQueue queue) { + title + "], playQueue = [" + playQueue + "]"); } + // Register broadcast receiver to listen to playQueue changes + // and hide the overlayPlayQueueButton when the playQueue is empty / destroyed. + if (playQueue != null && playQueue.getBroadcastReceiver() != null) { + playQueue.getBroadcastReceiver().subscribe( + event -> updateOverlayPlayQueueButtonVisibility() + ); + } + // This should be the only place where we push data to stack. // It will allow to have live instance of PlayQueue with actual information about // deleted/added items inside Channel/Playlist queue and makes possible to have @@ -1926,6 +1937,7 @@ public void onServiceStopped() { currentInfo.getUploaderName(), currentInfo.getThumbnailUrl()); } + updateOverlayPlayQueueButtonVisibility(); } @Override @@ -2392,6 +2404,18 @@ public void onSlide(@NonNull final View bottomSheet, final float slideOffset) { }); } + private void updateOverlayPlayQueueButtonVisibility() { + final boolean isPlayQueueEmpty = + player == null // no player => no play queue :) + || player.getPlayQueue() == null + || player.getPlayQueue().isEmpty(); + if (binding != null) { + // binding is null when rotating the device... + binding.overlayPlayQueueButton.setVisibility( + isPlayQueueEmpty ? View.GONE : View.VISIBLE); + } + } + private void updateOverlayData(@Nullable final String overlayTitle, @Nullable final String uploader, @Nullable final String thumbnailUrl) {