Properly modify StateFlow value (#7059)
This commit is contained in:
parent
5bd5b21543
commit
ed8a54bd2a
@ -27,10 +27,10 @@ class MigrationMangaPresenter(
|
|||||||
getFavoritesBySourceId
|
getFavoritesBySourceId
|
||||||
.subscribe(sourceId)
|
.subscribe(sourceId)
|
||||||
.catch { exception ->
|
.catch { exception ->
|
||||||
_state.emit(MigrateMangaState.Error(exception))
|
_state.value = MigrateMangaState.Error(exception)
|
||||||
}
|
}
|
||||||
.collectLatest { list ->
|
.collectLatest { list ->
|
||||||
_state.emit(MigrateMangaState.Success(list))
|
_state.value = MigrateMangaState.Success(list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,10 @@ class MigrationSourcesPresenter(
|
|||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
getSourcesWithFavoriteCount.subscribe()
|
getSourcesWithFavoriteCount.subscribe()
|
||||||
.catch { exception ->
|
.catch { exception ->
|
||||||
_state.emit(MigrateSourceState.Error(exception))
|
_state.value = MigrateSourceState.Error(exception)
|
||||||
}
|
}
|
||||||
.collectLatest { sources ->
|
.collectLatest { sources ->
|
||||||
_state.emit(MigrateSourceState.Success(sources))
|
_state.value = MigrateSourceState.Success(sources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@ class SourceFilterPresenter(
|
|||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
getLanguagesWithSources.subscribe()
|
getLanguagesWithSources.subscribe()
|
||||||
.catch { exception ->
|
.catch { exception ->
|
||||||
_state.emit(SourceFilterState.Error(exception))
|
_state.value = SourceFilterState.Error(exception)
|
||||||
}
|
}
|
||||||
.collectLatest { sourceLangMap ->
|
.collectLatest { sourceLangMap ->
|
||||||
val uiModels = sourceLangMap.toFilterUiModels()
|
val uiModels = sourceLangMap.toFilterUiModels()
|
||||||
_state.emit(SourceFilterState.Success(uiModels))
|
_state.value = SourceFilterState.Success(uiModels)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class SourcePresenter(
|
|||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
getEnabledSources.subscribe()
|
getEnabledSources.subscribe()
|
||||||
.catch { exception ->
|
.catch { exception ->
|
||||||
_state.emit(SourceState.Error(exception))
|
_state.value = SourceState.Error(exception)
|
||||||
}
|
}
|
||||||
.collectLatest(::collectLatestSources)
|
.collectLatest(::collectLatestSources)
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ class SourcePresenter(
|
|||||||
}.toTypedArray(),
|
}.toTypedArray(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_state.emit(SourceState.Success(uiModels))
|
_state.value = SourceState.Success(uiModels)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleSource(source: Source) {
|
fun toggleSource(source: Source) {
|
||||||
|
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
|||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -24,7 +25,7 @@ class MorePresenter(
|
|||||||
val incognitoMode = preferencesHelper.incognitoMode().asState()
|
val incognitoMode = preferencesHelper.incognitoMode().asState()
|
||||||
|
|
||||||
private var _state: MutableStateFlow<DownloadQueueState> = MutableStateFlow(DownloadQueueState.Stopped)
|
private var _state: MutableStateFlow<DownloadQueueState> = MutableStateFlow(DownloadQueueState.Stopped)
|
||||||
val downloadQueueState: StateFlow<DownloadQueueState> = _state
|
val downloadQueueState: StateFlow<DownloadQueueState> = _state.asStateFlow()
|
||||||
|
|
||||||
private var isDownloading: Boolean = false
|
private var isDownloading: Boolean = false
|
||||||
private var downloadQueueSize: Int = 0
|
private var downloadQueueSize: Int = 0
|
||||||
@ -66,14 +67,12 @@ class MorePresenter(
|
|||||||
private fun updateDownloadQueueState() {
|
private fun updateDownloadQueueState() {
|
||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
val pendingDownloadExists = downloadQueueSize != 0
|
val pendingDownloadExists = downloadQueueSize != 0
|
||||||
_state.emit(
|
_state.value = when {
|
||||||
when {
|
!pendingDownloadExists -> DownloadQueueState.Stopped
|
||||||
!pendingDownloadExists -> DownloadQueueState.Stopped
|
!isDownloading && !pendingDownloadExists -> DownloadQueueState.Paused(0)
|
||||||
!isDownloading && !pendingDownloadExists -> DownloadQueueState.Paused(0)
|
!isDownloading && pendingDownloadExists -> DownloadQueueState.Paused(downloadQueueSize)
|
||||||
!isDownloading && pendingDownloadExists -> DownloadQueueState.Paused(downloadQueueSize)
|
else -> DownloadQueueState.Downloading(downloadQueueSize)
|
||||||
else -> DownloadQueueState.Downloading(downloadQueueSize)
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,14 +53,14 @@ class HistoryPresenter(
|
|||||||
_query.collectLatest { query ->
|
_query.collectLatest { query ->
|
||||||
getHistory.subscribe(query)
|
getHistory.subscribe(query)
|
||||||
.catch { exception ->
|
.catch { exception ->
|
||||||
_state.emit(HistoryState.Error(exception))
|
_state.value = HistoryState.Error(exception)
|
||||||
}
|
}
|
||||||
.map { pagingData ->
|
.map { pagingData ->
|
||||||
pagingData.toHistoryUiModels()
|
pagingData.toHistoryUiModels()
|
||||||
}
|
}
|
||||||
.cachedIn(presenterScope)
|
.cachedIn(presenterScope)
|
||||||
.let { uiModelsPagingDataFlow ->
|
.let { uiModelsPagingDataFlow ->
|
||||||
_state.emit(HistoryState.Success(uiModelsPagingDataFlow))
|
_state.value = HistoryState.Success(uiModelsPagingDataFlow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user