mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 18:51:49 +01:00
Reduce some usages of toDbManga
(#8116)
Co-Authored-By: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
parent
98c459a6b6
commit
b04d1e5f50
@ -99,6 +99,28 @@ data class Manga(
|
|||||||
it.initialized = initialized
|
it.initialized = initialized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun copyFrom(other: SManga): Manga {
|
||||||
|
val author = other.author ?: author
|
||||||
|
val artist = other.artist ?: artist
|
||||||
|
val description = other.description ?: description
|
||||||
|
val genres = if (other.genre != null) {
|
||||||
|
other.getGenres()
|
||||||
|
} else {
|
||||||
|
genre
|
||||||
|
}
|
||||||
|
val thumbnailUrl = other.thumbnail_url ?: thumbnailUrl
|
||||||
|
return this.copy(
|
||||||
|
author = author,
|
||||||
|
artist = artist,
|
||||||
|
description = description,
|
||||||
|
genre = genres,
|
||||||
|
thumbnailUrl = thumbnailUrl,
|
||||||
|
status = other.status.toLong(),
|
||||||
|
updateStrategy = other.update_strategy,
|
||||||
|
initialized = other.initialized && initialized,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Generic filter that does not filter anything
|
// Generic filter that does not filter anything
|
||||||
const val SHOW_ALL = 0x00000000L
|
const val SHOW_ALL = 0x00000000L
|
||||||
|
@ -66,15 +66,14 @@ import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateItem
|
|||||||
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateSectionItem
|
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateSectionItem
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
|
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
import eu.kanade.tachiyomi.util.system.logcat
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
import kotlinx.coroutines.NonCancellable
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -212,17 +211,13 @@ open class BrowseSourcePresenter(
|
|||||||
*/
|
*/
|
||||||
private suspend fun initializeManga(manga: DomainManga) {
|
private suspend fun initializeManga(manga: DomainManga) {
|
||||||
if (manga.thumbnailUrl != null || manga.initialized) return
|
if (manga.thumbnailUrl != null || manga.initialized) return
|
||||||
withContext(NonCancellable) {
|
withNonCancellableContext {
|
||||||
val db = manga.toDbManga()
|
|
||||||
try {
|
try {
|
||||||
val networkManga = source!!.getMangaDetails(db.copy())
|
val networkManga = source!!.getMangaDetails(manga.toSManga())
|
||||||
db.copyFrom(networkManga)
|
val updatedManga = manga.copyFrom(networkManga)
|
||||||
db.initialized = true
|
.copy(initialized = true)
|
||||||
updateManga.await(
|
|
||||||
db
|
updateManga.await(updatedManga.toMangaUpdate())
|
||||||
.toDomainManga()
|
|
||||||
?.toMangaUpdate()!!,
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logcat(LogPriority.ERROR, e)
|
logcat(LogPriority.ERROR, e)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ suspend fun DomainManga.editCover(
|
|||||||
coverCache: CoverCache = Injekt.get(),
|
coverCache: CoverCache = Injekt.get(),
|
||||||
) {
|
) {
|
||||||
if (isLocal()) {
|
if (isLocal()) {
|
||||||
LocalSource.updateCover(context, toDbManga(), stream)
|
LocalSource.updateCover(context, toSManga(), stream)
|
||||||
updateManga.awaitUpdateCoverLastModified(id)
|
updateManga.awaitUpdateCoverLastModified(id)
|
||||||
} else if (favorite) {
|
} else if (favorite) {
|
||||||
coverCache.setCustomCoverToCache(toDbManga(), stream)
|
coverCache.setCustomCoverToCache(toDbManga(), stream)
|
||||||
|
Loading…
Reference in New Issue
Block a user