Update in-app update checking

This commit is contained in:
Koitharu
2022-07-21 19:32:32 +03:00
parent c158c4e18e
commit 089e3dc209
19 changed files with 232 additions and 105 deletions

View File

@@ -3,11 +3,11 @@ package org.koitharu.kotatsu.utils.ext
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.liveData
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import org.koitharu.kotatsu.utils.BufferedObserver
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
fun <T> LiveData<T>.requireValue(): T = checkNotNull(value) {
"LiveData value is null"
@@ -22,12 +22,12 @@ fun <T> LiveData<T>.observeWithPrevious(owner: LifecycleOwner, observer: Buffere
}
fun <T> StateFlow<T>.asLiveDataDistinct(
context: CoroutineContext = EmptyCoroutineContext
context: CoroutineContext = EmptyCoroutineContext,
): LiveData<T> = asLiveDataDistinct(context, value)
fun <T> Flow<T>.asLiveDataDistinct(
context: CoroutineContext = EmptyCoroutineContext,
defaultValue: T
defaultValue: T,
): LiveData<T> = liveData(context) {
if (latestValue == null) {
emit(defaultValue)
@@ -37,4 +37,4 @@ fun <T> Flow<T>.asLiveDataDistinct(
emit(it)
}
}
}
}