From e36e9d9d5c1b2a7b55f28f2bf0ef064880cbac8f Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Fri, 19 Aug 2022 02:07:13 +0800 Subject: [PATCH] Remove 1.x source models (#7781) --- app/build.gradle.kts | 3 - .../domain/manga/interactor/UpdateManga.kt | 16 ++-- .../eu/kanade/domain/manga/model/Manga.kt | 12 --- .../tachiyomi/data/database/models/Manga.kt | 14 ---- .../data/library/LibraryUpdateService.kt | 46 ++++------- .../eu/kanade/tachiyomi/source/LocalSource.kt | 79 ++++++++----------- .../java/eu/kanade/tachiyomi/source/Source.kt | 32 +++----- .../kanade/tachiyomi/source/SourceManager.kt | 8 +- .../eu/kanade/tachiyomi/source/model/Page.kt | 14 ---- .../kanade/tachiyomi/source/model/SChapter.kt | 22 ------ .../kanade/tachiyomi/source/model/SManga.kt | 40 +++------- .../migration/search/SearchPresenter.kt | 5 +- .../source/browse/BrowseSourcePresenter.kt | 6 +- .../globalsearch/GlobalSearchPresenter.kt | 6 +- .../tachiyomi/ui/manga/MangaPresenter.kt | 7 +- .../kanade/tachiyomi/util/MangaExtensions.kt | 5 +- gradle/libs.versions.toml | 2 - 17 files changed, 92 insertions(+), 225 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8f96c3977..b02d075ba 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -177,9 +177,6 @@ dependencies { implementation(kotlinx.reflect) implementation(kotlinx.bundles.coroutines) - // Source models and interfaces from Tachiyomi 1.x - implementation(libs.tachiyomi.api) - // AndroidX libraries implementation(androidx.annotation) implementation(androidx.appcompat) diff --git a/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt b/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt index 329359253..220b27e94 100644 --- a/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt @@ -7,7 +7,7 @@ import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.repository.MangaRepository import eu.kanade.tachiyomi.data.cache.CoverCache -import tachiyomi.source.model.MangaInfo +import eu.kanade.tachiyomi.source.model.SManga import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.Date @@ -26,17 +26,18 @@ class UpdateManga( suspend fun awaitUpdateFromSource( localManga: Manga, - remoteManga: MangaInfo, + remoteManga: SManga, manualFetch: Boolean, coverCache: CoverCache = Injekt.get(), ): Boolean { // if the manga isn't a favorite, set its title from source and update in db val title = if (!localManga.favorite) remoteManga.title else null - // Never refresh covers if the url is empty to avoid "losing" existing covers - val updateCover = remoteManga.cover.isNotEmpty() && (manualFetch || localManga.thumbnailUrl != remoteManga.cover) - val coverLastModified = if (updateCover) { + val coverLastModified = when { + // Never refresh covers if the url is empty to avoid "losing" existing covers + remoteManga.thumbnail_url.isNullOrEmpty() -> null + !manualFetch && localManga.thumbnailUrl == remoteManga.thumbnail_url -> null localManga.isLocal() -> Date().time localManga.hasCustomCover(coverCache) -> { coverCache.deleteFromCache(localManga.toDbManga(), false) @@ -47,7 +48,6 @@ class UpdateManga( Date().time } } - } else null return mangaRepository.update( MangaUpdate( @@ -57,8 +57,8 @@ class UpdateManga( author = remoteManga.author, artist = remoteManga.artist, description = remoteManga.description, - genre = remoteManga.genres, - thumbnailUrl = remoteManga.cover.takeIf { it.isNotEmpty() }, + genre = remoteManga.getGenres(), + thumbnailUrl = remoteManga.thumbnail_url?.takeIf { it.isNotEmpty() }, status = remoteManga.status.toLong(), initialized = true, ), diff --git a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt index a084d1471..aba7e14b7 100644 --- a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt @@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.widget.ExtendedNavigationView -import tachiyomi.source.model.MangaInfo import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.Serializable @@ -184,17 +183,6 @@ fun Manga.toDbManga(): DbManga = MangaImpl().also { it.initialized = initialized } -fun Manga.toMangaInfo(): MangaInfo = MangaInfo( - artist = artist ?: "", - author = author ?: "", - cover = thumbnailUrl ?: "", - description = description ?: "", - genres = genre ?: emptyList(), - key = url, - status = status.toInt(), - title = title, -) - fun Manga.toMangaUpdate(): MangaUpdate { return MangaUpdate( id = id, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 8b6b9900e..4d19bfe91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.database.models import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType -import tachiyomi.source.model.MangaInfo import eu.kanade.domain.manga.model.Manga as DomainManga interface Manga : SManga { @@ -75,19 +74,6 @@ interface Manga : SManga { } } -fun Manga.toMangaInfo(): MangaInfo { - return MangaInfo( - artist = this.artist ?: "", - author = this.author ?: "", - cover = this.thumbnail_url ?: "", - description = this.description ?: "", - genres = this.getGenres() ?: emptyList(), - key = this.url, - status = this.status, - title = this.title, - ) -} - fun Manga.toDomainManga(): DomainManga? { val mangaId = id ?: return null return DomainManga( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 849d5ab5f..6c80f1f70 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -16,7 +16,6 @@ import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.GetLibraryManga import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.UpdateManga -import eu.kanade.domain.manga.model.toMangaInfo import eu.kanade.domain.manga.model.toMangaUpdate import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack @@ -29,7 +28,6 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.database.models.toDomainManga -import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start @@ -44,8 +42,6 @@ import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.UnmeteredSource import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toSChapter -import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.util.lang.withIOContext import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.shouldDownloadNewChapters @@ -69,7 +65,6 @@ import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit import logcat.LogPriority -import tachiyomi.source.model.MangaInfo import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File @@ -428,16 +423,13 @@ class LibraryUpdateService( private suspend fun updateManga(manga: DomainManga): List { val source = sourceManager.getOrStub(manga.source) - val mangaInfo: MangaInfo = manga.toMangaInfo() - // Update manga metadata if needed if (preferences.autoUpdateMetadata()) { - val updatedMangaInfo = source.getMangaDetails(manga.toMangaInfo()) - updateManga.awaitUpdateFromSource(manga, updatedMangaInfo, manualFetch = false, coverCache) + val networkManga = source.getMangaDetails(manga.toSManga()) + updateManga.awaitUpdateFromSource(manga, networkManga, manualFetch = false, coverCache) } - val chapters = source.getChapterList(mangaInfo) - .map { it.toSChapter() } + val chapters = source.getChapterList(manga.toSManga()) // Get manga from database to account for if it was removed during the update val dbManga = getManga.await(manga.id) @@ -469,27 +461,19 @@ class LibraryUpdateService( progressCount, manga, ) { mangaWithNotif -> - sourceManager.get(mangaWithNotif.source)?.let { source -> + val source = sourceManager.get(mangaWithNotif.source) ?: return@withUpdateNotification + try { + val networkManga = source.getMangaDetails(mangaWithNotif.copy()) + mangaWithNotif.prepUpdateCover(coverCache, networkManga, true) + mangaWithNotif.copyFrom(networkManga) try { - val networkManga = - source.getMangaDetails(mangaWithNotif.toMangaInfo()) - val sManga = networkManga.toSManga() - mangaWithNotif.prepUpdateCover(coverCache, sManga, true) - sManga.thumbnail_url?.let { - mangaWithNotif.thumbnail_url = it - try { - updateManga.await( - mangaWithNotif.toDomainManga()!! - .toMangaUpdate(), - ) - } catch (e: Exception) { - logcat(LogPriority.ERROR) { "Manga don't exist anymore" } - } - } - } catch (e: Throwable) { - // Ignore errors and continue - logcat(LogPriority.ERROR, e) + updateManga.await(mangaWithNotif.toDomainManga()!!.toMangaUpdate()) + } catch (e: Exception) { + logcat(LogPriority.ERROR) { "Manga doesn't exist anymore" } } + } catch (e: Throwable) { + // Ignore errors and continue + logcat(LogPriority.ERROR, e) } } } @@ -574,7 +558,7 @@ class LibraryUpdateService( } updatingManga.remove(manga) - completed.andIncrement + completed.getAndIncrement() notifier.showProgressNotification( updatingManga.map { it.toDomainManga()!! }, completed.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 75c472069..45ad25381 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -9,10 +9,6 @@ import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toChapterInfo -import eu.kanade.tachiyomi.source.model.toMangaInfo -import eu.kanade.tachiyomi.source.model.toSChapter -import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.util.chapter.ChapterRecognition import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder import eu.kanade.tachiyomi.util.storage.DiskUtil @@ -20,17 +16,11 @@ import eu.kanade.tachiyomi.util.storage.EpubFile import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.runBlocking +import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.decodeFromStream -import kotlinx.serialization.json.intOrNull -import kotlinx.serialization.json.jsonArray -import kotlinx.serialization.json.jsonPrimitive import logcat.LogPriority import rx.Observable -import tachiyomi.source.model.ChapterInfo -import tachiyomi.source.model.MangaInfo import uy.kohesive.injekt.injectLazy import java.io.File import java.io.FileInputStream @@ -120,11 +110,10 @@ class LocalSource( // Fetch chapters of all the manga mangas.forEach { manga -> - val mangaInfo = manga.toMangaInfo() runBlocking { - val chapters = getChapterList(mangaInfo) + val chapters = getChapterList(manga) if (chapters.isNotEmpty()) { - val chapter = chapters.last().toSChapter() + val chapter = chapters.last() val format = getFormat(chapter) if (format is Format.Epub) { @@ -145,47 +134,48 @@ class LocalSource( } // Manga details related - override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo { - var mangaInfo = manga - + override suspend fun getMangaDetails(manga: SManga): SManga { val baseDirsFile = getBaseDirectoriesFiles(context) - val coverFile = getCoverFile(manga.key, baseDirsFile) - - coverFile?.let { - mangaInfo = mangaInfo.copy(cover = it.absolutePath) + getCoverFile(manga.url, baseDirsFile)?.let { + manga.thumbnail_url = it.absolutePath } - val localDetails = getMangaDirsFiles(manga.key, baseDirsFile) + getMangaDirsFiles(manga.url, baseDirsFile) .firstOrNull { it.extension.equals("json", ignoreCase = true) } + ?.let { file -> + json.decodeFromStream(file.inputStream()).run { + title?.let { manga.title = it } + author?.let { manga.author = it } + artist?.let { manga.artist = it } + description?.let { manga.description = it } + genre?.let { manga.genre = it.joinToString() } + status?.let { manga.status = it } + } + } - if (localDetails != null) { - val obj = json.decodeFromStream(localDetails.inputStream()) - - mangaInfo = mangaInfo.copy( - title = obj["title"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.title, - author = obj["author"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.author, - artist = obj["artist"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.artist, - description = obj["description"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.description, - genres = obj["genre"]?.jsonArray?.map { it.jsonPrimitive.content } ?: mangaInfo.genres, - status = obj["status"]?.jsonPrimitive?.intOrNull ?: mangaInfo.status, - ) - } - - return mangaInfo + return manga } - // Chapters - override suspend fun getChapterList(manga: MangaInfo): List { - val sManga = manga.toSManga() + @Serializable + class MangaDetails( + val title: String? = null, + val author: String? = null, + val artist: String? = null, + val description: String? = null, + val genre: List? = null, + val status: Int? = null, + ) + // Chapters + override suspend fun getChapterList(manga: SManga): List { val baseDirsFile = getBaseDirectoriesFiles(context) - return getMangaDirsFiles(manga.key, baseDirsFile) + return getMangaDirsFiles(manga.url, baseDirsFile) // Only keep supported formats .filter { it.isDirectory || isSupportedFile(it.extension) } .map { chapterFile -> SChapter.create().apply { - url = "${manga.key}/${chapterFile.name}" + url = "${manga.url}/${chapterFile.name}" name = if (chapterFile.isDirectory) { chapterFile.name } else { @@ -193,7 +183,7 @@ class LocalSource( } date_upload = chapterFile.lastModified() - chapter_number = ChapterRecognition.parseChapterNumber(sManga.title, this.name, this.chapter_number) + chapter_number = ChapterRecognition.parseChapterNumber(manga.title, this.name, this.chapter_number) val format = getFormat(chapterFile) if (format is Format.Epub) { @@ -203,9 +193,8 @@ class LocalSource( } } } - .map { it.toChapterInfo() } .sortedWith { c1, c2 -> - val c = c2.number.compareTo(c1.number) + val c = c2.chapter_number.compareTo(c1.chapter_number) if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c } .toList() @@ -224,7 +213,7 @@ class LocalSource( ) // Unused stuff - override suspend fun getPageList(chapter: ChapterInfo) = throw UnsupportedOperationException("Unused") + override suspend fun getPageList(chapter: SChapter) = throw UnsupportedOperationException("Unused") // Miscellaneous private fun isSupportedFile(extension: String): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt index d71dd05bb..fe5e1019f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt @@ -7,34 +7,27 @@ import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toChapterInfo -import eu.kanade.tachiyomi.source.model.toMangaInfo -import eu.kanade.tachiyomi.source.model.toPageUrl -import eu.kanade.tachiyomi.source.model.toSChapter -import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.util.lang.awaitSingle import rx.Observable -import tachiyomi.source.model.ChapterInfo -import tachiyomi.source.model.MangaInfo import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get /** * A basic interface for creating a source. It could be an online source, a local source, etc... */ -interface Source : tachiyomi.source.Source { +interface Source { /** * Id for the source. Must be unique. */ - override val id: Long + val id: Long /** * Name of the source. */ - override val name: String + val name: String - override val lang: String + val lang: String get() = "" /** @@ -75,29 +68,24 @@ interface Source : tachiyomi.source.Source { * [1.x API] Get the updated details for a manga. */ @Suppress("DEPRECATION") - override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo { - val sManga = manga.toSManga() - val networkManga = fetchMangaDetails(sManga).awaitSingle() - sManga.copyFrom(networkManga) - return sManga.toMangaInfo() + suspend fun getMangaDetails(manga: SManga): SManga { + return fetchMangaDetails(manga).awaitSingle() } /** * [1.x API] Get all the available chapters for a manga. */ @Suppress("DEPRECATION") - override suspend fun getChapterList(manga: MangaInfo): List { - return fetchChapterList(manga.toSManga()).awaitSingle() - .map { it.toChapterInfo() } + suspend fun getChapterList(manga: SManga): List { + return fetchChapterList(manga).awaitSingle() } /** * [1.x API] Get the list of pages a chapter has. */ @Suppress("DEPRECATION") - override suspend fun getPageList(chapter: ChapterInfo): List { - return fetchPageList(chapter.toSChapter()).awaitSingle() - .map { it.toPageUrl() } + suspend fun getPageList(chapter: SChapter): List { + return fetchPageList(chapter).awaitSingle() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt index c528ae1c4..4828d9e72 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt @@ -19,8 +19,6 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import rx.Observable -import tachiyomi.source.model.ChapterInfo -import tachiyomi.source.model.MangaInfo class SourceManager( private val context: Context, @@ -115,7 +113,7 @@ class SourceManager( override val lang: String = sourceData.lang - override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo { + override suspend fun getMangaDetails(manga: SManga): SManga { throw getSourceNotInstalledException() } @@ -123,7 +121,7 @@ class SourceManager( return Observable.error(getSourceNotInstalledException()) } - override suspend fun getChapterList(manga: MangaInfo): List { + override suspend fun getChapterList(manga: SManga): List { throw getSourceNotInstalledException() } @@ -131,7 +129,7 @@ class SourceManager( return Observable.error(getSourceNotInstalledException()) } - override suspend fun getPageList(chapter: ChapterInfo): List { + override suspend fun getPageList(chapter: SChapter): List { throw getSourceNotInstalledException() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt index c6b46dde2..be5ab89d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt @@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.network.ProgressListener import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import rx.subjects.Subject -import tachiyomi.source.model.PageUrl @Serializable open class Page( @@ -65,16 +64,3 @@ open class Page( const val ERROR = 4 } } - -fun Page.toPageUrl(): PageUrl { - return PageUrl( - url = this.imageUrl ?: this.url, - ) -} - -fun PageUrl.toPage(index: Int): Page { - return Page( - index = index, - imageUrl = this.url, - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt index 62fc1f9d1..572d7020e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.source.model import data.Chapters -import tachiyomi.source.model.ChapterInfo import java.io.Serializable interface SChapter : Serializable { @@ -38,24 +37,3 @@ interface SChapter : Serializable { } } } - -fun SChapter.toChapterInfo(): ChapterInfo { - return ChapterInfo( - dateUpload = this.date_upload, - key = this.url, - name = this.name, - number = this.chapter_number, - scanlator = this.scanlator ?: "", - ) -} - -fun ChapterInfo.toSChapter(): SChapter { - val chapter = this - return SChapter.create().apply { - url = chapter.key - name = chapter.name - date_upload = chapter.dateUpload - chapter_number = chapter.number - scanlator = chapter.scanlator - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt index 8b4477b68..824e0e2ca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.source.model import data.Mangas -import tachiyomi.source.model.MangaInfo import java.io.Serializable interface SManga : Serializable { @@ -85,6 +84,18 @@ interface SManga : Serializable { } } + fun copy() = create().also { + it.url = url + it.title = title + it.artist = artist + it.author = author + it.description = description + it.genre = genre + it.status = status + it.thumbnail_url = thumbnail_url + it.initialized = initialized + } + companion object { const val UNKNOWN = 0 const val ONGOING = 1 @@ -99,30 +110,3 @@ interface SManga : Serializable { } } } - -fun SManga.toMangaInfo(): MangaInfo { - return MangaInfo( - key = this.url, - title = this.title, - artist = this.artist ?: "", - author = this.author ?: "", - description = this.description ?: "", - genres = this.getGenres() ?: emptyList(), - status = this.status, - cover = this.thumbnail_url ?: "", - ) -} - -fun MangaInfo.toSManga(): SManga { - val mangaInfo = this - return SManga.create().apply { - url = mangaInfo.key - title = mangaInfo.title - artist = mangaInfo.artist - author = mangaInfo.author - description = mangaInfo.description - genre = mangaInfo.genres.joinToString(", ") - status = mangaInfo.status - thumbnail_url = mangaInfo.cover - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index d803eb40a..6a7c60395 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -13,7 +13,6 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.MangaUpdate import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.toDbManga -import eu.kanade.domain.manga.model.toMangaInfo import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.tachiyomi.data.cache.CoverCache @@ -23,7 +22,6 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem @@ -89,8 +87,7 @@ class SearchPresenter( presenterScope.launchIO { try { - val chapters = source.getChapterList(manga.toMangaInfo()) - .map { it.toSChapter() } + val chapters = source.getChapterList(manga.toSManga()) migrateMangaInternal(prevSource, source, chapters, prevManga, manga, replace) } catch (e: Throwable) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index 913749de6..b4cc39fe9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -17,7 +17,6 @@ import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga -import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager @@ -27,7 +26,6 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.browse.source.filter.CheckboxItem import eu.kanade.tachiyomi.ui.browse.source.filter.CheckboxSectionItem @@ -267,8 +265,8 @@ open class BrowseSourcePresenter( */ private suspend fun getMangaDetails(manga: Manga): Manga { try { - val networkManga = source.getMangaDetails(manga.toMangaInfo()) - manga.copyFrom(networkManga.toSManga()) + val networkManga = source.getMangaDetails(manga.copy()) + manga.copyFrom(networkManga) manga.initialized = true updateManga.await( manga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index 280b4f7fe..65ae91213 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -8,7 +8,6 @@ import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.model.toMangaUpdate import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga -import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.CatalogueSource @@ -16,7 +15,6 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter import eu.kanade.tachiyomi.util.lang.runAsObservable @@ -245,8 +243,8 @@ open class GlobalSearchPresenter( * @return The initialized manga. */ private suspend fun getMangaDetails(manga: Manga, source: Source): Manga { - val networkManga = source.getMangaDetails(manga.toMangaInfo()) - manga.copyFrom(networkManga.toSManga()) + val networkManga = source.getMangaDetails(manga.copy()) + manga.copyFrom(networkManga) manga.initialized = true updateManga.await(manga.toDomainManga()!!.toMangaUpdate()) return manga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 6ed4eed0d..2e3ff998a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -20,7 +20,6 @@ import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.TriStateFilter import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.toDbManga -import eu.kanade.domain.manga.model.toMangaInfo import eu.kanade.domain.track.interactor.DeleteTrack import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack @@ -36,7 +35,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager -import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.manga.track.TrackItem import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper @@ -245,7 +243,7 @@ class MangaPresenter( updateSuccessState { it.copy(isRefreshingInfo = true) } try { successState?.let { - val networkManga = it.source.getMangaDetails(it.manga.toMangaInfo()) + val networkManga = it.source.getMangaDetails(it.manga.toSManga()) updateManga.awaitUpdateFromSource(it.manga, networkManga, manualFetch) } } catch (e: Throwable) { @@ -518,8 +516,7 @@ class MangaPresenter( updateSuccessState { it.copy(isRefreshingChapter = true) } try { successState?.let { successState -> - val chapters = successState.source.getChapterList(successState.manga.toMangaInfo()) - .map { it.toSChapter() } + val chapters = successState.source.getChapterList(successState.manga.toSManga()) val newChapters = syncChaptersWithSource.await( chapters, diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt index f544f783d..76089f437 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt @@ -29,11 +29,12 @@ fun Manga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSa if (!refreshSameUrl && thumbnail_url == newUrl) return + val domainManga = toDomainManga()!! when { - toDomainManga()!!.isLocal() -> { + domainManga.isLocal() -> { cover_last_modified = Date().time } - toDomainManga()!!.hasCustomCover(coverCache) -> { + domainManga.hasCustomCover(coverCache) -> { coverCache.deleteFromCache(this, false) } else -> { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c5d46d88b..37a57e188 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,8 +13,6 @@ leakcanary = "2.9.1" android-shortcut-gradle = "com.github.zellius:android-shortcut-gradle-plugin:0.1.2" google-services-gradle = "com.google.gms:google-services:4.3.13" -tachiyomi-api = "org.tachiyomi:source-api:1.1" - rxandroid = "io.reactivex:rxandroid:1.2.1" rxjava = "io.reactivex:rxjava:1.3.8" rxrelay = "com.jakewharton.rxrelay:rxrelay:1.2.0"