|
|
|
@ -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>
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|