Fixes to bottom sheet in browse

same scroll behavior as the set categories sheet: it will not collapse the recycler when reaching the top of the list. Only when swiping down after being at the top of the list will it be able to scroll away

Also fixing appbar elevation when returning to browse controller
This commit is contained in:
Jays2Kings 2021-04-05 23:10:42 -04:00
parent f724f66e66
commit 5868ca3197
4 changed files with 56 additions and 2 deletions

View File

@ -86,7 +86,7 @@ class SetCategoriesSheet(
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
sheetBehavior.isDraggable = !recyclerView.canScrollVertically(-1)
sheetBehavior.isDraggable = true
}
}

View File

@ -69,6 +69,8 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
val migrationFrameLayout: RecyclerWithScrollerView?
get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView
var isExpanding = false
override fun onFinishInflate() {
super.onFinishInflate()
binding = ExtensionsBottomSheetBinding.bind(this)
@ -95,6 +97,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
}
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
isExpanding = !sheetBehavior.isExpanded()
if (canExpand) {
this@ExtensionBottomSheet.sheetBehavior?.expand()
}
@ -107,6 +110,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
0 -> extensionFrameLayout
else -> migrationFrameLayout
}?.binding?.recycler?.requestLayout()
sheetBehavior?.isDraggable = true
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
@ -120,11 +124,13 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
}
override fun onTabReselected(tab: TabLayout.Tab?) {
isExpanding = !sheetBehavior.isExpanded()
this@ExtensionBottomSheet.sheetBehavior?.expand()
when (tab?.position) {
0 -> extensionFrameLayout
else -> migrationFrameLayout
}?.binding?.recycler?.isNestedScrollingEnabled = true
sheetBehavior?.isDraggable = true
}
})
presenter.onCreate()
@ -141,6 +147,10 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
presenter.getExtensionUpdateCount()
}
fun isOnView(view: View): Boolean {
return "TabbedRecycler${binding.pager.currentItem}" == view.tag
}
fun updatedNestedRecyclers() {
listOf(extensionFrameLayout, migrationFrameLayout).forEachIndexed { index, recyclerWithScrollerBinding ->
recyclerWithScrollerBinding?.binding?.recycler?.isNestedScrollingEnabled = binding.pager.currentItem == index

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.extension
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
@ -17,6 +18,22 @@ class RecyclerWithScrollerView @JvmOverloads constructor(context: Context, attrs
binding.recycler.setHasFixedSize(true)
binding.recycler.addItemDecoration(ExtensionDividerItemDecoration(context))
binding.recycler.updatePaddingRelative(bottom = height)
binding.recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (sheet.isOnView(this@RecyclerWithScrollerView) && newState == RecyclerView.SCROLL_STATE_IDLE) {
sheet.sheetBehavior?.isDraggable = true
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (sheet.isOnView(this@RecyclerWithScrollerView) && recyclerView.canScrollVertically(-1)) {
sheet.sheetBehavior?.isDraggable = false
}
}
})
this.binding = binding
}

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.source
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.animation.ValueAnimator
import android.app.Activity
import android.content.res.ColorStateList
import android.os.Parcelable
@ -129,6 +130,7 @@ class BrowseController :
val array = view.context.obtainStyledAttributes(attrsArray)
val appBarHeight = array.getDimensionPixelSize(0, 0)
array.recycle()
var elevationAnim: ValueAnimator? = null
scrollViewWith(
binding.sourceRecycler,
customPadding = true,
@ -139,6 +141,19 @@ class BrowseController :
bottom = (activityBinding?.bottomNav?.height ?: 0) + 58.spToPx
)
},
liftOnScroll = { el ->
if (!binding.bottomSheet.root.sheetBehavior.isExpanded()) {
elevationAnim?.cancel()
elevationAnim = ValueAnimator.ofFloat(
activityBinding?.appBar?.elevation ?: 0f,
if (el) 15f else 0f
)
elevationAnim?.addUpdateListener { valueAnimator ->
activityBinding?.appBar?.elevation = valueAnimator.animatedValue as Float
}
elevationAnim?.start()
}
},
onBottomNavUpdate = {
setBottomPadding()
}
@ -180,6 +195,9 @@ class BrowseController :
override fun onStateChanged(p0: View, state: Int) {
if (state == BottomSheetBehavior.STATE_SETTLING) {
binding.bottomSheet.root.updatedNestedRecyclers()
} else if (state == BottomSheetBehavior.STATE_EXPANDED && binding.bottomSheet.root.isExpanding) {
binding.bottomSheet.root.updatedNestedRecyclers()
binding.bottomSheet.root.isExpanding = false
}
val extBottomSheet = binding.bottomSheet.root
if (state == BottomSheetBehavior.STATE_EXPANDED) {
@ -188,6 +206,7 @@ class BrowseController :
if (state == BottomSheetBehavior.STATE_EXPANDED ||
state == BottomSheetBehavior.STATE_COLLAPSED
) {
binding.bottomSheet.root.sheetBehavior?.isDraggable = true
showingExtensions = state == BottomSheetBehavior.STATE_EXPANDED
setTitle()
if (state == BottomSheetBehavior.STATE_EXPANDED) {
@ -224,9 +243,11 @@ class BrowseController :
fun setBottomSheetTabs(progress: Float) {
val bottomSheet = binding.bottomSheet.root
val halfStepProgress = (max(0.5f, progress) - 0.5f) * 2
binding.bottomSheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = ((activityBinding?.appBar?.height?.minus(9f.dpToPx) ?: 0f) * progress).toInt()
topMargin = ((activityBinding?.appBar?.height?.minus(9f.dpToPx) ?: 0f) * halfStepProgress).toInt()
}
binding.bottomSheet.pill.alpha = (1 - progress) * 0.25f
val selectedColor = ColorUtils.setAlphaComponent(
ContextCompat.getColor(binding.bottomSheet.tabs.context, R.color.colorAccent),
(progress * 255).toInt()
@ -333,6 +354,12 @@ class BrowseController :
}
} else {
binding.bottomSheet.root.presenter.refreshMigrations()
activityBinding?.appBar?.elevation =
when {
binding.bottomSheet.root.sheetBehavior.isExpanded() -> 0f
binding.sourceRecycler.canScrollVertically(-1) -> 15f
else -> 0f
}
}
setBottomPadding()
}