mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +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:
		| @@ -99,6 +99,28 @@ data class Manga( | ||||
|         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 { | ||||
|         // Generic filter that does not filter anything | ||||
|         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.util.lang.launchIO | ||||
| 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.system.logcat | ||||
| import kotlinx.coroutines.NonCancellable | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.collectLatest | ||||
| import kotlinx.coroutines.flow.firstOrNull | ||||
| import kotlinx.coroutines.flow.map | ||||
| import kotlinx.coroutines.launch | ||||
| import kotlinx.coroutines.withContext | ||||
| import logcat.LogPriority | ||||
| import uy.kohesive.injekt.Injekt | ||||
| import uy.kohesive.injekt.api.get | ||||
| @@ -212,17 +211,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) | ||||
|             } | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user