mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:29:16 +01:00
Fix scroller getting dragged incorrectly in RTL (fixes #5496)
This commit is contained in:
parent
8362bf0886
commit
7c72d6cb7c
@ -1,11 +1,14 @@
|
|||||||
package eu.kanade.tachiyomi.widget
|
package eu.kanade.tachiyomi.widget
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
import eu.davidea.fastscroller.FastScroller
|
import eu.davidea.fastscroller.FastScroller
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPxEnd
|
import eu.kanade.tachiyomi.util.system.dpToPxEnd
|
||||||
|
import eu.kanade.tachiyomi.util.system.isLTR
|
||||||
|
|
||||||
class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
FastScroller(context, attrs) {
|
FastScroller(context, attrs) {
|
||||||
@ -14,14 +17,59 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
|
|||||||
setViewsToUse(
|
setViewsToUse(
|
||||||
R.layout.material_fastscroll,
|
R.layout.material_fastscroll,
|
||||||
R.id.fast_scroller_bubble,
|
R.id.fast_scroller_bubble,
|
||||||
R.id.fast_scroller_handle
|
R.id.fast_scroller_handle,
|
||||||
)
|
)
|
||||||
autoHideEnabled = true
|
autoHideEnabled = true
|
||||||
ignoreTouchesOutsideHandle = true
|
ignoreTouchesOutsideHandle = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Overridden to handle RTL
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
if (isHidden) return false
|
if (recyclerView.computeVerticalScrollRange() <= recyclerView.computeVerticalScrollExtent()) {
|
||||||
|
return super.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
// start: handle RTL differently
|
||||||
|
if (
|
||||||
|
if (context.resources.isLTR) {
|
||||||
|
event.x < handle.x - ViewCompat.getPaddingStart(handle)
|
||||||
|
} else {
|
||||||
|
event.x > handle.width + ViewCompat.getPaddingStart(handle)
|
||||||
|
}
|
||||||
|
) return false
|
||||||
|
// end
|
||||||
|
|
||||||
|
if (ignoreTouchesOutsideHandle &&
|
||||||
|
(event.y < handle.y || event.y > handle.y + handle.height)
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
handle.isSelected = true
|
||||||
|
notifyScrollStateChange(true)
|
||||||
|
showBubble()
|
||||||
|
showScrollbar()
|
||||||
|
val y = event.y
|
||||||
|
setBubbleAndHandlePosition(y)
|
||||||
|
setRecyclerViewPosition(y)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
val y = event.y
|
||||||
|
setBubbleAndHandlePosition(y)
|
||||||
|
setRecyclerViewPosition(y)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
handle.isSelected = false
|
||||||
|
notifyScrollStateChange(false)
|
||||||
|
hideBubble()
|
||||||
|
if (autoHideEnabled) hideScrollbar()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.onTouchEvent(event)
|
return super.onTouchEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user