From ed8a54bd2ae58f9fb58d1d92318b5dcb4c7ce3f5 Mon Sep 17 00:00:00 2001 From: jobobby04 Date: Mon, 2 May 2022 08:31:50 -0400 Subject: [PATCH] Properly modify StateFlow value (#7059) --- .../migration/manga/MigrationMangaPresenter.kt | 4 ++-- .../sources/MigrationSourcesPresenter.kt | 4 ++-- .../ui/browse/source/SourceFilterPresenter.kt | 4 ++-- .../ui/browse/source/SourcePresenter.kt | 4 ++-- .../kanade/tachiyomi/ui/more/MorePresenter.kt | 17 ++++++++--------- .../ui/recent/history/HistoryPresenter.kt | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt index 97bab21a2..156bb5cd5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt @@ -27,10 +27,10 @@ class MigrationMangaPresenter( getFavoritesBySourceId .subscribe(sourceId) .catch { exception -> - _state.emit(MigrateMangaState.Error(exception)) + _state.value = MigrateMangaState.Error(exception) } .collectLatest { list -> - _state.emit(MigrateMangaState.Success(list)) + _state.value = MigrateMangaState.Success(list) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt index 37a2c1069..019d31817 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesPresenter.kt @@ -28,10 +28,10 @@ class MigrationSourcesPresenter( presenterScope.launchIO { getSourcesWithFavoriteCount.subscribe() .catch { exception -> - _state.emit(MigrateSourceState.Error(exception)) + _state.value = MigrateSourceState.Error(exception) } .collectLatest { sources -> - _state.emit(MigrateSourceState.Success(sources)) + _state.value = MigrateSourceState.Success(sources) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterPresenter.kt index dd94b3d9d..d57048c6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterPresenter.kt @@ -31,11 +31,11 @@ class SourceFilterPresenter( presenterScope.launchIO { getLanguagesWithSources.subscribe() .catch { exception -> - _state.emit(SourceFilterState.Error(exception)) + _state.value = SourceFilterState.Error(exception) } .collectLatest { sourceLangMap -> val uiModels = sourceLangMap.toFilterUiModels() - _state.emit(SourceFilterState.Success(uiModels)) + _state.value = SourceFilterState.Success(uiModels) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt index ee0ea1a08..3f30be1f9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt @@ -36,7 +36,7 @@ class SourcePresenter( presenterScope.launchIO { getEnabledSources.subscribe() .catch { exception -> - _state.emit(SourceState.Error(exception)) + _state.value = SourceState.Error(exception) } .collectLatest(::collectLatestSources) } @@ -71,7 +71,7 @@ class SourcePresenter( }.toTypedArray(), ) } - _state.emit(SourceState.Success(uiModels)) + _state.value = SourceState.Success(uiModels) } fun toggleSource(source: Source) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt index 9ceef9856..74840fb8e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -24,7 +25,7 @@ class MorePresenter( val incognitoMode = preferencesHelper.incognitoMode().asState() private var _state: MutableStateFlow = MutableStateFlow(DownloadQueueState.Stopped) - val downloadQueueState: StateFlow = _state + val downloadQueueState: StateFlow = _state.asStateFlow() private var isDownloading: Boolean = false private var downloadQueueSize: Int = 0 @@ -66,14 +67,12 @@ class MorePresenter( private fun updateDownloadQueueState() { presenterScope.launchIO { val pendingDownloadExists = downloadQueueSize != 0 - _state.emit( - when { - !pendingDownloadExists -> DownloadQueueState.Stopped - !isDownloading && !pendingDownloadExists -> DownloadQueueState.Paused(0) - !isDownloading && pendingDownloadExists -> DownloadQueueState.Paused(downloadQueueSize) - else -> DownloadQueueState.Downloading(downloadQueueSize) - } - ) + _state.value = when { + !pendingDownloadExists -> DownloadQueueState.Stopped + !isDownloading && !pendingDownloadExists -> DownloadQueueState.Paused(0) + !isDownloading && pendingDownloadExists -> DownloadQueueState.Paused(downloadQueueSize) + else -> DownloadQueueState.Downloading(downloadQueueSize) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index a04abbe6e..75306324d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -53,14 +53,14 @@ class HistoryPresenter( _query.collectLatest { query -> getHistory.subscribe(query) .catch { exception -> - _state.emit(HistoryState.Error(exception)) + _state.value = HistoryState.Error(exception) } .map { pagingData -> pagingData.toHistoryUiModels() } .cachedIn(presenterScope) .let { uiModelsPagingDataFlow -> - _state.emit(HistoryState.Success(uiModelsPagingDataFlow)) + _state.value = HistoryState.Success(uiModelsPagingDataFlow) } } }