Ignore network error for background progress update

master
Koitharu 10 months ago
parent f0ba42b518
commit 088576cc9d
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.util.ext.EventFlow
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.call
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.EmptyCoroutineContext
@ -80,10 +81,15 @@ abstract class BaseViewModel : ViewModel() {
protected fun MutableStateFlow<Int>.decrement() = update { it - 1 } protected fun MutableStateFlow<Int>.decrement() = update { it - 1 }
private fun createErrorHandler() = CoroutineExceptionHandler { _, throwable -> private fun createErrorHandler() = CoroutineExceptionHandler { coroutineContext, throwable ->
throwable.printStackTraceDebug() throwable.printStackTraceDebug()
if (throwable !is CancellationException) { if (coroutineContext[SkipErrors.key] == null && throwable !is CancellationException) {
errorEvent.call(throwable) errorEvent.call(throwable)
} }
} }
protected object SkipErrors : AbstractCoroutineContextElement(Key) {
private object Key : CoroutineContext.Key<SkipErrors>
}
} }

@ -182,7 +182,7 @@ class DetailsViewModel @Inject constructor(
init { init {
loadingJob = doLoad(force = false) loadingJob = doLoad(force = false)
launchJob(Dispatchers.Default) { launchJob(Dispatchers.Default + SkipErrors) {
val manga = mangaDetails.firstOrNull { !it?.chapters.isNullOrEmpty() } ?: return@launchJob val manga = mangaDetails.firstOrNull { !it?.chapters.isNullOrEmpty() } ?: return@launchJob
val h = history.firstOrNull() val h = history.firstOrNull()
if (h != null) { if (h != null) {

@ -13,6 +13,7 @@ constraintlayout = "2.2.1"
coreKtx = "1.16.0" coreKtx = "1.16.0"
coroutines = "1.10.2" coroutines = "1.10.2"
dagger = "2.56.2" dagger = "2.56.2"
decoroutinator = "2.5.4"
desugar = "2.1.5" desugar = "2.1.5"
diskLruCache = "1.5" diskLruCache = "1.5"
documentfile = "1.1.0" documentfile = "1.1.0"
@ -119,3 +120,4 @@ kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinx-serizliation = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlinx-serizliation = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
room = { id = "androidx.room", version.ref = "room" } room = { id = "androidx.room", version.ref = "room" }
decoroutinator = { id = "dev.reformator.stacktracedecoroutinator", version.ref = "decoroutinator" }

Loading…
Cancel
Save