mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
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:
parent
f724f66e66
commit
5868ca3197
@ -86,7 +86,7 @@ class SetCategoriesSheet(
|
|||||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||||
super.onScrollStateChanged(recyclerView, newState)
|
super.onScrollStateChanged(recyclerView, newState)
|
||||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
sheetBehavior.isDraggable = !recyclerView.canScrollVertically(-1)
|
sheetBehavior.isDraggable = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,8 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
val migrationFrameLayout: RecyclerWithScrollerView?
|
val migrationFrameLayout: RecyclerWithScrollerView?
|
||||||
get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView
|
get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView
|
||||||
|
|
||||||
|
var isExpanding = false
|
||||||
|
|
||||||
override fun onFinishInflate() {
|
override fun onFinishInflate() {
|
||||||
super.onFinishInflate()
|
super.onFinishInflate()
|
||||||
binding = ExtensionsBottomSheetBinding.bind(this)
|
binding = ExtensionsBottomSheetBinding.bind(this)
|
||||||
@ -95,6 +97,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
}
|
}
|
||||||
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||||
|
isExpanding = !sheetBehavior.isExpanded()
|
||||||
if (canExpand) {
|
if (canExpand) {
|
||||||
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
||||||
}
|
}
|
||||||
@ -107,6 +110,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
0 -> extensionFrameLayout
|
0 -> extensionFrameLayout
|
||||||
else -> migrationFrameLayout
|
else -> migrationFrameLayout
|
||||||
}?.binding?.recycler?.requestLayout()
|
}?.binding?.recycler?.requestLayout()
|
||||||
|
sheetBehavior?.isDraggable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
||||||
@ -120,11 +124,13 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||||
|
isExpanding = !sheetBehavior.isExpanded()
|
||||||
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
||||||
when (tab?.position) {
|
when (tab?.position) {
|
||||||
0 -> extensionFrameLayout
|
0 -> extensionFrameLayout
|
||||||
else -> migrationFrameLayout
|
else -> migrationFrameLayout
|
||||||
}?.binding?.recycler?.isNestedScrollingEnabled = true
|
}?.binding?.recycler?.isNestedScrollingEnabled = true
|
||||||
|
sheetBehavior?.isDraggable = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
presenter.onCreate()
|
presenter.onCreate()
|
||||||
@ -141,6 +147,10 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
|||||||
presenter.getExtensionUpdateCount()
|
presenter.getExtensionUpdateCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isOnView(view: View): Boolean {
|
||||||
|
return "TabbedRecycler${binding.pager.currentItem}" == view.tag
|
||||||
|
}
|
||||||
|
|
||||||
fun updatedNestedRecyclers() {
|
fun updatedNestedRecyclers() {
|
||||||
listOf(extensionFrameLayout, migrationFrameLayout).forEachIndexed { index, recyclerWithScrollerBinding ->
|
listOf(extensionFrameLayout, migrationFrameLayout).forEachIndexed { index, recyclerWithScrollerBinding ->
|
||||||
recyclerWithScrollerBinding?.binding?.recycler?.isNestedScrollingEnabled = binding.pager.currentItem == index
|
recyclerWithScrollerBinding?.binding?.recycler?.isNestedScrollingEnabled = binding.pager.currentItem == index
|
||||||
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.extension
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
|
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
|
||||||
@ -17,6 +18,22 @@ class RecyclerWithScrollerView @JvmOverloads constructor(context: Context, attrs
|
|||||||
binding.recycler.setHasFixedSize(true)
|
binding.recycler.setHasFixedSize(true)
|
||||||
binding.recycler.addItemDecoration(ExtensionDividerItemDecoration(context))
|
binding.recycler.addItemDecoration(ExtensionDividerItemDecoration(context))
|
||||||
binding.recycler.updatePaddingRelative(bottom = height)
|
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
|
this.binding = binding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.ui.source
|
package eu.kanade.tachiyomi.ui.source
|
||||||
|
|
||||||
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
@ -129,6 +130,7 @@ class BrowseController :
|
|||||||
val array = view.context.obtainStyledAttributes(attrsArray)
|
val array = view.context.obtainStyledAttributes(attrsArray)
|
||||||
val appBarHeight = array.getDimensionPixelSize(0, 0)
|
val appBarHeight = array.getDimensionPixelSize(0, 0)
|
||||||
array.recycle()
|
array.recycle()
|
||||||
|
var elevationAnim: ValueAnimator? = null
|
||||||
scrollViewWith(
|
scrollViewWith(
|
||||||
binding.sourceRecycler,
|
binding.sourceRecycler,
|
||||||
customPadding = true,
|
customPadding = true,
|
||||||
@ -139,6 +141,19 @@ class BrowseController :
|
|||||||
bottom = (activityBinding?.bottomNav?.height ?: 0) + 58.spToPx
|
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 = {
|
onBottomNavUpdate = {
|
||||||
setBottomPadding()
|
setBottomPadding()
|
||||||
}
|
}
|
||||||
@ -180,6 +195,9 @@ class BrowseController :
|
|||||||
override fun onStateChanged(p0: View, state: Int) {
|
override fun onStateChanged(p0: View, state: Int) {
|
||||||
if (state == BottomSheetBehavior.STATE_SETTLING) {
|
if (state == BottomSheetBehavior.STATE_SETTLING) {
|
||||||
binding.bottomSheet.root.updatedNestedRecyclers()
|
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
|
val extBottomSheet = binding.bottomSheet.root
|
||||||
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
@ -188,6 +206,7 @@ class BrowseController :
|
|||||||
if (state == BottomSheetBehavior.STATE_EXPANDED ||
|
if (state == BottomSheetBehavior.STATE_EXPANDED ||
|
||||||
state == BottomSheetBehavior.STATE_COLLAPSED
|
state == BottomSheetBehavior.STATE_COLLAPSED
|
||||||
) {
|
) {
|
||||||
|
binding.bottomSheet.root.sheetBehavior?.isDraggable = true
|
||||||
showingExtensions = state == BottomSheetBehavior.STATE_EXPANDED
|
showingExtensions = state == BottomSheetBehavior.STATE_EXPANDED
|
||||||
setTitle()
|
setTitle()
|
||||||
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
@ -224,9 +243,11 @@ class BrowseController :
|
|||||||
|
|
||||||
fun setBottomSheetTabs(progress: Float) {
|
fun setBottomSheetTabs(progress: Float) {
|
||||||
val bottomSheet = binding.bottomSheet.root
|
val bottomSheet = binding.bottomSheet.root
|
||||||
|
val halfStepProgress = (max(0.5f, progress) - 0.5f) * 2
|
||||||
binding.bottomSheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
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(
|
val selectedColor = ColorUtils.setAlphaComponent(
|
||||||
ContextCompat.getColor(binding.bottomSheet.tabs.context, R.color.colorAccent),
|
ContextCompat.getColor(binding.bottomSheet.tabs.context, R.color.colorAccent),
|
||||||
(progress * 255).toInt()
|
(progress * 255).toInt()
|
||||||
@ -333,6 +354,12 @@ class BrowseController :
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.bottomSheet.root.presenter.refreshMigrations()
|
binding.bottomSheet.root.presenter.refreshMigrations()
|
||||||
|
activityBinding?.appBar?.elevation =
|
||||||
|
when {
|
||||||
|
binding.bottomSheet.root.sheetBehavior.isExpanded() -> 0f
|
||||||
|
binding.sourceRecycler.canScrollVertically(-1) -> 15f
|
||||||
|
else -> 0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setBottomPadding()
|
setBottomPadding()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user