From 1140c34d4da9197f0cbbfd41043a64c06e8707bb Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 14 Jan 2023 12:08:06 +0100 Subject: [PATCH] Fix visiblity of skip and prev btns when player locked --- .../libretube/ui/extensions/SetInvisible.kt | 7 ------- .../libretube/ui/fragments/PlayerFragment.kt | 21 ++++++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/ui/extensions/SetInvisible.kt diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetInvisible.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetInvisible.kt deleted file mode 100644 index b5cb0f836..000000000 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetInvisible.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.libretube.ui.extensions - -import android.view.View - -fun View.setInvisible(value: Boolean) { - this.visibility = if (value) View.INVISIBLE else View.VISIBLE -} diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index f041bd46f..43998bf69 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -75,7 +75,6 @@ import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog import com.github.libretube.ui.extensions.setAspectRatio import com.github.libretube.ui.extensions.setFormattedHtml -import com.github.libretube.ui.extensions.setInvisible import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.interfaces.OnlinePlayerOptions import com.github.libretube.ui.models.CommentsViewModel @@ -1078,9 +1077,21 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { private fun syncQueueButtons() { if (!PlayerHelper.skipButtonsEnabled) return - // next and previous buttons - playerBinding.skipPrev.setInvisible(!PlayingQueue.hasPrev()) - playerBinding.skipNext.setInvisible(!PlayingQueue.hasNext()) + // toggle the visibility of next and prev buttons based on queue and whether the player view is locked + playerBinding.skipPrev.visibility = if ( + PlayingQueue.hasPrev() && !binding.player.isPlayerLocked + ) { + View.VISIBLE + } else { + View.INVISIBLE + } + playerBinding.skipNext.visibility = if ( + PlayingQueue.hasNext() && !binding.player.isPlayerLocked + ) { + View.VISIBLE + } else { + View.INVISIBLE + } handler.postDelayed(this::syncQueueButtons, 100) } @@ -1203,7 +1214,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { * Get all available player resolutions */ private fun getAvailableResolutions(): List { - val resolutions = exoPlayer.currentTracks.groups.map { group -> + val resolutions = exoPlayer.currentTracks.groups.asSequence().map { group -> (0 until group.length).map { group.getTrackFormat(it).height }