Dynamic chapters loading
parent
60567757ae
commit
9adf19b898
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader
|
||||||
|
|
||||||
|
interface OnBoundsScrollListener {
|
||||||
|
|
||||||
|
fun onScrolledToStart()
|
||||||
|
|
||||||
|
fun onScrolledToEnd()
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
|
|
||||||
|
interface ReaderListener {
|
||||||
|
|
||||||
|
fun onPageChanged(chapter: MangaChapter, page: Int, total: Int)
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader.standard
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import org.koitharu.kotatsu.ui.reader.OnBoundsScrollListener
|
||||||
|
|
||||||
|
class PagerPaginationListener(
|
||||||
|
private val adapter: RecyclerView.Adapter<*>,
|
||||||
|
private val offset: Int,
|
||||||
|
private val listener: OnBoundsScrollListener
|
||||||
|
) : ViewPager2.OnPageChangeCallback() {
|
||||||
|
|
||||||
|
private var lastItemCountStart = 0
|
||||||
|
private var lastItemCountEnd = 0
|
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
val itemCount = adapter.itemCount
|
||||||
|
if (position <= offset && itemCount != lastItemCountStart) {
|
||||||
|
lastItemCountStart = itemCount
|
||||||
|
listener.onScrolledToStart()
|
||||||
|
} else if (position >= itemCount - offset && itemCount != lastItemCountEnd) {
|
||||||
|
lastItemCountEnd = itemCount
|
||||||
|
listener.onScrolledToEnd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.ui.reader.OnBoundsScrollListener
|
||||||
|
|
||||||
|
class ListPaginationListener(
|
||||||
|
private val offset: Int,
|
||||||
|
private val listener: OnBoundsScrollListener
|
||||||
|
) : RecyclerView.OnScrollListener() {
|
||||||
|
|
||||||
|
private var lastItemCountStart = 0
|
||||||
|
private var lastItemCountEnd = 0
|
||||||
|
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
|
val itemCount = recyclerView.adapter?.itemCount ?: return
|
||||||
|
val layoutManager = (recyclerView.layoutManager as? LinearLayoutManager) ?: return
|
||||||
|
val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition()
|
||||||
|
val lastVisiblePosition = layoutManager.findLastVisibleItemPosition()
|
||||||
|
if (firstVisiblePosition <= offset && itemCount != lastItemCountStart) {
|
||||||
|
lastItemCountStart = itemCount
|
||||||
|
listener.onScrolledToStart()
|
||||||
|
} else if (lastVisiblePosition >= itemCount - offset && itemCount != lastItemCountEnd) {
|
||||||
|
lastItemCountEnd = itemCount
|
||||||
|
listener.onScrolledToEnd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue