Option to hide bottom sheets in controller by swiping down the side nav

This commit is contained in:
Jays2Kings 2021-07-10 13:13:14 -04:00
parent f2851f2549
commit 05cff20b71
4 changed files with 38 additions and 3 deletions

View File

@ -1529,13 +1529,22 @@ class LibraryController(
//region sheet methods
override fun showSheet() {
closeTip()
val sheetBehavior = binding.filterBottomSheet.filterBottomSheet.sheetBehavior
when {
binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.collapse()
!binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isExpanded() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.expand()
sheetBehavior.isHidden() -> sheetBehavior?.collapse()
!sheetBehavior.isExpanded() -> sheetBehavior?.expand()
else -> showDisplayOptions()
}
}
override fun hideSheet() {
val sheetBehavior = binding.filterBottomSheet.filterBottomSheet.sheetBehavior
when {
sheetBehavior.isExpanded() -> sheetBehavior?.collapse()
!sheetBehavior.isHidden() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
}
}
override fun toggleSheet() {
closeTip()
when {

View File

@ -915,7 +915,7 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
val diffX = e2.x - e1.x
if (abs(diffX) <= abs(diffY)) {
val sheetRect = Rect()
binding.bottomNav?.getGlobalVisibleRect(sheetRect)
nav.getGlobalVisibleRect(sheetRect)
if (sheetRect.contains(e1.x.toInt(), e1.y.toInt()) &&
abs(diffY) > Companion.SWIPE_THRESHOLD &&
abs(velocityY) > Companion.SWIPE_VELOCITY_THRESHOLD &&
@ -924,6 +924,15 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
val bottomSheetController =
router.backstack.lastOrNull()?.controller as? BottomSheetController
bottomSheetController?.showSheet()
} else if (nav == binding.sideNav &&
sheetRect.contains(e1.x.toInt(), e1.y.toInt()) &&
abs(diffY) > Companion.SWIPE_THRESHOLD &&
abs(velocityY) > Companion.SWIPE_VELOCITY_THRESHOLD &&
diffY > 0
) {
val bottomSheetController =
router.backstack.lastOrNull()?.controller as? BottomSheetController
bottomSheetController?.hideSheet()
}
result = true
}
@ -981,6 +990,7 @@ interface FloatingSearchInterface {
interface BottomSheetController {
fun showSheet()
fun hideSheet()
fun toggleSheet()
fun handleSheetBack(): Boolean
fun sheetIsExpanded(): Boolean

View File

@ -48,7 +48,9 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.spToPx
import eu.kanade.tachiyomi.util.system.toInt
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.hide
import eu.kanade.tachiyomi.util.view.isCollapsed
import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.requestFilePermissionsSafe
@ -742,6 +744,15 @@ class RecentsController(bundle: Bundle? = null) :
}
}
override fun hideSheet() {
if (!isBindingInitialized) return
if (binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true) {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.hide()
} else {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.collapse()
}
}
override fun toggleSheet() {
if (showingDownloads) binding.downloadBottomSheet.dlBottomSheet.dismiss()
else binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.expand()

View File

@ -302,6 +302,11 @@ class BrowseController :
binding.bottomSheet.root.sheetBehavior?.expand()
}
override fun hideSheet() {
if (!isBindingInitialized) return
binding.bottomSheet.root.sheetBehavior?.collapse()
}
override fun toggleSheet() {
if (!binding.bottomSheet.root.sheetBehavior.isCollapsed()) {
binding.bottomSheet.root.sheetBehavior?.collapse()