Fix pages list scrolling
This commit is contained in:
@@ -36,7 +36,7 @@ class KotatsuApp : BaseApp() {
|
||||
FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder()
|
||||
.penaltyDeath()
|
||||
.detectFragmentReuse()
|
||||
// .detectWrongFragmentContainer() FIXME: migrate to ViewPager2
|
||||
.detectWrongFragmentContainer()
|
||||
.detectRetainInstanceUsage()
|
||||
.detectSetUserVisibleHint()
|
||||
.detectFragmentTagUsage()
|
||||
|
||||
@@ -17,7 +17,16 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||
|
||||
val fastScroller = FastScroller(context, attrs)
|
||||
private var applyViewPager2Fix = false
|
||||
var isVP2BugWorkaroundEnabled = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (value && isAttachedToWindow) {
|
||||
checkIfInVP2()
|
||||
} else if (!value) {
|
||||
applyVP2Workaround = false
|
||||
}
|
||||
}
|
||||
private var applyVP2Workaround = false
|
||||
|
||||
var isFastScrollerEnabled: Boolean = true
|
||||
set(value) {
|
||||
@@ -46,23 +55,29 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
fastScroller.attachRecyclerView(this)
|
||||
applyViewPager2Fix = ancestors.any { it is ViewPager2 } == true
|
||||
if (isVP2BugWorkaroundEnabled) {
|
||||
checkIfInVP2()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
fastScroller.detachRecyclerView()
|
||||
super.onDetachedFromWindow()
|
||||
applyViewPager2Fix = false
|
||||
applyVP2Workaround = false
|
||||
}
|
||||
|
||||
override fun isLayoutRequested(): Boolean {
|
||||
return if (applyViewPager2Fix) false else super.isLayoutRequested()
|
||||
return if (applyVP2Workaround) false else super.isLayoutRequested()
|
||||
}
|
||||
|
||||
override fun requestLayout() {
|
||||
super.requestLayout()
|
||||
if (applyViewPager2Fix && parent?.isLayoutRequested == true) {
|
||||
if (applyVP2Workaround && parent?.isLayoutRequested == true) {
|
||||
parent?.requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkIfInVP2() {
|
||||
applyVP2Workaround = ancestors.any { it is ViewPager2 } == true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,8 +363,8 @@ class DetailsActivity :
|
||||
}
|
||||
|
||||
private fun initPager() {
|
||||
viewBinding.pager.recyclerView?.isNestedScrollingEnabled = false
|
||||
val adapter = DetailsPagerAdapter(this)
|
||||
viewBinding.pager.recyclerView?.isNestedScrollingEnabled = false
|
||||
viewBinding.pager.offscreenPageLimit = 1
|
||||
viewBinding.pager.adapter = adapter
|
||||
TabLayoutMediator(viewBinding.tabs, viewBinding.pager, adapter).attach()
|
||||
|
||||
@@ -59,6 +59,7 @@ class ChaptersFragment :
|
||||
with(binding.recyclerViewChapters) {
|
||||
checkNotNull(selectionController).attachToRecyclerView(this)
|
||||
setHasFixedSize(true)
|
||||
isNestedScrollingEnabled = false
|
||||
adapter = chaptersAdapter
|
||||
}
|
||||
viewModel.isLoading.observe(viewLifecycleOwner, this::onLoadingStateChanged)
|
||||
@@ -83,6 +84,17 @@ class ChaptersFragment :
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
// required for BottomSheetBehavior
|
||||
requireViewBinding().recyclerViewChapters.isNestedScrollingEnabled = false
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
requireViewBinding().recyclerViewChapters.isNestedScrollingEnabled = true
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onItemClick(item: ChapterListItem, view: View) {
|
||||
if (selectionController?.onItemClick(item.chapter.id) == true) {
|
||||
return
|
||||
|
||||
@@ -88,6 +88,7 @@ class PagesFragment :
|
||||
addItemDecoration(TypedListSpacingDecoration(context, false))
|
||||
adapter = thumbnailsAdapter
|
||||
setHasFixedSize(true)
|
||||
isNestedScrollingEnabled = false
|
||||
addOnLayoutChangeListener(spanResolver)
|
||||
spanResolver?.setGridSize(settings.gridSize / 100f, this)
|
||||
addOnScrollListener(ScrollListener().also { scrollListener = it })
|
||||
@@ -112,6 +113,17 @@ class PagesFragment :
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
// required for BottomSheetBehavior
|
||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = false
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
requireViewBinding().recyclerView.isNestedScrollingEnabled = true
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
||||
|
||||
override fun onItemClick(item: PageThumbnail, view: View) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.favourites.ui.list
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@@ -12,6 +13,7 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||
import org.koitharu.kotatsu.core.util.ext.sortedByOrdinal
|
||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
||||
import org.koitharu.kotatsu.list.domain.ListSortOrder
|
||||
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
@@ -26,6 +28,11 @@ class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickLis
|
||||
val categoryId
|
||||
get() = viewModel.categoryId
|
||||
|
||||
override fun onViewBindingCreated(binding: FragmentListBinding, savedInstanceState: Bundle?) {
|
||||
super.onViewBindingCreated(binding, savedInstanceState)
|
||||
binding.recyclerView.isVP2BugWorkaroundEnabled = true
|
||||
}
|
||||
|
||||
override fun onScrolledToEnd() = Unit
|
||||
|
||||
override fun onFilterClick(view: View?) {
|
||||
|
||||
Reference in New Issue
Block a user