diff --git a/app/src/main/java/eu/kanade/presentation/category/CategoryExtensions.kt b/app/src/main/java/eu/kanade/presentation/category/CategoryExtensions.kt index a9a5a64e5..859c789ac 100644 --- a/app/src/main/java/eu/kanade/presentation/category/CategoryExtensions.kt +++ b/app/src/main/java/eu/kanade/presentation/category/CategoryExtensions.kt @@ -8,13 +8,13 @@ import eu.kanade.tachiyomi.R val Category.visualName: String @Composable - get() = when (id) { - Category.UNCATEGORIZED_ID -> stringResource(id = R.string.label_default) + get() = when { + isSystemCategory -> stringResource(id = R.string.label_default) else -> name } fun Category.visualName(context: Context): String = - when (id) { - Category.UNCATEGORIZED_ID -> context.getString(R.string.label_default) + when { + isSystemCategory -> context.getString(R.string.label_default) else -> name } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt index 0319c1cda..abbdd3c9c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.network.await import eu.kanade.tachiyomi.network.jsonMime import eu.kanade.tachiyomi.network.parseAs import eu.kanade.tachiyomi.util.lang.withIOContext -import kotlinx.coroutines.runBlocking import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonObject @@ -127,15 +126,13 @@ class ShikimoriApi(private val client: OkHttpClient, interceptor: ShikimoriInter } } - fun getCurrentUser(): Int { - return runBlocking { - authClient.newCall(GET("$apiUrl/users/whoami")) - .await() - .parseAs() - .let { - it["id"]!!.jsonPrimitive.int - } - } + suspend fun getCurrentUser(): Int { + return authClient.newCall(GET("$apiUrl/users/whoami")) + .await() + .parseAs() + .let { + it["id"]!!.jsonPrimitive.int + } } suspend fun accessToken(code: String): OAuth { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index a26e8989c..913749de6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -389,7 +389,7 @@ open class BrowseSourcePresenter( suspend fun getCategories(): List { return getCategories.subscribe() .firstOrNull() - ?.filterNot { it.id == DomainCategory.UNCATEGORIZED_ID } + ?.filterNot { it.isSystemCategory } ?: emptyList() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index 18c04019e..280b4f7fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -32,14 +32,6 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -/** - * Presenter of [GlobalSearchController] - * Function calls should be done from here. UI calls should be done from the controller. - * - * @param sourceManager manages the different sources. - * @param db manages the database calls. - * @param preferences manages the preference calls. - */ open class GlobalSearchPresenter( private val initialQuery: String? = "", private val initialExtensionFilter: String? = null, @@ -256,7 +248,7 @@ open class GlobalSearchPresenter( val networkManga = source.getMangaDetails(manga.toMangaInfo()) manga.copyFrom(networkManga.toSManga()) manga.initialized = true - runBlocking { updateManga.await(manga.toDomainManga()!!.toMangaUpdate()) } + updateManga.await(manga.toDomainManga()!!.toMangaUpdate()) return manga } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 9ad503ff3..c8fad392c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -408,7 +408,7 @@ class LibraryPresenter( private fun getLibraryObservable(): Observable { return combine(getCategoriesFlow(), getLibraryMangasFlow()) { dbCategories, libraryManga -> val categories = if (libraryManga.isNotEmpty() && libraryManga.containsKey(0).not()) { - dbCategories.filterNot { it.id == Category.UNCATEGORIZED_ID } + dbCategories.filterNot { it.isSystemCategory } } else { dbCategories } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 9c840824d..a34c97bfd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView import eu.kanade.tachiyomi.widget.materialdialogs.await import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import logcat.LogPriority import eu.kanade.domain.chapter.model.Chapter as DomainChapter @@ -214,7 +215,7 @@ class MangaController : } } else null, onRequireCategory = { manga, categories -> - val ids = presenter.getMangaCategoryIds(manga) + val ids = runBlocking { presenter.getMangaCategoryIds(manga) } val preselected = categories.map { if (it.id in ids) { QuadStateTextView.State.CHECKED.ordinal 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 6b43533d9..35e1a66d1 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 @@ -64,7 +64,6 @@ import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.withContext import logcat.LogPriority @@ -351,7 +350,7 @@ class MangaPresenter( * @return List of categories, not including the default category */ suspend fun getCategories(): List { - return getCategories.await() + return getCategories.await().filterNot { it.isSystemCategory } } /** @@ -360,8 +359,8 @@ class MangaPresenter( * @param manga the manga to get categories from. * @return Array of category ids the manga is in, if none returns default id */ - fun getMangaCategoryIds(manga: DomainManga): Array { - val categories = runBlocking { getCategories.await(manga.id) } + suspend fun getMangaCategoryIds(manga: DomainManga): Array { + val categories = getCategories.await(manga.id) return categories.map { it.id }.toTypedArray() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 4bdc53564..71f37ad54 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -9,8 +9,9 @@ import eu.kanade.tachiyomi.data.updater.AppUpdateChecker import eu.kanade.tachiyomi.data.updater.AppUpdateResult import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController import eu.kanade.tachiyomi.ui.base.controller.pushController -import eu.kanade.tachiyomi.util.lang.launchNow +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.toDateTimestampString +import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.toast import logcat.LogPriority @@ -43,20 +44,23 @@ class AboutController : BasicFullComposeController() { activity!!.toast(R.string.update_check_look_for_updates) - launchNow { - try { - when (val result = updateChecker.checkForUpdate(activity!!, isUserPrompt = true)) { - is AppUpdateResult.NewUpdate -> { - NewUpdateDialogController(result).showDialog(router) + viewScope.launchIO { + val result = updateChecker.checkForUpdate(activity!!, isUserPrompt = true) + withUIContext { + try { + when (result) { + is AppUpdateResult.NewUpdate -> { + NewUpdateDialogController(result).showDialog(router) + } + is AppUpdateResult.NoNewUpdate -> { + activity?.toast(R.string.update_check_no_new_updates) + } + else -> {} } - is AppUpdateResult.NoNewUpdate -> { - activity?.toast(R.string.update_check_no_new_updates) - } - else -> {} + } catch (error: Exception) { + activity?.toast(error.message) + logcat(LogPriority.ERROR, error) } - } catch (error: Exception) { - activity?.toast(error.message) - logcat(LogPriority.ERROR, error) } } }