fix: show exit fullscreen button on auto-fullscreen for shorts

This commit is contained in:
Bnyro 2023-11-05 14:16:45 +01:00
parent 314c594368
commit d0a4e53901

View File

@ -115,16 +115,16 @@ import com.github.libretube.util.TextUtils.toTimeInSeconds
import com.github.libretube.util.YoutubeHlsPlaylistParser import com.github.libretube.util.YoutubeHlsPlaylistParser
import com.github.libretube.util.deArrow import com.github.libretube.util.deArrow
import com.google.android.material.elevation.SurfaceColors import com.google.android.material.elevation.SurfaceColors
import java.io.IOException
import java.util.*
import java.util.concurrent.Executors
import kotlin.math.abs
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException
import java.util.*
import java.util.concurrent.Executors
import kotlin.math.abs
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class PlayerFragment : Fragment(), OnlinePlayerOptions { class PlayerFragment : Fragment(), OnlinePlayerOptions {
@ -521,7 +521,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// FullScreen button trigger // FullScreen button trigger
// hide fullscreen button if autorotation enabled // hide fullscreen button if autorotation enabled
playerBinding.fullscreen.isInvisible = PlayerHelper.autoFullscreenEnabled
playerBinding.fullscreen.setOnClickListener { playerBinding.fullscreen.setOnClickListener {
// hide player controller // hide player controller
binding.player.hideController() binding.player.hideController()
@ -531,6 +530,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
} else { } else {
// exit fullscreen mode // exit fullscreen mode
unsetFullscreen() unsetFullscreen()
// disable the fullscreen button for auto fullscreen
// this is necessary to hide the button after an auto fullscreen for shorts
playerBinding.fullscreen.isVisible = !PlayerHelper.autoFullscreenEnabled
} }
} }
@ -868,16 +871,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
PlayingQueue.insertRelatedStreams(streams.relatedStreams) PlayingQueue.insertRelatedStreams(streams.relatedStreams)
} }
if (PreferenceHelper.getBoolean(PreferenceKeys.AUTO_FULLSCREEN_SHORTS, false)) { val videoStream = streams.videoStreams.firstOrNull()
val videoStream = streams.videoStreams.firstOrNull() val isShort = PlayingQueue.getCurrent()?.isShort == true ||
if (PlayingQueue.getCurrent()?.isShort == true ||
(videoStream?.height ?: 0) > (videoStream?.width ?: 0) (videoStream?.height ?: 0) > (videoStream?.width ?: 0)
) {
withContext(Dispatchers.Main) {
if (binding.playerMotionLayout.progress == 0f) setFullscreen()
}
}
}
PlayingQueue.setOnQueueTapListener { streamItem -> PlayingQueue.setOnQueueTapListener { streamItem ->
streamItem.url?.toID()?.let { playNextVideo(it) } streamItem.url?.toID()?.let { playNextVideo(it) }
@ -890,6 +886,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// set media sources for the player // set media sources for the player
initStreamSources() initStreamSources()
if (PreferenceHelper.getBoolean(PreferenceKeys.AUTO_FULLSCREEN_SHORTS, false)
&& isShort && binding.playerMotionLayout.progress == 0f
) {
setFullscreen()
playerBinding.fullscreen.isVisible = true
} else {
// disable the fullscreen button for auto fullscreen
playerBinding.fullscreen.isVisible = !PlayerHelper.autoFullscreenEnabled
}
binding.player.apply { binding.player.apply {
useController = false useController = false
player = exoPlayer player = exoPlayer
@ -905,7 +911,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (binding.playerMotionLayout.progress != 1.0f) { if (binding.playerMotionLayout.progress != 1.0f) {
// show controllers when not in picture in picture mode // show controllers when not in picture in picture mode
val inPipMode = PlayerHelper.pipEnabled && val inPipMode = PlayerHelper.pipEnabled &&
PictureInPictureCompat.isInPictureInPictureMode(requireActivity()) PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
if (!inPipMode) { if (!inPipMode) {
binding.player.useController = true binding.player.useController = true
} }
@ -1157,9 +1163,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// if the user is scrubbing the time bar, don't update // if the user is scrubbing the time bar, don't update
if (scrubbingTimeBar && !forceUpdate) return if (scrubbingTimeBar && !forceUpdate) return
val chapterName = PlayerHelper.getCurrentChapterIndex(exoPlayer.currentPosition, viewModel.chapters)?.let { val chapterName =
viewModel.chapters[it].title.trim() PlayerHelper.getCurrentChapterIndex(exoPlayer.currentPosition, viewModel.chapters)
} ?: getString(R.string.no_chapter) ?.let {
viewModel.chapters[it].title.trim()
} ?: getString(R.string.no_chapter)
// change the chapter name textView text to the chapterName // change the chapter name textView text to the chapterName
if (chapterName != playerBinding.chapterName.text) { if (chapterName != playerBinding.chapterName.text) {
@ -1368,7 +1376,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
} else { } else {
// go to portrait mode // go to portrait mode
mainActivity.requestedOrientation = (requireActivity() as BaseActivity).screenOrientationPref mainActivity.requestedOrientation =
(requireActivity() as BaseActivity).screenOrientationPref
} }
} }