Merge pull request #3632 from xz-dev/master

Half expand comment dialog when roll player to avoid comments dialog hide the player
This commit is contained in:
Bnyro 2023-04-27 08:36:15 +02:00 committed by GitHub
commit 32d9abc5a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 23 deletions

View File

@ -110,10 +110,6 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.util.MimeTypes import com.google.android.exoplayer2.util.MimeTypes
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
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
@ -122,6 +118,10 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
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
class PlayerFragment : Fragment(), OnlinePlayerOptions { class PlayerFragment : Fragment(), OnlinePlayerOptions {
private var _binding: FragmentPlayerBinding? = null private var _binding: FragmentPlayerBinding? = null
@ -185,8 +185,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
private val mainActivity get() = activity as MainActivity private val mainActivity get() = activity as MainActivity
private val windowInsetsControllerCompat get() = WindowCompat private val windowInsetsControllerCompat
.getInsetsController(mainActivity.window, mainActivity.window.decorView) get() = WindowCompat
.getInsetsController(mainActivity.window, mainActivity.window.decorView)
private var scrubbingTimeBar = false private var scrubbingTimeBar = false
@ -200,18 +201,23 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
PlayerEvent.Play -> { PlayerEvent.Play -> {
exoPlayer.play() exoPlayer.play()
} }
PlayerEvent.Pause -> { PlayerEvent.Pause -> {
exoPlayer.pause() exoPlayer.pause()
} }
PlayerEvent.Forward -> { PlayerEvent.Forward -> {
exoPlayer.seekTo(exoPlayer.currentPosition + PlayerHelper.seekIncrement) exoPlayer.seekTo(exoPlayer.currentPosition + PlayerHelper.seekIncrement)
} }
PlayerEvent.Rewind -> { PlayerEvent.Rewind -> {
exoPlayer.seekTo(exoPlayer.currentPosition - PlayerHelper.seekIncrement) exoPlayer.seekTo(exoPlayer.currentPosition - PlayerHelper.seekIncrement)
} }
PlayerEvent.Next -> { PlayerEvent.Next -> {
playNextVideo() playNextVideo()
} }
PlayerEvent.Background -> { PlayerEvent.Background -> {
playOnBackground() playOnBackground()
// wait some time in order for the service to get started properly // wait some time in order for the service to get started properly
@ -219,6 +225,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
activity?.finish() activity?.finish()
} }
} }
else -> { else -> {
} }
} }
@ -298,6 +305,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
mainMotionLayout.progress = abs(progress) mainMotionLayout.progress = abs(progress)
binding.player.hideController() binding.player.hideController()
binding.player.useController = false binding.player.useController = false
commentsViewModel.setCommentSheetExpand(false)
eId = endId eId = endId
sId = startId sId = startId
} }
@ -310,6 +318,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// disable captions // disable captions
updateCaptionsLanguage(null) updateCaptionsLanguage(null)
binding.player.useController = false binding.player.useController = false
commentsViewModel.setCommentSheetExpand(null)
mainMotionLayout.progress = 1F mainMotionLayout.progress = 1F
(activity as MainActivity).requestOrientationChange() (activity as MainActivity).requestOrientationChange()
} else if (currentId == sId) { } else if (currentId == sId) {
@ -317,6 +326,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// re-enable captions // re-enable captions
updateCaptionsLanguage(captionLanguage) updateCaptionsLanguage(captionLanguage)
binding.player.useController = true binding.player.useController = true
commentsViewModel.setCommentSheetExpand(true)
mainMotionLayout.progress = 0F mainMotionLayout.progress = 0F
changeOrientationMode() changeOrientationMode()
} }
@ -360,6 +370,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
!exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> { !exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> {
exoPlayer.seekTo(0) exoPlayer.seekTo(0)
} }
!exoPlayer.isPlaying -> exoPlayer.play() !exoPlayer.isPlaying -> exoPlayer.play()
else -> exoPlayer.pause() else -> exoPlayer.pause()
} }
@ -489,6 +500,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.mainContainer.isClickable = true binding.mainContainer.isClickable = true
binding.linLayout.visibility = View.GONE binding.linLayout.visibility = View.GONE
commentsViewModel.setCommentSheetExpand(null)
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE playerBinding.exoTitle.visibility = View.VISIBLE
@ -643,13 +655,14 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (segments.isEmpty()) return if (segments.isEmpty()) return
exoPlayer.checkForSegments(requireContext(), segments, PlayerHelper.skipSegmentsManually)?.let { segmentEnd -> exoPlayer.checkForSegments(requireContext(), segments, PlayerHelper.skipSegmentsManually)
binding.sbSkipBtn.visibility = View.VISIBLE ?.let { segmentEnd ->
binding.sbSkipBtn.setOnClickListener { binding.sbSkipBtn.visibility = View.VISIBLE
exoPlayer.seekTo(segmentEnd) binding.sbSkipBtn.setOnClickListener {
exoPlayer.seekTo(segmentEnd)
}
return
} }
return
}
if (PlayerHelper.skipSegmentsManually) binding.sbSkipBtn.visibility = View.GONE if (PlayerHelper.skipSegmentsManually) binding.sbSkipBtn.visibility = View.GONE
} }
@ -1294,7 +1307,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
when { when {
// LBRY HLS // LBRY HLS
PreferenceHelper.getBoolean(PreferenceKeys.LBRY_HLS, false) && streams.videoStreams.any { PreferenceHelper.getBoolean(
PreferenceKeys.LBRY_HLS,
false
) && streams.videoStreams.any {
it.quality.orEmpty().contains("LBRY HLS") it.quality.orEmpty().contains("LBRY HLS")
} -> { } -> {
val lbryHlsUrl = streams.videoStreams.first { val lbryHlsUrl = streams.videoStreams.first {
@ -1303,7 +1319,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
setMediaSource(lbryHlsUrl.toUri(), MimeTypes.APPLICATION_M3U8) setMediaSource(lbryHlsUrl.toUri(), MimeTypes.APPLICATION_M3U8)
} }
// DASH // DASH
!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) && streams.videoStreams.isNotEmpty() -> { !PreferenceHelper.getBoolean(
PreferenceKeys.USE_HLS_OVER_DASH,
false
) && streams.videoStreams.isNotEmpty() -> {
// only use the dash manifest generated by YT if either it's a livestream or no other source is available // only use the dash manifest generated by YT if either it's a livestream or no other source is available
val uri = streams.dash?.let { ProxyHelper.unwrapIfEnabled(it) }?.toUri().takeIf { val uri = streams.dash?.let { ProxyHelper.unwrapIfEnabled(it) }?.toUri().takeIf {
streams.livestream || streams.videoStreams.isEmpty() streams.livestream || streams.videoStreams.isEmpty()

View File

@ -16,6 +16,14 @@ class CommentsViewModel : ViewModel() {
val commentsPage = MutableLiveData<CommentsPage?>() val commentsPage = MutableLiveData<CommentsPage?>()
val commentSheetExpand = MutableLiveData<Boolean?>()
fun setCommentSheetExpand(value: Boolean?) {
if (commentSheetExpand.value != value) {
commentSheetExpand.value = value
}
}
private var nextPage: String? = null private var nextPage: String? = null
var videoId: String? = null var videoId: String? = null
@ -64,5 +72,6 @@ class CommentsViewModel : ViewModel() {
nextPage = null nextPage = null
commentsPage.value = null commentsPage.value = null
videoId = null videoId = null
setCommentSheetExpand(null)
} }
} }

View File

@ -65,6 +65,15 @@ class CommentsSheet : ExpandedBottomSheet() {
.runOnCommit(this@CommentsSheet::onFragmentChanged) .runOnCommit(this@CommentsSheet::onFragmentChanged)
.commit() .commit()
} }
commentsViewModel.setCommentSheetExpand(true)
commentsViewModel.commentSheetExpand.observe(viewLifecycleOwner) {
when (it) {
true -> expand()
false -> expand(true)
else -> dismiss()
}
}
} }
private fun onFragmentChanged() { private fun onFragmentChanged() {
@ -74,6 +83,7 @@ class CommentsSheet : ExpandedBottomSheet() {
binding.btnBack.visibility = View.VISIBLE binding.btnBack.visibility = View.VISIBLE
binding.commentsTitle.text = getString(R.string.replies) binding.commentsTitle.text = getString(R.string.replies)
} }
else -> { else -> {
binding.btnBack.visibility = View.GONE binding.btnBack.visibility = View.GONE
binding.commentsTitle.text = getString(R.string.comments) binding.commentsTitle.text = getString(R.string.comments)

View File

@ -3,28 +3,22 @@ package com.github.libretube.ui.sheets
import android.app.Dialog import android.app.Dialog
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import com.google.android.material.R import com.google.android.material.R
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.PEEK_HEIGHT_AUTO
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
open class ExpandedBottomSheet : BottomSheetDialogFragment() { open class ExpandedBottomSheet : BottomSheetDialogFragment() {
private val bottomSheet: FrameLayout? get() = dialog?.findViewById(R.id.design_bottom_sheet)
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) return dialog if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) return dialog
dialog.setOnShowListener { dialog.setOnShowListener { expand() }
(it as BottomSheetDialog).let { d ->
(d.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout?)?.let { fl ->
BottomSheetBehavior.from(fl).state =
BottomSheetBehavior.STATE_EXPANDED
}
}
}
return dialog return dialog
} }
@ -36,4 +30,17 @@ open class ExpandedBottomSheet : BottomSheetDialogFragment() {
// ensure that the sheet doesn't hide parts of the video // ensure that the sheet doesn't hide parts of the video
dialog?.dismiss() dialog?.dismiss()
} }
fun expand(collapse: Boolean = false) {
bottomSheet?.let { fl ->
val bottomSheetInfoBehavior = BottomSheetBehavior.from(fl)
if (collapse) {
bottomSheetInfoBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
bottomSheetInfoBehavior.setPeekHeight(0, true)
} else {
bottomSheetInfoBehavior.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetInfoBehavior.setPeekHeight(PEEK_HEIGHT_AUTO, true)
}
}
}
} }