From b33ecff67e004fb54b00bf24a27323c64269cc7a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 27 Apr 2023 20:24:15 +0200 Subject: [PATCH] Fix top margin when viewing video in vertical fullscreen --- .../libretube/ui/fragments/PlayerFragment.kt | 6 +++--- .../libretube/ui/fragments/PlaylistFragment.kt | 15 ++++++++++----- .../libretube/ui/views/CustomExoPlayerView.kt | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) 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 293726a98..8638eaab9 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 @@ -396,7 +396,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { } // FullScreen button trigger - // hide fullscreen button if auto rotation enabled + // hide fullscreen button if autorotation enabled playerBinding.fullscreen.isInvisible = PlayerHelper.autoRotationEnabled playerBinding.fullscreen.setOnClickListener { // hide player controller @@ -508,7 +508,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width - // different orientations of the video are only available when auto rotation is disabled + // different orientations of the video are only available when autorotation is disabled val orientation = PlayerHelper.getOrientation(width, height) mainActivity.requestedOrientation = orientation } @@ -538,7 +538,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { playerBinding.exoTitle.visibility = View.INVISIBLE if (!PlayerHelper.autoRotationEnabled) { - // switch back to portrait mode if auto rotation disabled + // switch back to portrait mode if autorotation disabled mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 286deccfd..0a0afa3d1 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -237,13 +237,18 @@ class PlaylistFragment : Fragment() { } private fun showPlaylistVideos(playlist: Playlist) { - val videos = if (playlistType == PlaylistType.PUBLIC) playlistFeed - else { + val videos = if (playlistType == PlaylistType.PUBLIC) { + playlistFeed + } else { when (selectedSortOrder) { 0, 1 -> { - if (playlistType == PlaylistType.LOCAL) playlistFeed.sortedBy { - it.url.orEmpty().toInt() - } else playlistFeed + if (playlistType == PlaylistType.LOCAL) { + playlistFeed.sortedBy { + it.url.orEmpty().toInt() + } + } else { + playlistFeed + } } 2, 3 -> { playlistFeed.sortedBy { it.duration } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index a234171a1..9da3b6f50 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -219,6 +219,7 @@ internal class CustomExoPlayerView( playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen -> WindowHelper.toggleFullscreen(activity, isFullscreen) + updateTopBarMargin() } } @@ -644,11 +645,13 @@ internal class CustomExoPlayerView( * Add extra margin to the top bar to not overlap the status bar */ private fun updateTopBarMargin() { - val isFullscreen = - resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE || - playerViewModel?.isFullscreen?.value == true + val margin = when { + resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE -> 10 + playerViewModel?.isFullscreen?.value == true -> 20 + else -> 0 + } binding.topBar.updateLayoutParams { - topMargin = (if (isFullscreen) 10 else 0).dpToPx().toInt() + topMargin = margin.dpToPx().toInt() } }