recyclerView helper method in E2Ebottom sheet prevent accidental drag downs

This commit is contained in:
Jays2Kings 2021-04-26 03:28:36 -04:00
parent 8523dba27b
commit d0af0ddffe
4 changed files with 33 additions and 32 deletions

View File

@ -47,6 +47,7 @@ class SetCategoriesSheet(
private val itemAdapter = ItemAdapter<AddCategoryItem>() private val itemAdapter = ItemAdapter<AddCategoryItem>()
private val selectExtension: SelectExtension<AddCategoryItem> private val selectExtension: SelectExtension<AddCategoryItem>
private val db: DatabaseHelper by injectLazy() private val db: DatabaseHelper by injectLazy()
override var recyclerView: RecyclerView? = binding.categoryRecyclerView
override fun createBinding(inflater: LayoutInflater) = override fun createBinding(inflater: LayoutInflater) =
SetCategoriesSheetBinding.inflate(inflater) 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.titleLayout.viewTreeObserver.addOnGlobalLayoutListener {
binding.categoryRecyclerView.updateLayoutParams<ConstraintLayout.LayoutParams> { binding.categoryRecyclerView.updateLayoutParams<ConstraintLayout.LayoutParams> {
val fullHeight = activity.window.decorView.height val fullHeight = activity.window.decorView.height

View File

@ -7,6 +7,7 @@ import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
@ -39,6 +40,8 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
override fun createBinding(inflater: LayoutInflater) = override fun createBinding(inflater: LayoutInflater) =
TrackingBottomSheetBinding.inflate(inflater) TrackingBottomSheetBinding.inflate(inflater)
override var recyclerView: RecyclerView? = binding.trackRecycler
init { init {
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 500.dpToPx + height sheetBehavior.peekHeight = 500.dpToPx + height

View File

@ -30,6 +30,8 @@ class SourceFilterSheet(val activity: Activity) :
var onResetClicked = {} var onResetClicked = {}
override var recyclerView: RecyclerView? = binding.filtersRecycler
override fun createBinding(inflater: LayoutInflater) = SourceFilterSheetBinding.inflate(inflater) override fun createBinding(inflater: LayoutInflater) = SourceFilterSheetBinding.inflate(inflater)
init { init {
binding.searchBtn.setOnClickListener { dismiss() } 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() { override fun onStart() {

View File

@ -5,6 +5,7 @@ import android.os.Build
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
@ -17,6 +18,7 @@ abstract class EdgeToEdgeBottomSheetDialog<VB : ViewBinding>(activity: Activity)
protected val binding: VB protected val binding: VB
protected val sheetBehavior: BottomSheetBehavior<*> protected val sheetBehavior: BottomSheetBehavior<*>
protected open var recyclerView: RecyclerView? = null
init { init {
binding = createBinding(activity.layoutInflater) binding = createBinding(activity.layoutInflater)
@ -52,5 +54,30 @@ abstract class EdgeToEdgeBottomSheetDialog<VB : ViewBinding>(activity: Activity)
contentView.requestLayout() 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 abstract fun createBinding(inflater: LayoutInflater): VB
} }