Migrate Download to domain model (#8664)
This commit is contained in:
parent
f284a656d7
commit
5f6666a438
7 changed files with 14 additions and 18 deletions
|
@ -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<Download>) {
|
||||
removeFromDownloadQueue(downloads.mapNotNull { it.chapter.toDomainChapter() })
|
||||
removeFromDownloadQueue(downloads.map { it.chapter })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,6 @@ class DownloadItem(
|
|||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return download.chapter.id!!.toInt()
|
||||
return download.chapter.id.toInt()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue