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>
(cherry picked from commit b04d1e5f50b1a3622e8bfde3ddced7e5a7cd8e2e)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt
This commit is contained in:
AntsyLich 2022-10-01 21:01:25 +06:00 committed by Jobobby04
parent 30e3cc46c8
commit 37fd74f141
5 changed files with 50 additions and 37 deletions

View File

@ -135,6 +135,34 @@ data class Manga(
it.initialized = initialized
}
fun copyFrom(other: SManga): Manga {
// SY -->
val author = other.author ?: ogAuthor
val artist = other.artist ?: ogArtist
val description = other.description ?: ogDescription
val genres = if (other.genre != null) {
other.getGenres()
} else {
ogGenre
}
// SY <--
val thumbnailUrl = other.thumbnail_url ?: thumbnailUrl
return this.copy(
// SY -->
ogAuthor = author,
ogArtist = artist,
ogDescription = description,
ogGenre = genres,
// SY <--
thumbnailUrl = thumbnailUrl,
// SY -->
ogStatus = other.status.toLong(),
// SY <--
updateStrategy = other.update_strategy,
initialized = other.initialized && initialized,
)
}
companion object {
// Generic filter that does not filter anything
const val SHOW_ALL = 0x00000000L

View File

@ -28,18 +28,17 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.logcat
import exh.savedsearches.models.FeedSavedSearch
import exh.savedsearches.models.SavedSearch
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import logcat.LogPriority
@ -286,17 +285,13 @@ open class FeedPresenter(
*/
private suspend fun initializeManga(source: CatalogueSource?, manga: DomainManga) {
if (source == null || manga.thumbnailUrl != null || manga.initialized) return
withContext(NonCancellable) {
val db = manga.toDbManga()
withNonCancellableContext {
try {
val networkManga = source.getMangaDetails(db.copy())
db.copyFrom(networkManga)
db.initialized = true
updateManga.await(
db
.toDomainManga()
?.toMangaUpdate()!!,
)
val networkManga = source.getMangaDetails(manga.toSManga())
val updatedManga = manga.copyFrom(networkManga)
.copy(initialized = true)
updateManga.await(updatedManga.toMangaUpdate())
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}

View File

@ -76,6 +76,7 @@ import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateSectionItem
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.removeCovers
import eu.kanade.tachiyomi.util.system.logcat
@ -83,7 +84,6 @@ import exh.metadata.metadata.base.RaisedSearchMetadata
import exh.savedsearches.models.SavedSearch
import exh.source.getMainSource
import exh.util.nullIfBlank
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.firstOrNull
@ -92,7 +92,6 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@ -300,17 +299,13 @@ open class BrowseSourcePresenter(
*/
private suspend fun initializeManga(manga: DomainManga) {
if (manga.thumbnailUrl != null || manga.initialized) return
withContext(NonCancellable) {
val db = manga.toDbManga()
withNonCancellableContext {
try {
val networkManga = source!!.getMangaDetails(db.copy())
db.copyFrom(networkManga)
db.initialized = true
updateManga.await(
db
.toDomainManga()
?.toMangaUpdate()!!,
)
val networkManga = source!!.getMangaDetails(manga.toSManga())
val updatedManga = manga.copyFrom(networkManga)
.copy(initialized = true)
updateManga.await(updatedManga.toMangaUpdate())
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}

View File

@ -29,15 +29,14 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import exh.savedsearches.models.FeedSavedSearch
import exh.savedsearches.models.SavedSearch
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import logcat.LogPriority
@ -245,17 +244,13 @@ open class SourceFeedPresenter(
*/
private suspend fun initializeManga(manga: DomainManga) {
if (manga.thumbnailUrl != null || manga.initialized) return
withContext(NonCancellable) {
val db = manga.toDbManga()
withNonCancellableContext {
try {
val networkManga = source.getMangaDetails(db.copy())
db.copyFrom(networkManga)
db.initialized = true
updateManga.await(
db
.toDomainManga()
?.toMangaUpdate()!!,
)
val networkManga = source.getMangaDetails(manga.toSManga())
val updatedManga = manga.copyFrom(networkManga)
.copy(initialized = true)
updateManga.await(updatedManga.toMangaUpdate())
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}

View File

@ -89,7 +89,7 @@ suspend fun DomainManga.editCover(
coverCache: CoverCache = Injekt.get(),
) {
if (isLocal()) {
LocalSource.updateCover(context, toDbManga(), stream)
LocalSource.updateCover(context, toSManga(), stream)
updateManga.awaitUpdateCoverLastModified(id)
} else if (favorite) {
coverCache.setCustomCoverToCache(toDbManga(), stream)