Skip to content

Commit 8a4b09d

Browse files
alihrheraBnyro
authored andcommitted
feat: Dismiss chapters sheet when hidden
Introduces a `BottomSheetListener` to allow communication between the player view and the chapters bottom sheet. When the chapters sheet is manually swiped down and hidden, it now correctly dismisses itself and notifies the player view to ensure its state is updated. fix: libre-tube#7831
1 parent 774c85e commit 8a4b09d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

app/src/main/java/com/github/libretube/ui/sheets/ExpandablePlayerSheet.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
package com.github.libretube.ui.sheets
22

3+
import android.app.Dialog
34
import android.os.Bundle
45
import android.view.View
6+
import android.widget.FrameLayout
57
import androidx.annotation.LayoutRes
68
import androidx.fragment.app.activityViewModels
79
import com.github.libretube.ui.models.CommonPlayerViewModel
10+
import com.google.android.material.bottomsheet.BottomSheetBehavior
11+
import com.google.android.material.bottomsheet.BottomSheetDialog
812

913
abstract class ExpandablePlayerSheet(@LayoutRes layoutResId: Int) :
1014
UndimmedBottomSheet(layoutResId) {
1115
private val commonPlayerViewModel: CommonPlayerViewModel by activityViewModels()
1216

17+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
18+
val dialog = super.onCreateDialog(savedInstanceState)
19+
if (commonPlayerViewModel.isFullscreen.value == true) {
20+
// prevent an issue where swiping outside of the bottom sheet would make
21+
// the app unresponsive by disabling slide actions to dismiss the bottom sheet in fullscreen
22+
dialog.setOnShowListener { dialogInterface ->
23+
val bottomSheetDialog = dialogInterface as BottomSheetDialog
24+
val bottomSheet =
25+
bottomSheetDialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
26+
?: return@setOnShowListener
27+
28+
val behavior = BottomSheetBehavior.from(bottomSheet)
29+
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
30+
override fun onStateChanged(bottomSheet: View, newState: Int) {
31+
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
32+
dismissAllowingStateLoss()
33+
}
34+
}
35+
36+
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
37+
})
38+
}
39+
}
40+
return dialog
41+
}
42+
1343
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
1444
super.onViewCreated(view, savedInstanceState)
1545

0 commit comments

Comments
 (0)