Fix manga downloading
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import androidx.annotation.Px
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class RecyclerViewScrollCallback(recyclerView: RecyclerView, private val position: Int) : Runnable {
|
||||
class RecyclerViewScrollCallback(
|
||||
recyclerView: RecyclerView,
|
||||
private val position: Int,
|
||||
@Px private val offset: Int,
|
||||
) : Runnable {
|
||||
|
||||
private val recyclerViewRef = WeakReference(recyclerView)
|
||||
|
||||
@@ -13,7 +18,7 @@ class RecyclerViewScrollCallback(recyclerView: RecyclerView, private val positio
|
||||
val lm = rv.layoutManager ?: return
|
||||
rv.stopScroll()
|
||||
if (lm is LinearLayoutManager) {
|
||||
lm.scrollToPositionWithOffset(position, 0)
|
||||
lm.scrollToPositionWithOffset(position, offset)
|
||||
} else {
|
||||
lm.scrollToPosition(position)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.os.SystemClock
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.transform
|
||||
import kotlinx.coroutines.flow.transformLatest
|
||||
|
||||
fun <T> Flow<T>.onFirst(action: suspend (T) -> Unit): Flow<T> {
|
||||
var isFirstCall = true
|
||||
@@ -17,4 +19,19 @@ fun <T> Flow<T>.onFirst(action: suspend (T) -> Unit): Flow<T> {
|
||||
|
||||
inline fun <T, R> Flow<List<T>>.mapItems(crossinline transform: (T) -> R): Flow<List<R>> {
|
||||
return map { list -> list.map(transform) }
|
||||
}
|
||||
|
||||
fun <T> Flow<T>.throttle(timeoutMillis: (T) -> Long): Flow<T> {
|
||||
var lastEmittedAt = 0L
|
||||
return transformLatest { value ->
|
||||
val delay = timeoutMillis(value)
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
if (delay > 0L) {
|
||||
if (lastEmittedAt + delay < now) {
|
||||
delay(lastEmittedAt + delay - now)
|
||||
}
|
||||
}
|
||||
emit(value)
|
||||
lastEmittedAt = now
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user