From 05cff20b71b5fa367b0dc481285ce488115effd5 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 10 Jul 2021 13:13:14 -0400 Subject: [PATCH] Option to hide bottom sheets in controller by swiping down the side nav --- .../tachiyomi/ui/library/LibraryController.kt | 13 +++++++++++-- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 12 +++++++++++- .../tachiyomi/ui/recents/RecentsController.kt | 11 +++++++++++ .../kanade/tachiyomi/ui/source/BrowseController.kt | 5 +++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index bc15efb5db..c6aecc1053 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index f5d82f27b2..101e7826b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -915,7 +915,7 @@ open class MainActivity : BaseActivity(), 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(), 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 1077520b18..90ce20e9d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt index 8904c7143e..bb74451d56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt @@ -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()