|
|
|
|
@ -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)
|
|
|
|
|
|
|
|
|
|
|