mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix snackbar blocking refreshing state in MangaScreen (#8759)
This commit is contained in:
parent
376bbeb724
commit
c44db54d9f
1 changed files with 35 additions and 35 deletions
|
@ -213,20 +213,19 @@ class MangaInfoScreenModel(
|
||||||
* Fetch manga information from source.
|
* Fetch manga information from source.
|
||||||
*/
|
*/
|
||||||
private suspend fun fetchMangaFromSource(manualFetch: Boolean = false) {
|
private suspend fun fetchMangaFromSource(manualFetch: Boolean = false) {
|
||||||
withIOContext {
|
val state = successState ?: return
|
||||||
try {
|
try {
|
||||||
successState?.let {
|
withIOContext {
|
||||||
val networkManga = it.source.getMangaDetails(it.manga.toSManga())
|
val networkManga = state.source.getMangaDetails(state.manga.toSManga())
|
||||||
updateManga.awaitUpdateFromSource(it.manga, networkManga, manualFetch)
|
updateManga.awaitUpdateFromSource(state.manga, networkManga, manualFetch)
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
withUIContext {
|
// Ignore early hints "errors" that aren't handled by OkHttp
|
||||||
// Ignore early hints "errors" that aren't handled by OkHttp
|
if (e is HttpException && e.code == 103) return
|
||||||
if (e !is HttpException || e.code != 103) {
|
|
||||||
snackbarHostState.showSnackbar(message = "${e.message}")
|
logcat(LogPriority.ERROR, e)
|
||||||
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.
|
* Requests an updated list of chapters from the source.
|
||||||
*/
|
*/
|
||||||
private suspend fun fetchChaptersFromSource(manualFetch: Boolean = false) {
|
private suspend fun fetchChaptersFromSource(manualFetch: Boolean = false) {
|
||||||
withIOContext {
|
val state = successState ?: return
|
||||||
try {
|
try {
|
||||||
successState?.let { successState ->
|
withIOContext {
|
||||||
val chapters = successState.source.getChapterList(successState.manga.toSManga())
|
val chapters = state.source.getChapterList(state.manga.toSManga())
|
||||||
|
|
||||||
val newChapters = syncChaptersWithSource.await(
|
val newChapters = syncChaptersWithSource.await(
|
||||||
chapters,
|
chapters,
|
||||||
successState.manga,
|
state.manga,
|
||||||
successState.source,
|
state.source,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (manualFetch) {
|
if (manualFetch) {
|
||||||
downloadNewChapters(newChapters)
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue