mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore(reader/webtoon): Match extra layout space with scroll distance
Also increase recycler item view cache size
This commit is contained in:
parent
6a02e7f0a0
commit
8195fe56fd
2 changed files with 13 additions and 14 deletions
|
@ -13,12 +13,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
* This layout manager uses the same package name as the support library in order to use a package
|
* This layout manager uses the same package name as the support library in order to use a package
|
||||||
* protected method.
|
* protected method.
|
||||||
*/
|
*/
|
||||||
class WebtoonLayoutManager(activity: ReaderActivity) : LinearLayoutManager(activity) {
|
class WebtoonLayoutManager(activity: ReaderActivity, private val extraLayoutSpace: Int) : LinearLayoutManager(activity) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Extra layout space is set to half the screen height.
|
|
||||||
*/
|
|
||||||
private val extraLayoutSpace = activity.resources.displayMetrics.heightPixels / 2
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
isItemPrefetchEnabled = false
|
isItemPrefetchEnabled = false
|
||||||
|
@ -27,7 +22,8 @@ class WebtoonLayoutManager(activity: ReaderActivity) : LinearLayoutManager(activ
|
||||||
/**
|
/**
|
||||||
* Returns the custom extra layout space.
|
* Returns the custom extra layout space.
|
||||||
*/
|
*/
|
||||||
override fun getExtraLayoutSpace(state: androidx.recyclerview.widget.RecyclerView.State): Int {
|
@Deprecated("Deprecated in Java")
|
||||||
|
override fun getExtraLayoutSpace(state: RecyclerView.State): Int {
|
||||||
return extraLayoutSpace
|
return extraLayoutSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +33,7 @@ class WebtoonLayoutManager(activity: ReaderActivity) : LinearLayoutManager(activ
|
||||||
fun findLastEndVisibleItemPosition(): Int {
|
fun findLastEndVisibleItemPosition(): Int {
|
||||||
ensureLayoutState()
|
ensureLayoutState()
|
||||||
@ViewBoundsCheck.ViewBounds val preferredBoundsFlag =
|
@ViewBoundsCheck.ViewBounds val preferredBoundsFlag =
|
||||||
(androidx.recyclerview.widget.ViewBoundsCheck.FLAG_CVE_LT_PVE or androidx.recyclerview.widget.ViewBoundsCheck.FLAG_CVE_EQ_PVE)
|
(ViewBoundsCheck.FLAG_CVE_LT_PVE or ViewBoundsCheck.FLAG_CVE_EQ_PVE)
|
||||||
|
|
||||||
val fromIndex = childCount - 1
|
val fromIndex = childCount - 1
|
||||||
val toIndex = -1
|
val toIndex = -1
|
||||||
|
|
|
@ -43,21 +43,21 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals
|
||||||
*/
|
*/
|
||||||
private val frame = WebtoonFrame(activity)
|
private val frame = WebtoonFrame(activity)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance to scroll when the user taps on one side of the recycler view.
|
||||||
|
*/
|
||||||
|
private var scrollDistance = activity.resources.displayMetrics.heightPixels * 3 / 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Layout manager of the recycler view.
|
* Layout manager of the recycler view.
|
||||||
*/
|
*/
|
||||||
private val layoutManager = WebtoonLayoutManager(activity)
|
private val layoutManager = WebtoonLayoutManager(activity, scrollDistance)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter of the recycler view.
|
* Adapter of the recycler view.
|
||||||
*/
|
*/
|
||||||
private val adapter = WebtoonAdapter(this)
|
private val adapter = WebtoonAdapter(this)
|
||||||
|
|
||||||
/**
|
|
||||||
* Distance to scroll when the user taps on one side of the recycler view.
|
|
||||||
*/
|
|
||||||
private var scrollDistance = activity.resources.displayMetrics.heightPixels * 3 / 4
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently active item. It can be a chapter page or a chapter transition.
|
* Currently active item. It can be a chapter page or a chapter transition.
|
||||||
*/
|
*/
|
||||||
|
@ -69,6 +69,7 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals
|
||||||
val config = WebtoonConfig(scope)
|
val config = WebtoonConfig(scope)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
recycler.setItemViewCacheSize(RECYCLER_VIEW_CACHE_SIZE)
|
||||||
recycler.isVisible = false // Don't let the recycler layout yet
|
recycler.isVisible = false // Don't let the recycler layout yet
|
||||||
recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||||
recycler.itemAnimator = null
|
recycler.itemAnimator = null
|
||||||
|
@ -328,3 +329,5 @@ class WebtoonViewer(val activity: ReaderActivity, val hasMargins: Boolean = fals
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val RECYCLER_VIEW_CACHE_SIZE = 4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue