From 5f6666a438a3a58088765aa3813a49f14afcb72c Mon Sep 17 00:00:00 2001 From: Two-Ai <81279822+Two-Ai@users.noreply.github.com> Date: Sat, 3 Dec 2022 22:30:30 -0500 Subject: [PATCH] Migrate Download to domain model (#8664) --- .../eu/kanade/tachiyomi/data/download/DownloadManager.kt | 3 +-- .../eu/kanade/tachiyomi/data/download/DownloadStore.kt | 7 +++---- .../java/eu/kanade/tachiyomi/data/download/Downloader.kt | 5 ++--- .../eu/kanade/tachiyomi/data/download/model/Download.kt | 5 ++--- .../java/eu/kanade/tachiyomi/ui/download/DownloadItem.kt | 2 +- .../kanade/tachiyomi/ui/download/DownloadQueueScreen.kt | 8 ++++---- .../tachiyomi/ui/download/DownloadQueueScreenModel.kt | 2 +- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 646e87228b..10b0ea74d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -6,7 +6,6 @@ import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue import eu.kanade.tachiyomi.source.Source @@ -221,7 +220,7 @@ class DownloadManager( } fun cancelQueuedDownloads(downloads: List) { - removeFromDownloadQueue(downloads.mapNotNull { it.chapter.toDomainChapter() }) + removeFromDownloadQueue(downloads.map { it.chapter }) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt index a275a1d4f9..4d8bf57ca8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadStore.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import androidx.core.content.edit import eu.kanade.domain.chapter.interactor.GetChapter -import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.data.download.model.Download @@ -78,7 +77,7 @@ class DownloadStore( * @param download the download. */ private fun getKey(download: Download): String { - return download.chapter.id!!.toString() + return download.chapter.id.toString() } /** @@ -98,7 +97,7 @@ class DownloadStore( runBlocking { getManga.await(mangaId) } } ?: continue val source = sourceManager.get(manga.source) as? HttpSource ?: continue - val chapter = runBlocking { getChapter.await(chapterId) }?.toDbChapter() ?: continue + val chapter = runBlocking { getChapter.await(chapterId) } ?: continue downloads.add(Download(source, manga, chapter)) } } @@ -114,7 +113,7 @@ class DownloadStore( * @param download the download to serialize. */ private fun serialize(download: Download): String { - val obj = DownloadObject(download.manga.id, download.chapter.id!!, counter++) + val obj = DownloadObject(download.manga.id, download.chapter.id, counter++) return json.encodeToString(obj) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 6207989361..3e591379f9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -4,7 +4,6 @@ import android.content.Context import com.hippo.unifile.UniFile import com.jakewharton.rxrelay.PublishRelay import eu.kanade.domain.chapter.model.Chapter -import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.manga.model.COMIC_INFO_FILE import eu.kanade.domain.manga.model.ComicInfo @@ -267,7 +266,7 @@ class Downloader( // Filter out those already enqueued. .filter { chapter -> queue.none { it.chapter.id == chapter.id } } // Create a download for each one. - .map { Download(source, manga, it.toDbChapter()) } + .map { Download(source, manga, it) } if (chaptersToQueue.isNotEmpty()) { queue.addAll(chaptersToQueue) @@ -322,7 +321,7 @@ class Downloader( val pageListObservable = if (download.pages == null) { // Pull page list from network and add them to download object - download.source.fetchPageList(download.chapter) + download.source.fetchPageList(download.chapter.toSChapter()) .map { pages -> if (pages.isEmpty()) { throw Exception(context.getString(R.string.page_list_empty_error)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt index d632bafc41..7dff294b96 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/Download.kt @@ -1,10 +1,9 @@ package eu.kanade.tachiyomi.data.download.model import eu.kanade.domain.chapter.interactor.GetChapter -import eu.kanade.domain.chapter.model.toDbChapter +import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.model.Manga -import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource @@ -75,7 +74,7 @@ data class Download( val manga = getManga.await(chapter.mangaId) ?: return null val source = sourceManager.get(manga.source) as? HttpSource ?: return null - return Download(source, manga, chapter.toDbChapter()) + return Download(source, manga, chapter) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadItem.kt index 783ec061fb..6dd4f9b251 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadItem.kt @@ -63,6 +63,6 @@ class DownloadItem( } override fun hashCode(): Int { - return download.chapter.id!!.toInt() + return download.chapter.id.toInt() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt index 0f68c1fe3c..37584ee4e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt @@ -135,7 +135,7 @@ object DownloadQueueScreen : Screen { text = { Text(text = stringResource(R.string.action_newest)) }, onClick = { screenModel.reorderQueue( - { it.download.chapter.date_upload }, + { it.download.chapter.dateUpload }, true, ) closeMenu() @@ -145,7 +145,7 @@ object DownloadQueueScreen : Screen { text = { Text(text = stringResource(R.string.action_oldest)) }, onClick = { screenModel.reorderQueue( - { it.download.chapter.date_upload }, + { it.download.chapter.dateUpload }, false, ) closeMenu() @@ -160,7 +160,7 @@ object DownloadQueueScreen : Screen { text = { Text(text = stringResource(R.string.action_asc)) }, onClick = { screenModel.reorderQueue( - { it.download.chapter.chapter_number }, + { it.download.chapter.chapterNumber }, false, ) closeMenu() @@ -170,7 +170,7 @@ object DownloadQueueScreen : Screen { text = { Text(text = stringResource(R.string.action_desc)) }, onClick = { screenModel.reorderQueue( - { it.download.chapter.chapter_number }, + { it.download.chapter.chapterNumber }, true, ) closeMenu() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreenModel.kt index 17a1d1d635..750566943f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreenModel.kt @@ -260,6 +260,6 @@ class DownloadQueueScreenModel( * @return the holder of the download or null if it's not bound. */ private fun getHolder(download: Download): DownloadHolder? { - return controllerBinding.recycler.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder + return controllerBinding.recycler.findViewHolderForItemId(download.chapter.id) as? DownloadHolder } }