|
1 | 1 | package com.github.libretube.ui.sheets |
2 | 2 |
|
| 3 | +import android.app.Dialog |
3 | 4 | import android.os.Bundle |
4 | 5 | import android.view.View |
| 6 | +import android.widget.FrameLayout |
5 | 7 | import androidx.annotation.LayoutRes |
6 | 8 | import androidx.fragment.app.activityViewModels |
7 | 9 | import com.github.libretube.ui.models.CommonPlayerViewModel |
| 10 | +import com.google.android.material.bottomsheet.BottomSheetBehavior |
| 11 | +import com.google.android.material.bottomsheet.BottomSheetDialog |
8 | 12 |
|
9 | 13 | abstract class ExpandablePlayerSheet(@LayoutRes layoutResId: Int) : |
10 | 14 | UndimmedBottomSheet(layoutResId) { |
11 | 15 | private val commonPlayerViewModel: CommonPlayerViewModel by activityViewModels() |
12 | 16 |
|
| 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 | + |
13 | 43 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
14 | 44 | super.onViewCreated(view, savedInstanceState) |
15 | 45 |
|
|
0 commit comments