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 {
val sheetBehavior = BottomSheetBehavior.from(filter_bottom_sheet)
if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED && sheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN) {

View File

@ -624,4 +624,5 @@ interface BottomSheetController {
fun showSheet()
fun toggleSheet()
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
}
override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior?.state ==
BottomSheetBehavior.STATE_EXPANDED
override fun expandSearch() {
if (showingDownloads) {
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 {
if (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.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))

View File

@ -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">
<com.google.android.material.textview.MaterialTextView