diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/fastscroll/FastScroller.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/fastscroll/FastScroller.kt index 63480c8d6..946992aea 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/fastscroll/FastScroller.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/fastscroll/FastScroller.kt @@ -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) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/FlowObserver.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/FlowObserver.kt index e13f221e1..d6c634468 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/FlowObserver.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/FlowObserver.kt @@ -14,9 +14,7 @@ import org.koitharu.kotatsu.core.util.Event fun Flow.observe(owner: LifecycleOwner, collector: FlowCollector) { 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) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt index aaf868a15..a49bb4dfa 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/MangaListFragment.kt @@ -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 } diff --git a/app/src/main/res/layout/fragment_feed.xml b/app/src/main/res/layout/fragment_feed.xml index d41b732b3..dba209dca 100644 --- a/app/src/main/res/layout/fragment_feed.xml +++ b/app/src/main/res/layout/fragment_feed.xml @@ -1,13 +1,13 @@ - - @@ -24,6 +24,6 @@ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:listitem="@layout/item_feed" /> - + - + diff --git a/app/src/main/res/layout/fragment_list.xml b/app/src/main/res/layout/fragment_list.xml index 84c59071a..06a5d7497 100644 --- a/app/src/main/res/layout/fragment_list.xml +++ b/app/src/main/res/layout/fragment_list.xml @@ -1,13 +1,13 @@ - - @@ -22,6 +22,5 @@ tools:layoutManager="org.koitharu.kotatsu.core.ui.list.FitHeightLinearLayoutManager" tools:listitem="@layout/item_manga_list" /> - - - + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 717a03880..4925f903f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -68,7 +68,7 @@ 8dp 8dp - 6dp + 12dp 6dp 400dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d73894979..fce1c7d72 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -134,7 +134,7 @@ ?colorOnTertiary ?colorOutline normal - 6dp + @dimen/grid_spacing_outer