mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-11 14:53:18 +02:00
recyclerView helper method in E2Ebottom sheet prevent accidental drag downs
This commit is contained in:
parent
8523dba27b
commit
d0af0ddffe
@ -47,6 +47,7 @@ class SetCategoriesSheet(
|
||||
private val itemAdapter = ItemAdapter<AddCategoryItem>()
|
||||
private val selectExtension: SelectExtension<AddCategoryItem>
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
override var recyclerView: RecyclerView? = binding.categoryRecyclerView
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) =
|
||||
SetCategoriesSheetBinding.inflate(inflater)
|
||||
@ -80,22 +81,6 @@ class SetCategoriesSheet(
|
||||
}
|
||||
)
|
||||
|
||||
binding.categoryRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
sheetBehavior.isDraggable = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (recyclerView.canScrollVertically(-1)) {
|
||||
sheetBehavior.isDraggable = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
binding.categoryRecyclerView.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
val fullHeight = activity.window.decorView.height
|
||||
|
@ -7,6 +7,7 @@ import android.view.View
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.net.toUri
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
@ -39,6 +40,8 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
||||
override fun createBinding(inflater: LayoutInflater) =
|
||||
TrackingBottomSheetBinding.inflate(inflater)
|
||||
|
||||
override var recyclerView: RecyclerView? = binding.trackRecycler
|
||||
|
||||
init {
|
||||
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
|
||||
sheetBehavior.peekHeight = 500.dpToPx + height
|
||||
|
@ -30,6 +30,8 @@ class SourceFilterSheet(val activity: Activity) :
|
||||
|
||||
var onResetClicked = {}
|
||||
|
||||
override var recyclerView: RecyclerView? = binding.filtersRecycler
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = SourceFilterSheetBinding.inflate(inflater)
|
||||
init {
|
||||
binding.searchBtn.setOnClickListener { dismiss() }
|
||||
@ -82,22 +84,6 @@ class SourceFilterSheet(val activity: Activity) :
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
binding.filtersRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
sheetBehavior.isDraggable = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (recyclerView.canScrollVertically(-1)) {
|
||||
sheetBehavior.isDraggable = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -5,6 +5,7 @@ import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
@ -17,6 +18,7 @@ abstract class EdgeToEdgeBottomSheetDialog<VB : ViewBinding>(activity: Activity)
|
||||
protected val binding: VB
|
||||
|
||||
protected val sheetBehavior: BottomSheetBehavior<*>
|
||||
protected open var recyclerView: RecyclerView? = null
|
||||
|
||||
init {
|
||||
binding = createBinding(activity.layoutInflater)
|
||||
@ -52,5 +54,30 @@ abstract class EdgeToEdgeBottomSheetDialog<VB : ViewBinding>(activity: Activity)
|
||||
contentView.requestLayout()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
recyclerView?.let { recyclerView ->
|
||||
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE ||
|
||||
newState == RecyclerView.SCROLL_STATE_SETTLING
|
||||
) {
|
||||
sheetBehavior.isDraggable = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (recyclerView.canScrollVertically(-1) &&
|
||||
recyclerView.scrollState != RecyclerView.SCROLL_STATE_SETTLING
|
||||
) {
|
||||
sheetBehavior.isDraggable = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun createBinding(inflater: LayoutInflater): VB
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user