mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 12:49:19 +01:00
Fix crash when setting cover errors (closes #7714)
This commit is contained in:
parent
22e83f408b
commit
e511f24979
@ -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
|
||||
|
@ -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)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import eu.kanade.tachiyomi.util.chapter.getChapterSort
|
||||
import eu.kanade.tachiyomi.util.editCover
|
||||
import eu.kanade.tachiyomi.util.lang.byteSize
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.lang.takeBytes
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
@ -665,7 +664,7 @@ class ReaderPresenter(
|
||||
location = Location.Pictures.create(relativePath),
|
||||
),
|
||||
)
|
||||
launchUI {
|
||||
withUIContext {
|
||||
notifier.onComplete(uri)
|
||||
view!!.onSaveImageResult(SaveImageResult.Success(uri))
|
||||
}
|
||||
@ -702,7 +701,7 @@ class ReaderPresenter(
|
||||
location = Location.Cache,
|
||||
),
|
||||
)
|
||||
launchUI {
|
||||
withUIContext {
|
||||
view!!.onShareImageResult(uri, page)
|
||||
}
|
||||
}
|
||||
@ -720,20 +719,19 @@ class ReaderPresenter(
|
||||
val stream = page.stream ?: return
|
||||
|
||||
presenterScope.launchIO {
|
||||
val result = try {
|
||||
try {
|
||||
manga.editCover(context, stream())
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
launchUI {
|
||||
val resultResult = if (!result) {
|
||||
SetAsCoverResult.Error
|
||||
} else if (manga.isLocal() || manga.favorite) {
|
||||
SetAsCoverResult.Success
|
||||
} else {
|
||||
SetAsCoverResult.AddToLibraryFirst
|
||||
withUIContext {
|
||||
view?.onSetAsCoverResult(
|
||||
if (manga.isLocal() || manga.favorite) {
|
||||
SetAsCoverResult.Success
|
||||
} else {
|
||||
SetAsCoverResult.AddToLibraryFirst
|
||||
},
|
||||
)
|
||||
}
|
||||
view?.onSetAsCoverResult(resultResult)
|
||||
} catch (e: Exception) {
|
||||
withUIContext { view?.onSetAsCoverResult(SetAsCoverResult.Error) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
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.toDateKey
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
@ -112,7 +112,7 @@ class HistoryPresenter(
|
||||
presenterScope.launchIO {
|
||||
val result = deleteHistoryTable.await()
|
||||
if (!result) return@launchIO
|
||||
launchUI {
|
||||
withUIContext {
|
||||
view?.activity?.toast(R.string.clear_history_completed)
|
||||
}
|
||||
}
|
||||
|
@ -80,15 +80,12 @@ suspend fun DomainManga.editCover(
|
||||
stream: InputStream,
|
||||
updateManga: UpdateManga = Injekt.get(),
|
||||
coverCache: CoverCache = Injekt.get(),
|
||||
): Boolean {
|
||||
return if (isLocal()) {
|
||||
) {
|
||||
if (isLocal()) {
|
||||
LocalSource.updateCover(context, toDbManga(), stream)
|
||||
updateManga.awaitUpdateCoverLastModified(id)
|
||||
} else if (favorite) {
|
||||
coverCache.setCustomCoverToCache(toDbManga(), stream)
|
||||
updateManga.awaitUpdateCoverLastModified(id)
|
||||
} else {
|
||||
// We should never reach this block
|
||||
false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user