More domain model usage
This commit is contained in:
parent
3791d82540
commit
a3378e6080
@ -7,7 +7,6 @@ import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.domain.chapter.repository.ChapterRepository
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
@ -97,7 +96,7 @@ class SyncChaptersWithSource(
|
||||
} else {
|
||||
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
||||
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source)) {
|
||||
downloadManager.renameChapter(source, manga.toDbManga(), dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
}
|
||||
var toChangeChapter = dbChapter.copy(
|
||||
name = chapter.name,
|
||||
|
@ -42,8 +42,7 @@ data class Chapter(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(): Chapter {
|
||||
return Chapter(
|
||||
fun create() = Chapter(
|
||||
id = -1,
|
||||
mangaId = -1,
|
||||
read = false,
|
||||
@ -59,7 +58,6 @@ data class Chapter(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove when all deps are migrated
|
||||
fun Chapter.toDbChapter(): DbChapter = ChapterImpl().also {
|
||||
|
@ -33,20 +33,6 @@ data class Manga(
|
||||
val initialized: Boolean,
|
||||
) : Serializable {
|
||||
|
||||
fun toSManga(): SManga {
|
||||
return SManga.create().also {
|
||||
it.url = url
|
||||
it.title = title
|
||||
it.artist = artist
|
||||
it.author = author
|
||||
it.description = description
|
||||
it.genre = genre.orEmpty().joinToString()
|
||||
it.status = status.toInt()
|
||||
it.thumbnail_url = thumbnailUrl
|
||||
it.initialized = initialized
|
||||
}
|
||||
}
|
||||
|
||||
val sorting: Long
|
||||
get() = chapterFlags and CHAPTER_SORTING_MASK
|
||||
|
||||
@ -100,6 +86,18 @@ data class Manga(
|
||||
return chapterFlags and CHAPTER_SORT_DIR_MASK == CHAPTER_SORT_DESC
|
||||
}
|
||||
|
||||
fun toSManga(): SManga = SManga.create().also {
|
||||
it.url = url
|
||||
it.title = title
|
||||
it.artist = artist
|
||||
it.author = author
|
||||
it.description = description
|
||||
it.genre = genre.orEmpty().joinToString()
|
||||
it.status = status.toInt()
|
||||
it.thumbnail_url = thumbnailUrl
|
||||
it.initialized = initialized
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Generic filter that does not filter anything
|
||||
const val SHOW_ALL = 0x00000000L
|
||||
@ -128,6 +126,26 @@ data class Manga(
|
||||
const val CHAPTER_DISPLAY_NAME = 0x00000000L
|
||||
const val CHAPTER_DISPLAY_NUMBER = 0x00100000L
|
||||
const val CHAPTER_DISPLAY_MASK = 0x00100000L
|
||||
|
||||
fun create() = Manga(
|
||||
id = -1L,
|
||||
url = "",
|
||||
title = "",
|
||||
source = -1L,
|
||||
favorite = false,
|
||||
lastUpdate = -1L,
|
||||
dateAdded = -1L,
|
||||
viewerFlags = -1L,
|
||||
chapterFlags = -1L,
|
||||
coverLastModified = -1L,
|
||||
artist = null,
|
||||
author = null,
|
||||
description = null,
|
||||
genre = null,
|
||||
status = 0L,
|
||||
thumbnailUrl = null,
|
||||
initialized = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.data.download
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
@ -4,9 +4,9 @@ import android.content.Context
|
||||
import com.hippo.unifile.UniFile
|
||||
import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import eu.kanade.domain.category.interactor.GetCategories
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.data.download
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
@ -155,7 +155,7 @@ class DownloadPendingDeleter(context: Context) {
|
||||
* Returns a manga entry from a manga model.
|
||||
*/
|
||||
private fun Manga.toEntry(): MangaEntry {
|
||||
return MangaEntry(id!!, url, title, source)
|
||||
return MangaEntry(id, url, title, source)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,9 +169,12 @@ class DownloadPendingDeleter(context: Context) {
|
||||
* Returns a manga model from a manga entry.
|
||||
*/
|
||||
private fun MangaEntry.toModel(): Manga {
|
||||
return Manga.create(url, title, source).also {
|
||||
it.id = id
|
||||
}
|
||||
return Manga.create().copy(
|
||||
url = url,
|
||||
title = title,
|
||||
source = source,
|
||||
id = id,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.data.download
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
|
@ -5,8 +5,7 @@ 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.toDbManga
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
@ -96,7 +95,7 @@ class DownloadStore(
|
||||
val cachedManga = mutableMapOf<Long, Manga?>()
|
||||
for ((mangaId, chapterId) in objs) {
|
||||
val manga = cachedManga.getOrPut(mangaId) {
|
||||
runBlocking { getManga.await(mangaId)?.toDbManga() }
|
||||
runBlocking { getManga.await(mangaId) }
|
||||
} ?: continue
|
||||
val source = sourceManager.get(manga.source) as? HttpSource ?: continue
|
||||
val chapter = runBlocking { getChapter.await(chapterId) }?.toDbChapter() ?: continue
|
||||
|
@ -5,10 +5,10 @@ import android.webkit.MimeTypeMap
|
||||
import com.hippo.unifile.UniFile
|
||||
import com.jakewharton.rxrelay.BehaviorRelay
|
||||
import com.jakewharton.rxrelay.PublishRelay
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
|
||||
|
@ -3,9 +3,8 @@ 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.manga.interactor.GetManga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
@ -76,7 +75,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.toDbManga(), chapter.toDbChapter())
|
||||
return Download(source, manga, chapter.toDbChapter())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package eu.kanade.tachiyomi.data.download.model
|
||||
|
||||
import com.jakewharton.rxrelay.PublishRelay
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadStore
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import rx.Observable
|
||||
|
@ -416,7 +416,7 @@ class LibraryUpdateService(
|
||||
private fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
// We don't want to start downloading while the library is updating, because websites
|
||||
// may don't like it and they could ban the user.
|
||||
downloadManager.downloadChapters(manga, chapters, false)
|
||||
downloadManager.downloadChapters(manga.toDomainManga()!!, chapters, false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,6 @@ import eu.kanade.domain.chapter.model.toChapterUpdate
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.domain.manga.interactor.GetManga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreService
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
@ -252,7 +251,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
if (manga != null) {
|
||||
val source = sourceManager.get(manga.source)
|
||||
if (source != null) {
|
||||
downloadManager.deleteChapters(listOf(it.toDbChapter()), manga.toDbManga(), source)
|
||||
downloadManager.deleteChapters(listOf(it.toDbChapter()), manga, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -270,7 +269,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
*/
|
||||
private fun downloadChapters(chapterUrls: Array<String>, mangaId: Long) {
|
||||
launchIO {
|
||||
val manga = getManga.await(mangaId)?.toDbManga()
|
||||
val manga = getManga.await(mangaId)
|
||||
val chapters = chapterUrls.mapNotNull { getChapter.await(it, mangaId)?.toDbChapter() }
|
||||
if (manga != null && chapters.isNotEmpty()) {
|
||||
downloadManager.downloadChapters(manga, chapters)
|
||||
|
@ -17,7 +17,6 @@ import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.MangaUpdate
|
||||
import eu.kanade.domain.manga.model.isLocal
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.domain.track.interactor.GetTracks
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainManga
|
||||
@ -154,7 +153,7 @@ class LibraryPresenter(
|
||||
val isDownloaded = when {
|
||||
item.manga.toDomainManga()!!.isLocal() -> true
|
||||
item.downloadCount != -1 -> item.downloadCount > 0
|
||||
else -> downloadManager.getDownloadCount(item.manga) > 0
|
||||
else -> downloadManager.getDownloadCount(item.manga.toDomainManga()!!) > 0
|
||||
}
|
||||
|
||||
return@downloaded if (downloadedOnly || filterDownloaded == State.INCLUDE.value) isDownloaded
|
||||
@ -236,7 +235,7 @@ class LibraryPresenter(
|
||||
for ((_, itemList) in map) {
|
||||
for (item in itemList) {
|
||||
item.downloadCount = if (showDownloadBadges) {
|
||||
downloadManager.getDownloadCount(item.manga)
|
||||
downloadManager.getDownloadCount(item.manga.toDomainManga()!!)
|
||||
} else {
|
||||
// Unset download count if not enabled
|
||||
-1
|
||||
@ -521,7 +520,7 @@ class LibraryPresenter(
|
||||
.filter { !it.read }
|
||||
.map { it.toDbChapter() }
|
||||
|
||||
downloadManager.downloadChapters(manga.toDbManga(), chapters)
|
||||
downloadManager.downloadChapters(manga, chapters)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -555,7 +554,7 @@ class LibraryPresenter(
|
||||
|
||||
private fun deleteChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
sourceManager.get(manga.source)?.let { source ->
|
||||
downloadManager.deleteChapters(chapters.map { it.toDbChapter() }, manga.toDbManga(), source)
|
||||
downloadManager.deleteChapters(chapters.map { it.toDbChapter() }, manga, source)
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,7 +584,7 @@ class LibraryPresenter(
|
||||
mangaToDelete.forEach { manga ->
|
||||
val source = sourceManager.get(manga.source) as? HttpSource
|
||||
if (source != null) {
|
||||
downloadManager.deleteManga(manga, source)
|
||||
downloadManager.deleteManga(manga.toDomainManga()!!, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ class MangaPresenter(
|
||||
*/
|
||||
fun hasDownloads(): Boolean {
|
||||
val manga = successState?.manga ?: return false
|
||||
return downloadManager.getDownloadCount(manga.toDbManga()) > 0
|
||||
return downloadManager.getDownloadCount(manga) > 0
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,7 +313,7 @@ class MangaPresenter(
|
||||
*/
|
||||
fun deleteDownloads() {
|
||||
val state = successState ?: return
|
||||
downloadManager.deleteManga(state.manga.toDbManga(), state.source)
|
||||
downloadManager.deleteManga(state.manga, state.source)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -541,7 +541,7 @@ class MangaPresenter(
|
||||
*/
|
||||
fun downloadChapters(chapters: List<DomainChapter>) {
|
||||
val manga = successState?.manga ?: return
|
||||
downloadManager.downloadChapters(manga.toDbManga(), chapters.map { it.toDbChapter() })
|
||||
downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() })
|
||||
}
|
||||
|
||||
/**
|
||||
@ -567,7 +567,7 @@ class MangaPresenter(
|
||||
try {
|
||||
updateSuccessState { successState ->
|
||||
val deletedIds = downloadManager
|
||||
.deleteChapters(chapters2, successState.manga.toDbManga(), successState.source)
|
||||
.deleteChapters(chapters2, successState.manga, successState.source)
|
||||
.map { it.id }
|
||||
val deletedChapters = successState.chapters.filter { deletedIds.contains(it.chapter.id) }
|
||||
if (deletedChapters.isEmpty()) return@updateSuccessState successState
|
||||
|
@ -804,7 +804,7 @@ class ReaderPresenter(
|
||||
val manga = manga ?: return
|
||||
|
||||
launchIO {
|
||||
downloadManager.enqueueDeleteChapters(listOf(chapter.chapter), manga)
|
||||
downloadManager.enqueueDeleteChapters(listOf(chapter.chapter), manga.toDomainManga()!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import android.app.Application
|
||||
import android.net.Uri
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
@ -46,7 +45,7 @@ class DownloadPageLoader(
|
||||
}
|
||||
|
||||
private fun getPagesFromDirectory(): Observable<List<ReaderPage>> {
|
||||
return downloadManager.buildPageList(source, manga.toDbManga(), chapter.chapter)
|
||||
return downloadManager.buildPageList(source, manga, chapter.chapter)
|
||||
.map { pages ->
|
||||
pages.map { page ->
|
||||
ReaderPage(page.index, page.url, page.imageUrl) {
|
||||
|
@ -8,7 +8,6 @@ import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.domain.chapter.model.ChapterUpdate
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
@ -219,7 +218,7 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
|
||||
* @param items list of recent chapters seleted.
|
||||
*/
|
||||
fun downloadChapters(items: List<UpdatesItem>) {
|
||||
items.forEach { downloadManager.downloadChapters(it.manga.toDbManga(), listOf(it.chapter.toDbChapter())) }
|
||||
items.forEach { downloadManager.downloadChapters(it.manga, listOf(it.chapter.toDbChapter())) }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,7 +229,7 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
|
||||
private fun deleteChaptersInternal(chapterItems: List<UpdatesItem>) {
|
||||
val itemsByManga = chapterItems.groupBy { it.manga.id }
|
||||
for ((_, items) in itemsByManga) {
|
||||
val manga = items.first().manga.toDbManga()
|
||||
val manga = items.first().manga
|
||||
val source = sourceManager.get(manga.source) ?: continue
|
||||
val chapters = items.map { it.chapter.toDbChapter() }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user