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.util.MimeTypes
|
||||
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.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -122,6 +118,10 @@ import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
|
||||
class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
private var _binding: FragmentPlayerBinding? = null
|
||||
@ -185,7 +185,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val mainActivity get() = activity as MainActivity
|
||||
private val windowInsetsControllerCompat get() = WindowCompat
|
||||
private val windowInsetsControllerCompat
|
||||
get() = WindowCompat
|
||||
.getInsetsController(mainActivity.window, mainActivity.window.decorView)
|
||||
|
||||
private var scrubbingTimeBar = false
|
||||
@ -200,18 +201,23 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
PlayerEvent.Play -> {
|
||||
exoPlayer.play()
|
||||
}
|
||||
|
||||
PlayerEvent.Pause -> {
|
||||
exoPlayer.pause()
|
||||
}
|
||||
|
||||
PlayerEvent.Forward -> {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition + PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
PlayerEvent.Rewind -> {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition - PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
PlayerEvent.Next -> {
|
||||
playNextVideo()
|
||||
}
|
||||
|
||||
PlayerEvent.Background -> {
|
||||
playOnBackground()
|
||||
// wait some time in order for the service to get started properly
|
||||
@ -219,6 +225,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
@ -298,6 +305,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
mainMotionLayout.progress = abs(progress)
|
||||
binding.player.hideController()
|
||||
binding.player.useController = false
|
||||
commentsViewModel.setCommentSheetExpand(false)
|
||||
eId = endId
|
||||
sId = startId
|
||||
}
|
||||
@ -310,6 +318,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// disable captions
|
||||
updateCaptionsLanguage(null)
|
||||
binding.player.useController = false
|
||||
commentsViewModel.setCommentSheetExpand(null)
|
||||
mainMotionLayout.progress = 1F
|
||||
(activity as MainActivity).requestOrientationChange()
|
||||
} else if (currentId == sId) {
|
||||
@ -317,6 +326,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// re-enable captions
|
||||
updateCaptionsLanguage(captionLanguage)
|
||||
binding.player.useController = true
|
||||
commentsViewModel.setCommentSheetExpand(true)
|
||||
mainMotionLayout.progress = 0F
|
||||
changeOrientationMode()
|
||||
}
|
||||
@ -360,6 +370,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
!exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> {
|
||||
exoPlayer.seekTo(0)
|
||||
}
|
||||
|
||||
!exoPlayer.isPlaying -> exoPlayer.play()
|
||||
else -> exoPlayer.pause()
|
||||
}
|
||||
@ -643,7 +654,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
if (segments.isEmpty()) return
|
||||
|
||||
exoPlayer.checkForSegments(requireContext(), segments, PlayerHelper.skipSegmentsManually)?.let { segmentEnd ->
|
||||
exoPlayer.checkForSegments(requireContext(), segments, PlayerHelper.skipSegmentsManually)
|
||||
?.let { segmentEnd ->
|
||||
binding.sbSkipBtn.visibility = View.VISIBLE
|
||||
binding.sbSkipBtn.setOnClickListener {
|
||||
exoPlayer.seekTo(segmentEnd)
|
||||
|
@ -16,6 +16,14 @@ class CommentsViewModel : ViewModel() {
|
||||
|
||||
val commentsPage = MutableLiveData<CommentsPage?>()
|
||||
|
||||
val commentSheetExpand = MutableLiveData<Boolean?>()
|
||||
|
||||
fun setCommentSheetExpand(value: Boolean?) {
|
||||
if (commentSheetExpand.value != value) {
|
||||
commentSheetExpand.value = value
|
||||
}
|
||||
}
|
||||
|
||||
private var nextPage: String? = null
|
||||
|
||||
var videoId: String? = null
|
||||
@ -64,5 +72,6 @@ class CommentsViewModel : ViewModel() {
|
||||
nextPage = null
|
||||
commentsPage.value = null
|
||||
videoId = null
|
||||
setCommentSheetExpand(null)
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,17 @@ class CommentsSheet : ExpandedBottomSheet() {
|
||||
.runOnCommit(this@CommentsSheet::onFragmentChanged)
|
||||
.commit()
|
||||
}
|
||||
|
||||
commentsViewModel.setCommentSheetExpand(true)
|
||||
commentsViewModel.commentSheetExpand.observe(viewLifecycleOwner) {
|
||||
if (it == null) {
|
||||
dismiss()
|
||||
} else if (it) {
|
||||
expand()
|
||||
} else {
|
||||
expand(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFragmentChanged() {
|
||||
@ -74,6 +85,7 @@ class CommentsSheet : ExpandedBottomSheet() {
|
||||
binding.btnBack.visibility = View.VISIBLE
|
||||
binding.commentsTitle.text = getString(R.string.replies)
|
||||
}
|
||||
|
||||
else -> {
|
||||
binding.btnBack.visibility = View.GONE
|
||||
binding.commentsTitle.text = getString(R.string.comments)
|
||||
|
@ -3,7 +3,6 @@ package com.github.libretube.ui.sheets
|
||||
import android.app.Dialog
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.R
|
||||
@ -12,19 +11,13 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
open class ExpandedBottomSheet : BottomSheetDialogFragment() {
|
||||
private val bottomSheet: FrameLayout? get() = dialog?.findViewById(R.id.design_bottom_sheet)
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
|
||||
|
||||
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) return dialog
|
||||
|
||||
dialog.setOnShowListener {
|
||||
(it as BottomSheetDialog).let { d ->
|
||||
(d.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout?)?.let { fl ->
|
||||
BottomSheetBehavior.from(fl).state =
|
||||
BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
}
|
||||
}
|
||||
dialog.setOnShowListener { expand() }
|
||||
|
||||
return dialog
|
||||
}
|
||||
@ -36,4 +29,15 @@ open class ExpandedBottomSheet : BottomSheetDialogFragment() {
|
||||
// ensure that the sheet doesn't hide parts of the video
|
||||
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