From 770595bbd522478564b7789057d10078aa0a12e0 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 30 Apr 2020 01:56:13 -0400 Subject: [PATCH] Tapping the toolbar now scrolls to the top of the controller Or collaspes a bottom sheet --- .../tachiyomi/ui/library/LibraryController.kt | 2 ++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 1 + .../tachiyomi/ui/recents/RecentsController.kt | 3 +++ .../tachiyomi/ui/source/SourceController.kt | 3 +++ .../util/view/ControllerExtensions.kt | 19 +++++++++++++++++-- app/src/main/res/layout/main_activity.xml | 2 -- 6 files changed, 26 insertions(+), 4 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 ffd9443b36..43b63a6970 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 @@ -863,6 +863,8 @@ class LibraryController( } } + override fun sheetIsExpanded(): Boolean = false + override fun handleSheetBack(): Boolean { val sheetBehavior = BottomSheetBehavior.from(filter_bottom_sheet) if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED && sheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN) { 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 76f21f6882..37adf78ba1 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 @@ -624,4 +624,5 @@ interface BottomSheetController { fun showSheet() 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 9f8838a209..e1686872a1 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 @@ -438,6 +438,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED } + override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior?.state == + BottomSheetBehavior.STATE_EXPANDED + override fun expandSearch() { if (showingDownloads) { dl_bottom_sheet.dismiss() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt index 7c07ee171e..89bc9be4d9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt @@ -183,6 +183,9 @@ class SourceController : NucleusController(), } } + override fun sheetIsExpanded(): Boolean = ext_bottom_sheet.sheetBehavior?.state == + BottomSheetBehavior.STATE_EXPANDED + override fun handleSheetBack(): Boolean { if (ext_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) { ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index f85aa9f2d0..2d40b0cf41 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -16,9 +16,11 @@ import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.FadeChangeHandler +import eu.kanade.tachiyomi.ui.main.BottomSheetController import eu.kanade.tachiyomi.util.system.dpToPx import kotlinx.android.synthetic.main.main_activity.* import kotlin.math.abs +import kotlin.random.Random fun Controller.setOnQueryTextChangeListener( searchView: SearchView, @@ -70,6 +72,8 @@ fun Controller.scrollViewWith( recycler.requestApplyInsets() } } + val randomTag = Random.nextLong() + recycler.doOnApplyWindowInsets { view, insets, _ -> val headerHeight = insets.systemWindowInsetTop + appBarHeight if (!customPadding) view.updatePaddingRelative( @@ -106,10 +110,21 @@ fun Controller.scrollViewWith( changeType: ControllerChangeType ) { super.onChangeStart(controller, changeHandler, changeType) - if (changeType.isEnter) + if (changeType.isEnter) { elevateFunc(elevate) - else + activity!!.toolbar.tag = randomTag + activity!!.toolbar.setOnClickListener { + if ((this@scrollViewWith as? BottomSheetController)?.sheetIsExpanded() != true) { + recycler.scrollToPosition(0) + } else { + (this@scrollViewWith as? BottomSheetController)?.toggleSheet() + } + } + } else { elevationAnim?.cancel() + if (activity!!.toolbar.tag == randomTag) + activity!!.toolbar.setOnClickListener(null) + } } }) elevateFunc(recycler.canScrollVertically(-1)) diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index c7b8866566..12aa5b56fc 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -42,8 +42,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:clickable="true" - android:focusable="true" android:orientation="horizontal">