From c44db54d9f729f94c53ccf690cb86e8bac332189 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Sun, 18 Dec 2022 01:06:49 +0800 Subject: [PATCH] Fix snackbar blocking refreshing state in MangaScreen (#8759) --- .../tachiyomi/ui/manga/MangaScreenModel.kt | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 9ba65edbd..ffaabcf35 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -213,20 +213,19 @@ class MangaInfoScreenModel( * Fetch manga information from source. */ private suspend fun fetchMangaFromSource(manualFetch: Boolean = false) { - withIOContext { - try { - successState?.let { - val networkManga = it.source.getMangaDetails(it.manga.toSManga()) - updateManga.awaitUpdateFromSource(it.manga, networkManga, manualFetch) - } - } catch (e: Throwable) { - withUIContext { - // Ignore early hints "errors" that aren't handled by OkHttp - if (e !is HttpException || e.code != 103) { - snackbarHostState.showSnackbar(message = "${e.message}") - logcat(LogPriority.ERROR, e) - } - } + val state = successState ?: return + try { + withIOContext { + val networkManga = state.source.getMangaDetails(state.manga.toSManga()) + updateManga.awaitUpdateFromSource(state.manga, networkManga, manualFetch) + } + } catch (e: Throwable) { + // Ignore early hints "errors" that aren't handled by OkHttp + if (e is HttpException && e.code == 103) return + + logcat(LogPriority.ERROR, e) + coroutineScope.launch { + snackbarHostState.showSnackbar(message = e.toString()) } } } @@ -524,31 +523,32 @@ class MangaInfoScreenModel( * Requests an updated list of chapters from the source. */ private suspend fun fetchChaptersFromSource(manualFetch: Boolean = false) { - withIOContext { - try { - successState?.let { successState -> - val chapters = successState.source.getChapterList(successState.manga.toSManga()) + val state = successState ?: return + try { + withIOContext { + val chapters = state.source.getChapterList(state.manga.toSManga()) - val newChapters = syncChaptersWithSource.await( - chapters, - successState.manga, - successState.source, - ) + val newChapters = syncChaptersWithSource.await( + chapters, + state.manga, + state.source, + ) - if (manualFetch) { - downloadNewChapters(newChapters) - } - } - } catch (e: Throwable) { - withUIContext { - if (e is NoChaptersException) { - snackbarHostState.showSnackbar(message = context.getString(R.string.no_chapters_error)) - } else { - snackbarHostState.showSnackbar(message = "${e.message}") - logcat(LogPriority.ERROR, e) - } + if (manualFetch) { + downloadNewChapters(newChapters) } } + } catch (e: Throwable) { + val message = if (e is NoChaptersException) { + context.getString(R.string.no_chapters_error) + } else { + logcat(LogPriority.ERROR, e) + e.toString() + } + + coroutineScope.launch { + snackbarHostState.showSnackbar(message = message) + } } }