Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
mainMotionLayout.progress = abs(progress)
}
disableController()
commentsViewModel.setCommentSheetExpand(false)
commonPlayerViewModel.setSheetExpand(false)
transitionEndId = endId
transitionStartId = startId
}
Expand All @@ -530,15 +530,15 @@ 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) {
commonPlayerViewModel.isMiniPlayerVisible.value = true
// disable captions temporarily
updateCurrentSubtitle(null)
disableController()
commentsViewModel.setCommentSheetExpand(null)
commonPlayerViewModel.setSheetExpand(null)
binding.sbSkipBtn.isGone = true
if (NavBarHelper.hasTabs()) {
mainMotionLayout.progress = 1F
Expand Down Expand Up @@ -773,7 +773,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {

updateFullscreenOrientation()

commentsViewModel.setCommentSheetExpand(null)
commonPlayerViewModel.setSheetExpand(null)

updateResolution(true)
openOrCloseFullscreenDialog(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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