Fix fast scroll issues
This commit is contained in:
@@ -9,6 +9,7 @@ import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.*
|
||||
import androidx.annotation.*
|
||||
@@ -24,6 +25,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
||||
import org.koitharu.kotatsu.core.util.ext.parents
|
||||
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
||||
import kotlin.math.roundToInt
|
||||
import com.google.android.material.R as materialR
|
||||
@@ -115,6 +117,9 @@ class FastScroller @JvmOverloads constructor(
|
||||
return viewHeight * proportion
|
||||
}
|
||||
|
||||
val isScrollbarVisible: Boolean
|
||||
get() = binding.scrollbar.isVisible
|
||||
|
||||
init {
|
||||
clipChildren = false
|
||||
orientation = HORIZONTAL
|
||||
@@ -165,7 +170,9 @@ class FastScroller @JvmOverloads constructor(
|
||||
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
if (event.x.toInt() !in binding.scrollbar.left..binding.scrollbar.right) return false
|
||||
if (!isScrollbarVisible || event.x.toInt() !in binding.scrollbar.left..binding.scrollbar.right) {
|
||||
return false
|
||||
}
|
||||
|
||||
requestDisallowInterceptTouchEvent(true)
|
||||
setHandleSelected(true)
|
||||
@@ -296,10 +303,12 @@ class FastScroller @JvmOverloads constructor(
|
||||
|
||||
if (parent is ViewGroup) {
|
||||
setLayoutParams(parent as ViewGroup)
|
||||
} else if (recyclerView.parent is ViewGroup) {
|
||||
val viewGroup = recyclerView.parent as ViewGroup
|
||||
viewGroup.addView(this)
|
||||
setLayoutParams(viewGroup)
|
||||
} else {
|
||||
val viewGroup = findValidParent(recyclerView)
|
||||
if (viewGroup != null) {
|
||||
viewGroup.addView(this)
|
||||
setLayoutParams(viewGroup)
|
||||
}
|
||||
}
|
||||
|
||||
recyclerView.addOnScrollListener(scrollListener)
|
||||
@@ -513,6 +522,14 @@ class FastScroller @JvmOverloads constructor(
|
||||
return BubbleSize.values().getOrNull(ordinal) ?: defaultValue
|
||||
}
|
||||
|
||||
private fun findValidParent(view: View): ViewGroup? = view.parents.firstNotNullOfOrNull { p ->
|
||||
if (p is FrameLayout || p is ConstraintLayout || p is CoordinatorLayout || p is RelativeLayout) {
|
||||
p as ViewGroup
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private val BubbleSize.textSize
|
||||
@Px get() = resources.getDimension(textSizeId)
|
||||
|
||||
|
||||
@@ -14,9 +14,7 @@ import org.koitharu.kotatsu.core.util.Event
|
||||
fun <T> Flow<T>.observe(owner: LifecycleOwner, collector: FlowCollector<T>) {
|
||||
val start = if (this is StateFlow) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
|
||||
owner.lifecycleScope.launch(start = start) {
|
||||
owner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
collect(collector)
|
||||
}
|
||||
collect(collector)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
||||
import org.koitharu.kotatsu.core.util.ext.clearItemDecorations
|
||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||
import org.koitharu.kotatsu.core.util.ext.measureHeight
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||
@@ -114,8 +113,6 @@ abstract class MangaListFragment :
|
||||
fastScroller.setFastScrollListener(this@MangaListFragment)
|
||||
}
|
||||
with(binding.swipeRefreshLayout) {
|
||||
setProgressBackgroundColorSchemeColor(context.getThemeColor(com.google.android.material.R.attr.colorPrimary))
|
||||
setColorSchemeColors(context.getThemeColor(com.google.android.material.R.attr.colorOnPrimary))
|
||||
setOnRefreshListener(this@MangaListFragment)
|
||||
isEnabled = isSwipeRefreshEnabled
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user