mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Half expand comment dialog when roll player
This commit is contained in:
parent
e69090eef1
commit
f6884204fd
@ -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()
|
||||||
}
|
}
|
||||||
@ -643,13 +654,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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,17 @@ class CommentsSheet : ExpandedBottomSheet() {
|
|||||||
.runOnCommit(this@CommentsSheet::onFragmentChanged)
|
.runOnCommit(this@CommentsSheet::onFragmentChanged)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commentsViewModel.setCommentSheetExpand(true)
|
||||||
|
commentsViewModel.commentSheetExpand.observe(viewLifecycleOwner) {
|
||||||
|
if (it == null) {
|
||||||
|
dismiss()
|
||||||
|
} else if (it) {
|
||||||
|
expand()
|
||||||
|
} else {
|
||||||
|
expand(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onFragmentChanged() {
|
private fun onFragmentChanged() {
|
||||||
@ -74,6 +85,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)
|
||||||
|
@ -3,7 +3,6 @@ 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
|
||||||
@ -12,19 +11,13 @@ 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 +29,15 @@ 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(half: Boolean = false) {
|
||||||
|
bottomSheet?.let { fl ->
|
||||||
|
val bottomSheetInfoBehavior = BottomSheetBehavior.from(fl)
|
||||||
|
bottomSheetInfoBehavior.state = if (half) {
|
||||||
|
BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||||
|
} else {
|
||||||
|
BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user