Fix crash when setting cover errors (closes #7714)
(cherry picked from commit e511f24979b0f40c545345ed151d3557644f79c6) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
This commit is contained in:
parent
a7400df245
commit
4e4e369188
@ -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
|
||||
|
@ -28,7 +28,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
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 exh.favorites.FavoritesIntroDialog
|
||||
@ -276,7 +276,7 @@ class LibraryController(
|
||||
else -> QuadStateTextView.State.UNCHECKED.ordinal
|
||||
}
|
||||
}.toTypedArray()
|
||||
launchUI {
|
||||
withUIContext {
|
||||
ChangeMangaCategoriesDialog(this@LibraryController, mangas.mapNotNull { it.toDomainManga() }, categories, preselected)
|
||||
.showDialog(router)
|
||||
}
|
||||
|
@ -63,7 +63,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
|
||||
@ -673,7 +672,7 @@ class MangaPresenter(
|
||||
if (manga.toDbManga().removeCovers() > 0) {
|
||||
updateManga.awaitUpdateCoverLastModified(manga.id)
|
||||
}
|
||||
launchUI { onRemoved() }
|
||||
withUIContext { onRemoved() }
|
||||
}
|
||||
} else {
|
||||
// Add to library
|
||||
@ -681,7 +680,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
|
||||
}
|
||||
}
|
||||
@ -696,7 +695,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
|
||||
@ -704,11 +703,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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,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
|
||||
@ -785,8 +784,7 @@ class ReaderPresenter(
|
||||
location = Location.Pictures.create(relativePath),
|
||||
),
|
||||
)
|
||||
launchUI {
|
||||
DiskUtil.scanMedia(context, uri)
|
||||
withUIContext {
|
||||
notifier.onComplete(uri)
|
||||
view!!.onSaveImageResult(SaveImageResult.Success(uri))
|
||||
}
|
||||
@ -821,7 +819,7 @@ class ReaderPresenter(
|
||||
location = Location.Pictures.create(relativePath),
|
||||
manga = manga,
|
||||
)
|
||||
launchUI {
|
||||
withUIContext {
|
||||
notifier.onComplete(uri)
|
||||
view!!.onSaveImageResult(SaveImageResult.Success(uri))
|
||||
}
|
||||
@ -891,7 +889,7 @@ class ReaderPresenter(
|
||||
location = Location.Cache,
|
||||
),
|
||||
)
|
||||
launchUI {
|
||||
withUIContext {
|
||||
view!!.onShareImageResult(uri, page)
|
||||
}
|
||||
}
|
||||
@ -920,7 +918,7 @@ class ReaderPresenter(
|
||||
location = Location.Cache,
|
||||
manga = manga,
|
||||
)
|
||||
launchUI {
|
||||
withUIContext {
|
||||
view!!.onShareImageResult(uri, firstPage, secondPage)
|
||||
}
|
||||
}
|
||||
@ -939,20 +937,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…
x
Reference in New Issue
Block a user