mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
feat: dismiss chapters sheet when minimizing video
This commit is contained in:
parent
c881b6ff5c
commit
fd0b89cfc7
@ -517,7 +517,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
mainMotionLayout.progress = abs(progress)
|
||||
}
|
||||
disableController()
|
||||
commentsViewModel.setCommentSheetExpand(false)
|
||||
commonPlayerViewModel.setSheetExpand(false)
|
||||
transitionEndId = endId
|
||||
transitionStartId = startId
|
||||
}
|
||||
@ -530,7 +530,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// re-enable captions
|
||||
updateCurrentSubtitle(viewModel.currentSubtitle)
|
||||
binding.player.useController = true
|
||||
commentsViewModel.setCommentSheetExpand(true)
|
||||
commonPlayerViewModel.setSheetExpand(true)
|
||||
mainMotionLayout.progress = 0F
|
||||
changeOrientationMode()
|
||||
} else if (currentId == transitionEndId) {
|
||||
@ -538,7 +538,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// disable captions temporarily
|
||||
updateCurrentSubtitle(null)
|
||||
disableController()
|
||||
commentsViewModel.setCommentSheetExpand(null)
|
||||
commonPlayerViewModel.setSheetExpand(null)
|
||||
binding.sbSkipBtn.isGone = true
|
||||
if (NavBarHelper.hasTabs()) {
|
||||
mainMotionLayout.progress = 1F
|
||||
@ -773,7 +773,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
updateFullscreenOrientation()
|
||||
|
||||
commentsViewModel.setCommentSheetExpand(null)
|
||||
commonPlayerViewModel.setSheetExpand(null)
|
||||
|
||||
updateResolution(true)
|
||||
openOrCloseFullscreenDialog(true)
|
||||
|
@ -30,22 +30,13 @@ class CommentsViewModel : ViewModel() {
|
||||
private val _commentCountLiveData = MutableLiveData<Long>()
|
||||
val commentCountLiveData: LiveData<Long> = _commentCountLiveData
|
||||
|
||||
val commentSheetExpand = MutableLiveData<Boolean?>()
|
||||
|
||||
private val _currentCommentsPosition = MutableLiveData(0)
|
||||
val currentCommentsPosition: LiveData<Int> = _currentCommentsPosition
|
||||
|
||||
private val _currentRepliesPosition = MutableLiveData(0)
|
||||
val currentRepliesPosition: LiveData<Int> = _currentRepliesPosition
|
||||
|
||||
fun setCommentSheetExpand(value: Boolean?) {
|
||||
if (commentSheetExpand.value != value) {
|
||||
commentSheetExpand.value = value
|
||||
}
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
setCommentSheetExpand(null)
|
||||
_currentCommentsPosition.value = 0
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,16 @@ package com.github.libretube.ui.models
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.github.libretube.extensions.updateIfChanged
|
||||
|
||||
class CommonPlayerViewModel : ViewModel() {
|
||||
val isMiniPlayerVisible = MutableLiveData(false)
|
||||
val isFullscreen = MutableLiveData(false)
|
||||
var maxSheetHeightPx = 0
|
||||
|
||||
val sheetExpand = MutableLiveData<Boolean?>()
|
||||
|
||||
fun setSheetExpand(state: Boolean?) {
|
||||
sheetExpand.updateIfChanged(state)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import com.github.libretube.databinding.BottomSheetBinding
|
||||
import com.github.libretube.ui.adapters.ChaptersAdapter
|
||||
import com.github.libretube.ui.models.ChaptersViewModel
|
||||
|
||||
class ChaptersBottomSheet : UndimmedBottomSheet() {
|
||||
class ChaptersBottomSheet : ExpandablePlayerSheet() {
|
||||
private var _binding: BottomSheetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
|
@ -12,15 +12,13 @@ import androidx.fragment.app.setFragmentResult
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.CommentsSheetBinding
|
||||
import com.github.libretube.ui.fragments.CommentsMainFragment
|
||||
import com.github.libretube.ui.models.CommentsViewModel
|
||||
import com.github.libretube.ui.models.CommonPlayerViewModel
|
||||
|
||||
class CommentsSheet : UndimmedBottomSheet() {
|
||||
class CommentsSheet : ExpandablePlayerSheet() {
|
||||
private var _binding: CommentsSheetBinding? = null
|
||||
val binding get() = _binding!!
|
||||
|
||||
private val commonPlayerViewModel: CommonPlayerViewModel by activityViewModels()
|
||||
private val commentsViewModel: CommentsViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@ -56,15 +54,6 @@ class CommentsSheet : UndimmedBottomSheet() {
|
||||
childFragmentManager.commit {
|
||||
replace<CommentsMainFragment>(R.id.commentFragContainer, args = arguments)
|
||||
}
|
||||
|
||||
commentsViewModel.setCommentSheetExpand(true)
|
||||
commentsViewModel.commentSheetExpand.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
true -> expand()
|
||||
false -> expand(true)
|
||||
else -> dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.github.libretube.ui.sheets
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.github.libretube.ui.models.CommonPlayerViewModel
|
||||
|
||||
abstract class ExpandablePlayerSheet: UndimmedBottomSheet() {
|
||||
private val commonPlayerViewModel: CommonPlayerViewModel by activityViewModels()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
commonPlayerViewModel.setSheetExpand(true)
|
||||
commonPlayerViewModel.sheetExpand.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
true -> expand()
|
||||
false -> expand(true)
|
||||
else -> dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
commonPlayerViewModel.setSheetExpand(null)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user