Use SharedFlow for available extensions to always emit the value (#7609)

- Fixes Extension screen being stuck refreshing due to StateFlow not emitting due to the value being the same
This commit is contained in:
Andreas 2022-07-25 14:31:41 +02:00 committed by GitHub
parent 76057b84b2
commit 73901f50c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,8 +19,11 @@ import eu.kanade.tachiyomi.util.preference.plusAssign
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import logcat.LogPriority import logcat.LogPriority
import rx.Observable import rx.Observable
@ -93,15 +96,15 @@ class ExtensionManager(
var availableExtensions = emptyList<Extension.Available>() var availableExtensions = emptyList<Extension.Available>()
private set(value) { private set(value) {
field = value field = value
availableExtensionsFlow.value = field availableExtensionsFlow.tryEmit(field)
updatedInstalledExtensionsStatuses(value) updatedInstalledExtensionsStatuses(value)
setupAvailableExtensionsSourcesDataMap(value) setupAvailableExtensionsSourcesDataMap(value)
} }
private val availableExtensionsFlow = MutableStateFlow(availableExtensions) private val availableExtensionsFlow = MutableSharedFlow<List<Extension.Available>>(replay = 1)
fun getAvailableExtensionsFlow(): StateFlow<List<Extension.Available>> { fun getAvailableExtensionsFlow(): Flow<List<Extension.Available>> {
return availableExtensionsFlow.asStateFlow() return availableExtensionsFlow.asSharedFlow()
} }
private var availableExtensionsSourcesData: Map<Long, SourceData> = mapOf() private var availableExtensionsSourcesData: Map<Long, SourceData> = mapOf()