From e511f24979b0f40c545345ed151d3557644f79c6 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 10 Aug 2022 16:11:12 -0400 Subject: [PATCH] Fix crash when setting cover errors (closes #7714) --- .../details/ExtensionDetailsPresenter.kt | 4 +-- .../migration/search/SearchPresenter.kt | 3 +- .../tachiyomi/ui/library/LibraryController.kt | 4 +-- .../tachiyomi/ui/manga/MangaPresenter.kt | 11 ++++---- .../ui/manga/info/MangaFullCoverDialog.kt | 16 +++++------ .../tachiyomi/ui/reader/ReaderPresenter.kt | 28 +++++++++---------- .../ui/recent/history/HistoryPresenter.kt | 4 +-- .../kanade/tachiyomi/util/MangaExtensions.kt | 7 ++--- 8 files changed, 34 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt index e2595e0cdb..59d26ba1fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO -import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.LocaleHelper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.collectLatest @@ -36,7 +36,7 @@ class ExtensionDetailsPresenter( .collectLatest { extension -> // If extension is null it's most likely uninstalled if (extension == null) { - launchUI { + withUIContext { view?.onExtensionUninstalled() } return@collectLatest diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index 79aa1926b9..d803eb40a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -29,7 +29,6 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.util.lang.launchIO -import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.toast import uy.kohesive.injekt.Injekt @@ -98,7 +97,7 @@ class SearchPresenter( withUIContext { view?.applicationContext?.toast(e.message) } } - presenterScope.launchUI { replacingMangaRelay.call(Pair(false, manga)) } + withUIContext { replacingMangaRelay.call(Pair(false, manga)) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index b4fa87fd9e..d02a51b316 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -22,7 +22,7 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.lang.launchIO -import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView import kotlinx.coroutines.cancel @@ -182,7 +182,7 @@ class LibraryController( else -> QuadStateTextView.State.UNCHECKED.ordinal } }.toTypedArray() - launchUI { + withUIContext { ChangeMangaCategoriesDialog(this@LibraryController, mangas.mapNotNull { it.toDomainManga() }, categories, preselected) .showDialog(router) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 10de78ff6f..2119a0c8c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -42,7 +42,6 @@ import eu.kanade.tachiyomi.ui.manga.track.TrackItem import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper import eu.kanade.tachiyomi.util.chapter.getChapterSort import eu.kanade.tachiyomi.util.lang.launchIO -import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.toRelativeString import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.preference.asHotFlow @@ -276,7 +275,7 @@ class MangaPresenter( if (manga.toDbManga().removeCovers() > 0) { updateManga.awaitUpdateCoverLastModified(manga.id) } - launchUI { onRemoved() } + withUIContext { onRemoved() } } } else { // Add to library @@ -284,7 +283,7 @@ class MangaPresenter( if (onDuplicateExists != null) { val duplicate = getDuplicateLibraryManga.await(manga.title, manga.source) if (duplicate != null) { - launchUI { onDuplicateExists(duplicate) } + withUIContext { onDuplicateExists(duplicate) } return@launchIO } } @@ -299,7 +298,7 @@ class MangaPresenter( val result = updateManga.awaitUpdateFavorite(manga.id, true) if (!result) return@launchIO moveMangaToCategory(defaultCategory) - launchUI { onAdded() } + withUIContext { onAdded() } } // Automatic 'Default' or no categories @@ -307,11 +306,11 @@ class MangaPresenter( val result = updateManga.awaitUpdateFavorite(manga.id, true) if (!result) return@launchIO moveMangaToCategory(null) - launchUI { onAdded() } + withUIContext { onAdded() } } // Choose a category - else -> launchUI { onRequireCategory(manga, categories) } + else -> withUIContext { onRequireCategory(manga, categories) } } // Finally match with enhanced tracking when available diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaFullCoverDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaFullCoverDialog.kt index c8bf71f1e0..24f34aa331 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaFullCoverDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaFullCoverDialog.kt @@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.data.saver.Location import eu.kanade.tachiyomi.ui.base.controller.FullComposeController import eu.kanade.tachiyomi.util.editCover import eu.kanade.tachiyomi.util.lang.launchIO -import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.toShareIntent @@ -81,11 +80,11 @@ class MangaFullCoverDialog : FullComposeController