Fix crash when setting cover errors (closes #7714)

This commit is contained in:
arkon
2022-08-10 16:11:12 -04:00
parent 22e83f408b
commit e511f24979
8 changed files with 34 additions and 43 deletions
@@ -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
@@ -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<MangaFullCoverDialog.MangaFul
viewScope.launchIO {
try {
val uri = presenter.saveCover(activity, temp = true) ?: return@launchIO
launchUI {
withUIContext {
startActivity(uri.toShareIntent(activity))
}
} catch (e: Throwable) {
launchUI {
withUIContext {
logcat(LogPriority.ERROR, e)
activity.toast(R.string.error_saving_cover)
}
@@ -98,11 +97,11 @@ class MangaFullCoverDialog : FullComposeController<MangaFullCoverDialog.MangaFul
viewScope.launchIO {
try {
presenter.saveCover(activity, temp = false)
launchUI {
withUIContext {
activity.toast(R.string.cover_saved)
}
} catch (e: Throwable) {
launchUI {
withUIContext {
logcat(LogPriority.ERROR, e)
activity.toast(R.string.error_saving_cover)
}
@@ -209,13 +208,12 @@ class MangaFullCoverDialog : FullComposeController<MangaFullCoverDialog.MangaFul
presenterScope.launchIO {
@Suppress("BlockingMethodInNonBlockingContext")
context.contentResolver.openInputStream(data)?.use {
val result = try {
try {
manga.editCover(context, it, updateManga, coverCache)
withUIContext { view?.onSetCoverSuccess() }
} catch (e: Exception) {
view?.onSetCoverError(e)
false
withUIContext { view?.onSetCoverError(e) }
}
withUIContext { if (result) view?.onSetCoverSuccess() }
}
}
}