Migrate Download to domain model (#8664)

This commit is contained in:
Two-Ai 2022-12-03 22:30:30 -05:00 committed by GitHub
parent f284a656d7
commit 5f6666a438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 18 deletions

View File

@ -6,7 +6,6 @@ import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.download.service.DownloadPreferences
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R 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.Download
import eu.kanade.tachiyomi.data.download.model.DownloadQueue import eu.kanade.tachiyomi.data.download.model.DownloadQueue
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
@ -221,7 +220,7 @@ class DownloadManager(
} }
fun cancelQueuedDownloads(downloads: List<Download>) { fun cancelQueuedDownloads(downloads: List<Download>) {
removeFromDownloadQueue(downloads.mapNotNull { it.chapter.toDomainChapter() }) removeFromDownloadQueue(downloads.map { it.chapter })
} }
/** /**

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.download
import android.content.Context import android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
import eu.kanade.domain.chapter.interactor.GetChapter 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.interactor.GetManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
@ -78,7 +77,7 @@ class DownloadStore(
* @param download the download. * @param download the download.
*/ */
private fun getKey(download: Download): String { 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) } runBlocking { getManga.await(mangaId) }
} ?: continue } ?: continue
val source = sourceManager.get(manga.source) as? HttpSource ?: 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)) downloads.add(Download(source, manga, chapter))
} }
} }
@ -114,7 +113,7 @@ class DownloadStore(
* @param download the download to serialize. * @param download the download to serialize.
*/ */
private fun serialize(download: Download): String { 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) return json.encodeToString(obj)
} }

View File

@ -4,7 +4,6 @@ import android.content.Context
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import com.jakewharton.rxrelay.PublishRelay import com.jakewharton.rxrelay.PublishRelay
import eu.kanade.domain.chapter.model.Chapter 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.download.service.DownloadPreferences
import eu.kanade.domain.manga.model.COMIC_INFO_FILE import eu.kanade.domain.manga.model.COMIC_INFO_FILE
import eu.kanade.domain.manga.model.ComicInfo import eu.kanade.domain.manga.model.ComicInfo
@ -267,7 +266,7 @@ class Downloader(
// Filter out those already enqueued. // Filter out those already enqueued.
.filter { chapter -> queue.none { it.chapter.id == chapter.id } } .filter { chapter -> queue.none { it.chapter.id == chapter.id } }
// Create a download for each one. // Create a download for each one.
.map { Download(source, manga, it.toDbChapter()) } .map { Download(source, manga, it) }
if (chaptersToQueue.isNotEmpty()) { if (chaptersToQueue.isNotEmpty()) {
queue.addAll(chaptersToQueue) queue.addAll(chaptersToQueue)
@ -322,7 +321,7 @@ class Downloader(
val pageListObservable = if (download.pages == null) { val pageListObservable = if (download.pages == null) {
// Pull page list from network and add them to download object // Pull page list from network and add them to download object
download.source.fetchPageList(download.chapter) download.source.fetchPageList(download.chapter.toSChapter())
.map { pages -> .map { pages ->
if (pages.isEmpty()) { if (pages.isEmpty()) {
throw Exception(context.getString(R.string.page_list_empty_error)) throw Exception(context.getString(R.string.page_list_empty_error))

View File

@ -1,10 +1,9 @@
package eu.kanade.tachiyomi.data.download.model package eu.kanade.tachiyomi.data.download.model
import eu.kanade.domain.chapter.interactor.GetChapter 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.interactor.GetManga
import eu.kanade.domain.manga.model.Manga 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.SourceManager
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
@ -75,7 +74,7 @@ data class Download(
val manga = getManga.await(chapter.mangaId) ?: return null val manga = getManga.await(chapter.mangaId) ?: return null
val source = sourceManager.get(manga.source) as? HttpSource ?: return null val source = sourceManager.get(manga.source) as? HttpSource ?: return null
return Download(source, manga, chapter.toDbChapter()) return Download(source, manga, chapter)
} }
} }
} }

View File

@ -63,6 +63,6 @@ class DownloadItem(
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return download.chapter.id!!.toInt() return download.chapter.id.toInt()
} }
} }

View File

@ -135,7 +135,7 @@ object DownloadQueueScreen : Screen {
text = { Text(text = stringResource(R.string.action_newest)) }, text = { Text(text = stringResource(R.string.action_newest)) },
onClick = { onClick = {
screenModel.reorderQueue( screenModel.reorderQueue(
{ it.download.chapter.date_upload }, { it.download.chapter.dateUpload },
true, true,
) )
closeMenu() closeMenu()
@ -145,7 +145,7 @@ object DownloadQueueScreen : Screen {
text = { Text(text = stringResource(R.string.action_oldest)) }, text = { Text(text = stringResource(R.string.action_oldest)) },
onClick = { onClick = {
screenModel.reorderQueue( screenModel.reorderQueue(
{ it.download.chapter.date_upload }, { it.download.chapter.dateUpload },
false, false,
) )
closeMenu() closeMenu()
@ -160,7 +160,7 @@ object DownloadQueueScreen : Screen {
text = { Text(text = stringResource(R.string.action_asc)) }, text = { Text(text = stringResource(R.string.action_asc)) },
onClick = { onClick = {
screenModel.reorderQueue( screenModel.reorderQueue(
{ it.download.chapter.chapter_number }, { it.download.chapter.chapterNumber },
false, false,
) )
closeMenu() closeMenu()
@ -170,7 +170,7 @@ object DownloadQueueScreen : Screen {
text = { Text(text = stringResource(R.string.action_desc)) }, text = { Text(text = stringResource(R.string.action_desc)) },
onClick = { onClick = {
screenModel.reorderQueue( screenModel.reorderQueue(
{ it.download.chapter.chapter_number }, { it.download.chapter.chapterNumber },
true, true,
) )
closeMenu() closeMenu()

View File

@ -260,6 +260,6 @@ class DownloadQueueScreenModel(
* @return the holder of the download or null if it's not bound. * @return the holder of the download or null if it's not bound.
*/ */
private fun getHolder(download: Download): DownloadHolder? { private fun getHolder(download: Download): DownloadHolder? {
return controllerBinding.recycler.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder return controllerBinding.recycler.findViewHolderForItemId(download.chapter.id) as? DownloadHolder
} }
} }