Fix fast scroll issues
This commit is contained in:
@@ -9,6 +9,7 @@ import android.util.AttributeSet
|
|||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.annotation.*
|
import androidx.annotation.*
|
||||||
@@ -24,6 +25,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.parents
|
||||||
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
@@ -115,6 +117,9 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
return viewHeight * proportion
|
return viewHeight * proportion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isScrollbarVisible: Boolean
|
||||||
|
get() = binding.scrollbar.isVisible
|
||||||
|
|
||||||
init {
|
init {
|
||||||
clipChildren = false
|
clipChildren = false
|
||||||
orientation = HORIZONTAL
|
orientation = HORIZONTAL
|
||||||
@@ -165,7 +170,9 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
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)
|
requestDisallowInterceptTouchEvent(true)
|
||||||
setHandleSelected(true)
|
setHandleSelected(true)
|
||||||
@@ -296,10 +303,12 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (parent is ViewGroup) {
|
if (parent is ViewGroup) {
|
||||||
setLayoutParams(parent as ViewGroup)
|
setLayoutParams(parent as ViewGroup)
|
||||||
} else if (recyclerView.parent is ViewGroup) {
|
} else {
|
||||||
val viewGroup = recyclerView.parent as ViewGroup
|
val viewGroup = findValidParent(recyclerView)
|
||||||
viewGroup.addView(this)
|
if (viewGroup != null) {
|
||||||
setLayoutParams(viewGroup)
|
viewGroup.addView(this)
|
||||||
|
setLayoutParams(viewGroup)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView.addOnScrollListener(scrollListener)
|
recyclerView.addOnScrollListener(scrollListener)
|
||||||
@@ -513,6 +522,14 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
return BubbleSize.values().getOrNull(ordinal) ?: defaultValue
|
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
|
private val BubbleSize.textSize
|
||||||
@Px get() = resources.getDimension(textSizeId)
|
@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>) {
|
fun <T> Flow<T>.observe(owner: LifecycleOwner, collector: FlowCollector<T>) {
|
||||||
val start = if (this is StateFlow) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
|
val start = if (this is StateFlow) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
|
||||||
owner.lifecycleScope.launch(start = start) {
|
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.ShareHelper
|
||||||
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
||||||
import org.koitharu.kotatsu.core.util.ext.clearItemDecorations
|
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.measureHeight
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
@@ -114,8 +113,6 @@ abstract class MangaListFragment :
|
|||||||
fastScroller.setFastScrollListener(this@MangaListFragment)
|
fastScroller.setFastScrollListener(this@MangaListFragment)
|
||||||
}
|
}
|
||||||
with(binding.swipeRefreshLayout) {
|
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)
|
setOnRefreshListener(this@MangaListFragment)
|
||||||
isEnabled = isSwipeRefreshEnabled
|
isEnabled = isSwipeRefreshEnabled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/swipeRefreshLayout"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipeRefreshLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -24,6 +24,6 @@
|
|||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
tools:listitem="@layout/item_feed" />
|
tools:listitem="@layout/item_feed" />
|
||||||
|
|
||||||
</FrameLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/swipeRefreshLayout"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipeRefreshLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -22,6 +22,5 @@
|
|||||||
tools:layoutManager="org.koitharu.kotatsu.core.ui.list.FitHeightLinearLayoutManager"
|
tools:layoutManager="org.koitharu.kotatsu.core.ui.list.FitHeightLinearLayoutManager"
|
||||||
tools:listitem="@layout/item_manga_list" />
|
tools:listitem="@layout/item_manga_list" />
|
||||||
|
|
||||||
</FrameLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
</FrameLayout>
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
<dimen name="fastscroll_scrollbar_margin_top">8dp</dimen>
|
<dimen name="fastscroll_scrollbar_margin_top">8dp</dimen>
|
||||||
<dimen name="fastscroll_scrollbar_margin_bottom">8dp</dimen>
|
<dimen name="fastscroll_scrollbar_margin_bottom">8dp</dimen>
|
||||||
<dimen name="fastscroll_scrollbar_padding_start">6dp</dimen>
|
<dimen name="fastscroll_scrollbar_padding_start">12dp</dimen>
|
||||||
<dimen name="fastscroll_scrollbar_padding_end">6dp</dimen>
|
<dimen name="fastscroll_scrollbar_padding_end">6dp</dimen>
|
||||||
|
|
||||||
<dimen name="m3_side_sheet_width">400dp</dimen>
|
<dimen name="m3_side_sheet_width">400dp</dimen>
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
<item name="bubbleTextColor">?colorOnTertiary</item>
|
<item name="bubbleTextColor">?colorOnTertiary</item>
|
||||||
<item name="trackColor">?colorOutline</item>
|
<item name="trackColor">?colorOutline</item>
|
||||||
<item name="bubbleSize">normal</item>
|
<item name="bubbleSize">normal</item>
|
||||||
<item name="scrollerOffset">6dp</item>
|
<item name="scrollerOffset">@dimen/grid_spacing_outer</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Widget.Kotatsu.ListItemTextView" parent="">
|
<style name="Widget.Kotatsu.ListItemTextView" parent="">
|
||||||
|
|||||||
Reference in New Issue
Block a user