Improve page loading progress displaying

This commit is contained in:
Koitharu
2022-11-12 10:28:47 +02:00
parent b599cb33ff
commit c896ac72e8
5 changed files with 62 additions and 41 deletions

View File

@@ -33,6 +33,7 @@ import org.koitharu.kotatsu.parsers.util.await
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.utils.ext.connectivityManager
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
import org.koitharu.kotatsu.utils.ext.withProgress
import org.koitharu.kotatsu.utils.progress.ProgressDeferred
import java.io.File
import java.util.LinkedList
@@ -203,8 +204,8 @@ class PageLoader @Inject constructor(
val body = checkNotNull(response.body) {
"Null response"
}
body.byteStream().use {
cache.put(pageUrl, it, body.contentLength(), progress)
body.withProgress(progress).byteStream().use {
cache.put(pageUrl, it)
}
}
}

View File

@@ -143,7 +143,7 @@ class PageHolderDelegate(
}
private fun observeProgress(scope: CoroutineScope, progress: Flow<Float>) = progress
.debounce(500)
.debounce(250)
.onEach { callback.onProgressChanged((100 * it).toInt()) }
.launchIn(scope)