Tapping the toolbar now scrolls to the top of the controller

Or collaspes a bottom sheet
This commit is contained in:
Jay 2020-04-30 01:56:13 -04:00
parent cd74c4d1ec
commit 770595bbd5
6 changed files with 26 additions and 4 deletions

View File

@ -863,6 +863,8 @@ class LibraryController(
} }
} }
override fun sheetIsExpanded(): Boolean = false
override fun handleSheetBack(): Boolean { override fun handleSheetBack(): Boolean {
val sheetBehavior = BottomSheetBehavior.from(filter_bottom_sheet) val sheetBehavior = BottomSheetBehavior.from(filter_bottom_sheet)
if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED && sheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN) { if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED && sheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN) {

View File

@ -624,4 +624,5 @@ interface BottomSheetController {
fun showSheet() fun showSheet()
fun toggleSheet() fun toggleSheet()
fun handleSheetBack(): Boolean fun handleSheetBack(): Boolean
fun sheetIsExpanded(): Boolean
} }

View File

@ -438,6 +438,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
} }
override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior?.state ==
BottomSheetBehavior.STATE_EXPANDED
override fun expandSearch() { override fun expandSearch() {
if (showingDownloads) { if (showingDownloads) {
dl_bottom_sheet.dismiss() dl_bottom_sheet.dismiss()

View File

@ -183,6 +183,9 @@ class SourceController : NucleusController<SourcePresenter>(),
} }
} }
override fun sheetIsExpanded(): Boolean = ext_bottom_sheet.sheetBehavior?.state ==
BottomSheetBehavior.STATE_EXPANDED
override fun handleSheetBack(): Boolean { override fun handleSheetBack(): Boolean {
if (ext_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) { if (ext_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) {
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED

View File

@ -16,9 +16,11 @@ import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import eu.kanade.tachiyomi.ui.main.BottomSheetController
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import kotlin.math.abs import kotlin.math.abs
import kotlin.random.Random
fun Controller.setOnQueryTextChangeListener( fun Controller.setOnQueryTextChangeListener(
searchView: SearchView, searchView: SearchView,
@ -70,6 +72,8 @@ fun Controller.scrollViewWith(
recycler.requestApplyInsets() recycler.requestApplyInsets()
} }
} }
val randomTag = Random.nextLong()
recycler.doOnApplyWindowInsets { view, insets, _ -> recycler.doOnApplyWindowInsets { view, insets, _ ->
val headerHeight = insets.systemWindowInsetTop + appBarHeight val headerHeight = insets.systemWindowInsetTop + appBarHeight
if (!customPadding) view.updatePaddingRelative( if (!customPadding) view.updatePaddingRelative(
@ -106,10 +110,21 @@ fun Controller.scrollViewWith(
changeType: ControllerChangeType changeType: ControllerChangeType
) { ) {
super.onChangeStart(controller, changeHandler, changeType) super.onChangeStart(controller, changeHandler, changeType)
if (changeType.isEnter) if (changeType.isEnter) {
elevateFunc(elevate) 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() elevationAnim?.cancel()
if (activity!!.toolbar.tag == randomTag)
activity!!.toolbar.setOnClickListener(null)
}
} }
}) })
elevateFunc(recycler.canScrollVertically(-1)) elevateFunc(recycler.canScrollVertically(-1))

View File

@ -42,8 +42,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView