Migrate to more domain model usages

This commit is contained in:
arkon 2022-11-10 22:42:44 -05:00
parent 811931ccc0
commit c6c4c1c393
21 changed files with 74 additions and 105 deletions

View File

@ -4,7 +4,6 @@ import eu.kanade.data.chapter.CleanupChapterName
import eu.kanade.data.chapter.NoChaptersException import eu.kanade.data.chapter.NoChaptersException
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.model.toChapterUpdate import eu.kanade.domain.chapter.model.toChapterUpdate
import eu.kanade.domain.chapter.model.toDbChapter
import eu.kanade.domain.chapter.repository.ChapterRepository import eu.kanade.domain.chapter.repository.ChapterRepository
import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
@ -111,7 +110,7 @@ class SyncChaptersWithSource(
downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source) downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source)
if (shouldRenameChapter) { if (shouldRenameChapter) {
downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter()) downloadManager.renameChapter(source, manga, dbChapter, chapter)
} }
var toChangeChapter = dbChapter.copy( var toChangeChapter = dbChapter.copy(
name = chapter.name, name = chapter.name,

View File

@ -1,7 +1,6 @@
package eu.kanade.domain.download.interactor package eu.kanade.domain.download.interactor
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.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
@ -14,7 +13,7 @@ class DeleteDownload(
suspend fun awaitAll(manga: Manga, vararg chapters: Chapter) = withNonCancellableContext { suspend fun awaitAll(manga: Manga, vararg chapters: Chapter) = withNonCancellableContext {
sourceManager.get(manga.source)?.let { source -> sourceManager.get(manga.source)?.let { source ->
downloadManager.deleteChapters(chapters.map { it.toDbChapter() }, manga, source) downloadManager.deleteChapters(chapters.toList(), manga, source)
} }
} }
} }

View File

@ -4,7 +4,6 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.MangaUpdate import eu.kanade.domain.manga.model.MangaUpdate
import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.hasCustomCover
import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.isLocal
import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.domain.manga.repository.MangaRepository import eu.kanade.domain.manga.repository.MangaRepository
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -46,11 +45,11 @@ class UpdateManga(
!manualFetch && localManga.thumbnailUrl == remoteManga.thumbnail_url -> null !manualFetch && localManga.thumbnailUrl == remoteManga.thumbnail_url -> null
localManga.isLocal() -> Date().time localManga.isLocal() -> Date().time
localManga.hasCustomCover(coverCache) -> { localManga.hasCustomCover(coverCache) -> {
coverCache.deleteFromCache(localManga.toDbManga(), false) coverCache.deleteFromCache(localManga, false)
null null
} }
else -> { else -> {
coverCache.deleteFromCache(localManga.toDbManga(), false) coverCache.deleteFromCache(localManga, false)
Date().time Date().time
} }
} }

View File

@ -1,12 +1,11 @@
package eu.kanade.tachiyomi.data.cache package eu.kanade.tachiyomi.data.cache
import android.content.Context import android.content.Context
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.DiskUtil
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import eu.kanade.domain.manga.model.Manga as DomainManga
/** /**
* Class used to create cover cache. * Class used to create cover cache.
@ -76,7 +75,7 @@ class CoverCache(private val context: Context) {
fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int { fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int {
var deleted = 0 var deleted = 0
getCoverFile(manga.thumbnail_url)?.let { getCoverFile(manga.thumbnailUrl)?.let {
if (it.exists() && it.delete()) ++deleted if (it.exists() && it.delete()) ++deleted
} }
@ -87,20 +86,6 @@ class CoverCache(private val context: Context) {
return deleted return deleted
} }
fun deleteFromCache(manga: DomainManga, deleteCustomCover: Boolean = false): Int {
var amountDeleted = 0
getCoverFile(manga.thumbnailUrl)?.let {
if (it.exists() && it.delete()) amountDeleted++
}
if (deleteCustomCover && deleteCustomCover(manga.id)) {
amountDeleted++
}
return amountDeleted
}
/** /**
* Delete custom cover of the manga from the cache * Delete custom cover of the manga from the cache
* *

View File

@ -4,9 +4,9 @@ import android.content.Context
import androidx.core.net.toUri import androidx.core.net.toUri
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.core.util.mapNotNullKeys import eu.kanade.core.util.mapNotNullKeys
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.data.database.models.Chapter
import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager

View File

@ -4,10 +4,11 @@ import android.content.Context
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.GetCategories
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.Chapter 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
@ -218,7 +219,7 @@ class DownloadManager(
*/ */
fun getChapterDownloadOrNull(chapter: Chapter): Download? { fun getChapterDownloadOrNull(chapter: Chapter): Download? {
return downloader.queue return downloader.queue
.firstOrNull { it.chapter.id == chapter.id && it.chapter.manga_id == chapter.manga_id } .firstOrNull { it.chapter.id == chapter.id && it.chapter.manga_id == chapter.mangaId }
} }
/** /**
@ -236,7 +237,7 @@ class DownloadManager(
* @param download the download to cancel. * @param download the download to cancel.
*/ */
fun deletePendingDownload(download: Download) { fun deletePendingDownload(download: Download) {
deleteChapters(listOf(download.chapter), download.manga, download.source, true) deleteChapters(listOf(download.chapter.toDomainChapter()!!), download.manga, download.source, true)
} }
fun deletePendingDownloads(vararg downloads: Download) { fun deletePendingDownloads(vararg downloads: Download) {
@ -244,7 +245,7 @@ class DownloadManager(
downloadsByManga.map { entry -> downloadsByManga.map { entry ->
val manga = entry.value.first().manga val manga = entry.value.first().manga
val source = entry.value.first().source val source = entry.value.first().source
deleteChapters(entry.value.map { it.chapter }, manga, source, true) deleteChapters(entry.value.map { it.chapter.toDomainChapter()!! }, manga, source, true)
} }
} }

View File

@ -2,8 +2,8 @@ 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.model.Chapter
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.database.models.Chapter
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
@ -181,11 +181,11 @@ class DownloadPendingDeleter(context: Context) {
* Returns a chapter model from a chapter entry. * Returns a chapter model from a chapter entry.
*/ */
private fun ChapterEntry.toModel(): Chapter { private fun ChapterEntry.toModel(): Chapter {
return Chapter.create().also { return Chapter.create().copy(
it.id = id id = id,
it.url = url url = url,
it.name = name name = name,
it.scanlator = scanlator scanlator = scanlator,
} )
} }
} }

View File

@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.data.download
import android.content.Context import android.content.Context
import androidx.core.net.toUri import androidx.core.net.toUri
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
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.Chapter
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
@ -16,7 +16,6 @@ import kotlinx.coroutines.flow.onEach
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import eu.kanade.domain.chapter.model.Chapter as DomainChapter
/** /**
* This class is used to provide the directories where the downloads should be saved. * This class is used to provide the directories where the downloads should be saved.
@ -147,7 +146,7 @@ class DownloadProvider(
) )
} }
fun isChapterDirNameChanged(oldChapter: DomainChapter, newChapter: DomainChapter): Boolean { fun isChapterDirNameChanged(oldChapter: Chapter, newChapter: Chapter): Boolean {
return oldChapter.name != newChapter.name || return oldChapter.name != newChapter.name ||
oldChapter.scanlator?.takeIf { it.isNotBlank() } != newChapter.scanlator?.takeIf { it.isNotBlank() } oldChapter.scanlator?.takeIf { it.isNotBlank() } != newChapter.scanlator?.takeIf { it.isNotBlank() }
} }

View File

@ -4,11 +4,12 @@ import android.content.Context
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import com.jakewharton.rxrelay.PublishRelay 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.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.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.database.models.Chapter
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.data.library.LibraryUpdateNotifier import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
@ -256,7 +257,7 @@ class Downloader(
// Filter out those already downloaded. // Filter out those already downloaded.
.filter { provider.findChapterDir(it.name, it.scanlator, manga.title, source) == null } .filter { provider.findChapterDir(it.name, it.scanlator, manga.title, source) == null }
// Add chapters to queue from the start. // Add chapters to queue from the start.
.sortedByDescending { it.source_order } .sortedByDescending { it.sourceOrder }
} }
// Runs in main thread (synchronization needed). // Runs in main thread (synchronization needed).
@ -264,7 +265,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) } .map { Download(source, manga, it.toDbChapter()) }
if (chaptersToQueue.isNotEmpty()) { if (chaptersToQueue.isNotEmpty()) {
queue.addAll(chaptersToQueue) queue.addAll(chaptersToQueue)

View File

@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.data.download.model
import com.jakewharton.rxrelay.PublishRelay import com.jakewharton.rxrelay.PublishRelay
import eu.kanade.core.util.asFlow import eu.kanade.core.util.asFlow
import eu.kanade.domain.chapter.model.Chapter
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.data.download.DownloadStore import eu.kanade.tachiyomi.data.download.DownloadStore
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow

View File

@ -13,7 +13,6 @@ import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay
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.library.model.LibraryManga import eu.kanade.domain.library.model.LibraryManga
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
@ -415,7 +414,7 @@ class LibraryUpdateService(
private fun downloadChapters(manga: Manga, chapters: List<Chapter>) { private fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
// We don't want to start downloading while the library is updating, because websites // 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. // may don't like it and they could ban the user.
downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() }, false) downloadManager.downloadChapters(manga, chapters, false)
} }
/** /**

View File

@ -12,7 +12,6 @@ import eu.kanade.domain.chapter.interactor.GetChapter
import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.interactor.UpdateChapter
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.model.toChapterUpdate import eu.kanade.domain.chapter.model.toChapterUpdate
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.interactor.GetManga import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
@ -253,7 +252,7 @@ class NotificationReceiver : BroadcastReceiver() {
if (manga != null) { if (manga != null) {
val source = sourceManager.get(manga.source) val source = sourceManager.get(manga.source)
if (source != null) { if (source != null) {
downloadManager.deleteChapters(listOf(it.toDbChapter()), manga, source) downloadManager.deleteChapters(listOf(it), manga, source)
} }
} }
} }
@ -272,7 +271,7 @@ class NotificationReceiver : BroadcastReceiver() {
private fun downloadChapters(chapterUrls: Array<String>, mangaId: Long) { private fun downloadChapters(chapterUrls: Array<String>, mangaId: Long) {
launchIO { launchIO {
val manga = getManga.await(mangaId) ?: return@launchIO val manga = getManga.await(mangaId) ?: return@launchIO
val chapters = chapterUrls.mapNotNull { getChapter.await(it, mangaId)?.toDbChapter() } val chapters = chapterUrls.mapNotNull { getChapter.await(it, mangaId) }
downloadManager.downloadChapters(manga, chapters) downloadManager.downloadChapters(manga, chapters)
} }
} }

View File

@ -12,7 +12,6 @@ import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.MangaUpdate import eu.kanade.domain.manga.model.MangaUpdate
import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.hasCustomCover
import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.GetTracks
import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.domain.track.interactor.InsertTrack
import eu.kanade.tachiyomi.core.preference.Preference import eu.kanade.tachiyomi.core.preference.Preference
@ -189,7 +188,7 @@ class SearchPresenter(
// Update custom cover (recheck if custom cover exists) // Update custom cover (recheck if custom cover exists)
if (migrateCustomCover && prevManga.hasCustomCover()) { if (migrateCustomCover && prevManga.hasCustomCover()) {
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
coverCache.setCustomCoverToCache(manga.toDbManga(), coverCache.getCustomCoverFile(prevManga.id).inputStream()) coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga.id).inputStream())
} }
updateManga.await( updateManga.await(

View File

@ -22,6 +22,7 @@ import eu.kanade.core.prefs.mapAsCheckboxState
import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.GetCategories
import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.interactor.SetMangaCategories
import eu.kanade.domain.category.model.Category
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags
import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay
@ -30,6 +31,7 @@ import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga
import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.manga.interactor.NetworkToLocalManga import eu.kanade.domain.manga.interactor.NetworkToLocalManga
import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.domain.manga.model.toDomainManga import eu.kanade.domain.manga.model.toDomainManga
import eu.kanade.domain.manga.model.toMangaUpdate import eu.kanade.domain.manga.model.toMangaUpdate
@ -76,8 +78,6 @@ import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.Date import java.util.Date
import eu.kanade.domain.category.model.Category as DomainCategory
import eu.kanade.domain.manga.model.Manga as DomainManga
open class BrowseSourcePresenter( open class BrowseSourcePresenter(
private val sourceId: Long, private val sourceId: Long,
@ -121,7 +121,7 @@ open class BrowseSourcePresenter(
} }
@Composable @Composable
fun getMangaList(): Flow<PagingData<DomainManga>> { fun getMangaList(): Flow<PagingData<Manga>> {
return remember(currentFilter) { return remember(currentFilter) {
Pager( Pager(
PagingConfig(pageSize = 25), PagingConfig(pageSize = 25),
@ -140,7 +140,7 @@ open class BrowseSourcePresenter(
} }
@Composable @Composable
fun getManga(initialManga: DomainManga): State<DomainManga> { fun getManga(initialManga: Manga): State<Manga> {
return produceState(initialValue = initialManga) { return produceState(initialValue = initialManga) {
getManga.subscribe(initialManga.url, initialManga.source) getManga.subscribe(initialManga.url, initialManga.source)
.collectLatest { manga -> .collectLatest { manga ->
@ -186,7 +186,7 @@ open class BrowseSourcePresenter(
* *
* @param manga to initialize. * @param manga to initialize.
*/ */
private suspend fun initializeManga(manga: DomainManga) { private suspend fun initializeManga(manga: Manga) {
if (manga.thumbnailUrl != null || manga.initialized) return if (manga.thumbnailUrl != null || manga.initialized) return
withNonCancellableContext { withNonCancellableContext {
try { try {
@ -206,7 +206,7 @@ open class BrowseSourcePresenter(
* *
* @param manga the manga to update. * @param manga the manga to update.
*/ */
fun changeMangaFavorite(manga: DomainManga) { fun changeMangaFavorite(manga: Manga) {
presenterScope.launch { presenterScope.launch {
var new = manga.copy( var new = manga.copy(
favorite = !manga.favorite, favorite = !manga.favorite,
@ -228,11 +228,11 @@ open class BrowseSourcePresenter(
} }
} }
fun getSourceOrStub(manga: DomainManga): Source { fun getSourceOrStub(manga: Manga): Source {
return sourceManager.getOrStub(manga.source) return sourceManager.getOrStub(manga.source)
} }
fun addFavorite(manga: DomainManga) { fun addFavorite(manga: Manga) {
presenterScope.launch { presenterScope.launch {
val categories = getCategories() val categories = getCategories()
val defaultCategoryId = libraryPreferences.defaultCategory().get() val defaultCategoryId = libraryPreferences.defaultCategory().get()
@ -262,7 +262,7 @@ open class BrowseSourcePresenter(
} }
} }
private suspend fun autoAddTrack(manga: DomainManga) { private suspend fun autoAddTrack(manga: Manga) {
loggedServices loggedServices
.filterIsInstance<EnhancedTrackService>() .filterIsInstance<EnhancedTrackService>()
.filter { it.accept(source!!) } .filter { it.accept(source!!) }
@ -287,22 +287,22 @@ open class BrowseSourcePresenter(
* *
* @return List of categories, not including the default category * @return List of categories, not including the default category
*/ */
suspend fun getCategories(): List<DomainCategory> { suspend fun getCategories(): List<Category> {
return getCategories.subscribe() return getCategories.subscribe()
.firstOrNull() .firstOrNull()
?.filterNot { it.isSystemCategory } ?.filterNot { it.isSystemCategory }
?: emptyList() ?: emptyList()
} }
suspend fun getDuplicateLibraryManga(manga: DomainManga): DomainManga? { suspend fun getDuplicateLibraryManga(manga: Manga): Manga? {
return getDuplicateLibraryManga.await(manga.title, manga.source) return getDuplicateLibraryManga.await(manga.title, manga.source)
} }
fun moveMangaToCategories(manga: DomainManga, vararg categories: DomainCategory) { fun moveMangaToCategories(manga: Manga, vararg categories: Category) {
moveMangaToCategories(manga, categories.filter { it.id != 0L }.map { it.id }) moveMangaToCategories(manga, categories.filter { it.id != 0L }.map { it.id })
} }
fun moveMangaToCategories(manga: DomainManga, categoryIds: List<Long>) { fun moveMangaToCategories(manga: Manga, categoryIds: List<Long>) {
presenterScope.launchIO { presenterScope.launchIO {
setMangaCategories.await( setMangaCategories.await(
mangaId = manga.id, mangaId = manga.id,
@ -328,11 +328,11 @@ open class BrowseSourcePresenter(
} }
sealed class Dialog { sealed class Dialog {
data class RemoveManga(val manga: DomainManga) : Dialog() data class RemoveManga(val manga: Manga) : Dialog()
data class AddDuplicateManga(val manga: DomainManga, val duplicate: DomainManga) : Dialog() data class AddDuplicateManga(val manga: Manga, val duplicate: Manga) : Dialog()
data class ChangeMangaCategory( data class ChangeMangaCategory(
val manga: DomainManga, val manga: Manga,
val initialSelection: List<CheckboxState.State<DomainCategory>>, val initialSelection: List<CheckboxState.State<Category>>,
) : Dialog() ) : Dialog()
} }
} }

View File

@ -13,7 +13,6 @@ import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.library.model.LibraryManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.isLocal
import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.presentation.components.ChangeCategoryDialog import eu.kanade.presentation.components.ChangeCategoryDialog
import eu.kanade.presentation.components.DeleteLibraryMangaDialog import eu.kanade.presentation.components.DeleteLibraryMangaDialog
import eu.kanade.presentation.library.LibraryScreen import eu.kanade.presentation.library.LibraryScreen
@ -102,7 +101,7 @@ class LibraryController(
containsLocalManga = dialog.manga.any(Manga::isLocal), containsLocalManga = dialog.manga.any(Manga::isLocal),
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
onConfirm = { deleteManga, deleteChapter -> onConfirm = { deleteManga, deleteChapter ->
presenter.removeMangas(dialog.manga.map { it.toDbManga() }, deleteManga, deleteChapter) presenter.removeMangas(dialog.manga, deleteManga, deleteChapter)
presenter.clearSelection() presenter.clearSelection()
}, },
) )

View File

@ -20,7 +20,6 @@ import eu.kanade.domain.category.model.Category
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.interactor.SetReadStatus
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.history.interactor.GetNextChapters import eu.kanade.domain.history.interactor.GetNextChapters
import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.library.model.LibraryManga
import eu.kanade.domain.library.model.LibrarySort import eu.kanade.domain.library.model.LibrarySort
@ -38,7 +37,6 @@ import eu.kanade.presentation.library.LibraryStateImpl
import eu.kanade.presentation.library.components.LibraryToolbarTitle import eu.kanade.presentation.library.components.LibraryToolbarTitle
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.models.toDomainManga
import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.download.DownloadCache
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
@ -64,7 +62,6 @@ import uy.kohesive.injekt.api.get
import java.text.Collator import java.text.Collator
import java.util.Collections import java.util.Collections
import java.util.Locale import java.util.Locale
import eu.kanade.tachiyomi.data.database.models.Manga as DbManga
/** /**
* Class containing library information. * Class containing library information.
@ -432,7 +429,7 @@ class LibraryPresenter(
} }
.let { if (amount != null) it.take(amount) else it } .let { if (amount != null) it.take(amount) else it }
downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() }) downloadManager.downloadChapters(manga, chapters)
} }
} }
} }
@ -460,7 +457,7 @@ class LibraryPresenter(
* @param deleteFromLibrary whether to delete manga from library. * @param deleteFromLibrary whether to delete manga from library.
* @param deleteChapters whether to delete downloaded chapters. * @param deleteChapters whether to delete downloaded chapters.
*/ */
fun removeMangas(mangaList: List<DbManga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) { fun removeMangas(mangaList: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) {
presenterScope.launchNonCancellable { presenterScope.launchNonCancellable {
val mangaToDelete = mangaList.distinctBy { it.id } val mangaToDelete = mangaList.distinctBy { it.id }
@ -469,7 +466,7 @@ class LibraryPresenter(
it.removeCovers(coverCache) it.removeCovers(coverCache)
MangaUpdate( MangaUpdate(
favorite = false, favorite = false,
id = it.id!!, id = it.id,
) )
} }
updateManga.awaitAll(toDelete) updateManga.awaitAll(toDelete)
@ -479,7 +476,7 @@ class LibraryPresenter(
mangaToDelete.forEach { manga -> mangaToDelete.forEach { manga ->
val source = sourceManager.get(manga.source) as? HttpSource val source = sourceManager.get(manga.source) as? HttpSource
if (source != null) { if (source != null) {
downloadManager.deleteManga(manga.toDomainManga()!!, source) downloadManager.deleteManga(manga, source)
} }
} }
} }

View File

@ -19,7 +19,6 @@ import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.interactor.UpdateChapter
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.model.ChapterUpdate import eu.kanade.domain.chapter.model.ChapterUpdate
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.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga
@ -289,7 +288,7 @@ class MangaInfoScreenModel(
// Remove from library // Remove from library
if (updateManga.awaitUpdateFavorite(manga.id, false)) { if (updateManga.awaitUpdateFavorite(manga.id, false)) {
// Remove covers and update last modified in db // Remove covers and update last modified in db
if (manga.toDbManga().removeCovers() > 0) { if (manga.removeCovers() != manga) {
updateManga.awaitUpdateCoverLastModified(manga.id) updateManga.awaitUpdateCoverLastModified(manga.id)
} }
withUIContext { onRemoved() } withUIContext { onRemoved() }
@ -689,7 +688,7 @@ class MangaInfoScreenModel(
*/ */
private fun downloadChapters(chapters: List<Chapter>) { private fun downloadChapters(chapters: List<Chapter>) {
val manga = successState?.manga ?: return val manga = successState?.manga ?: return
downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() }) downloadManager.downloadChapters(manga, chapters)
toggleAllSelection(false) toggleAllSelection(false)
} }
@ -717,7 +716,7 @@ class MangaInfoScreenModel(
try { try {
successState?.let { state -> successState?.let { state ->
downloadManager.deleteChapters( downloadManager.deleteChapters(
chapters.map { it.toDbChapter() }, chapters,
state.manga, state.manga,
state.source, state.source,
) )

View File

@ -23,6 +23,7 @@ import eu.kanade.domain.track.interactor.InsertTrack
import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDbTrack
import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.domain.track.service.TrackPreferences
import eu.kanade.tachiyomi.data.database.models.Manga 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.toDomainManga
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.DownloadProvider
@ -479,7 +480,7 @@ class ReaderPresenter(
.take(amount) .take(amount)
downloadManager.downloadChapters( downloadManager.downloadChapters(
manga.toDomainManga()!!, manga.toDomainManga()!!,
chaptersToDownload.map { it.toDbChapter() }, chaptersToDownload,
) )
} }
} }
@ -489,7 +490,7 @@ class ReaderPresenter(
* if setting is enabled and [currentChapter] is queued for download * if setting is enabled and [currentChapter] is queued for download
*/ */
private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter): Download? { private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter): Download? {
return downloadManager.getChapterDownloadOrNull(currentChapter.chapter)?.apply { return downloadManager.getChapterDownloadOrNull(currentChapter.chapter.toDomainChapter()!!)?.apply {
downloadManager.deletePendingDownload(this) downloadManager.deletePendingDownload(this)
} }
} }
@ -874,7 +875,7 @@ class ReaderPresenter(
val manga = manga ?: return val manga = manga ?: return
presenterScope.launchNonCancellable { presenterScope.launchNonCancellable {
downloadManager.enqueueDeleteChapters(listOf(chapter.chapter), manga.toDomainManga()!!) downloadManager.enqueueDeleteChapters(listOf(chapter.chapter.toDomainChapter()!!), manga.toDomainManga()!!)
} }
} }

View File

@ -4,6 +4,7 @@ import android.app.Application
import android.net.Uri import android.net.Uri
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
@ -47,7 +48,7 @@ class DownloadPageLoader(
} }
private fun getPagesFromDirectory(): Observable<List<ReaderPage>> { private fun getPagesFromDirectory(): Observable<List<ReaderPage>> {
return downloadManager.buildPageList(source, manga, chapter.chapter) return downloadManager.buildPageList(source, manga, chapter.chapter.toDomainChapter()!!)
.map { pages -> .map { pages ->
pages.map { page -> pages.map { page ->
ReaderPage(page.index, page.url, page.imageUrl) { ReaderPage(page.index, page.url, page.imageUrl) {

View File

@ -9,7 +9,6 @@ import eu.kanade.domain.chapter.interactor.GetChapter
import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.interactor.SetReadStatus
import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.interactor.UpdateChapter
import eu.kanade.domain.chapter.model.ChapterUpdate import eu.kanade.domain.chapter.model.ChapterUpdate
import eu.kanade.domain.chapter.model.toDbChapter
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.UiPreferences
@ -242,7 +241,7 @@ class UpdatesPresenter(
val manga = getManga.await(mangaId) ?: continue val manga = getManga.await(mangaId) ?: continue
// Don't download if source isn't available // Don't download if source isn't available
sourceManager.get(manga.source) ?: continue sourceManager.get(manga.source) ?: continue
val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() } val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId) }
downloadManager.downloadChapters(manga, chapters) downloadManager.downloadChapters(manga, chapters)
} }
} }
@ -261,7 +260,7 @@ class UpdatesPresenter(
.forEach { (mangaId, updates) -> .forEach { (mangaId, updates) ->
val manga = getManga.await(mangaId) ?: return@forEach val manga = getManga.await(mangaId) ?: return@forEach
val source = sourceManager.get(manga.source) ?: return@forEach val source = sourceManager.get(manga.source) ?: return@forEach
val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() } val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId) }
downloadManager.deleteChapters(chapters, manga, source) downloadManager.deleteChapters(chapters, manga, source)
} }
} }

View File

@ -3,24 +3,21 @@ package eu.kanade.tachiyomi.util
import android.content.Context import android.content.Context
import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.download.service.DownloadPreferences
import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.hasCustomCover
import eu.kanade.domain.manga.model.isLocal import eu.kanade.domain.manga.model.isLocal
import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.tachiyomi.data.cache.CoverCache 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.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.InputStream import java.io.InputStream
import java.util.Date import java.util.Date
import eu.kanade.domain.manga.model.Manga as DomainManga
/** /**
* Call before updating [Manga.thumbnail_url] to ensure old cover can be cleared from cache * Call before updating [Manga.thumbnail_url] to ensure old cover can be cleared from cache
*/ */
fun DomainManga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSameUrl: Boolean): DomainManga { fun Manga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSameUrl: Boolean): Manga {
// Never refresh covers if the new url is null, as the current url has possibly become invalid // Never refresh covers if the new url is null, as the current url has possibly become invalid
val newUrl = remoteManga.thumbnail_url ?: return this val newUrl = remoteManga.thumbnail_url ?: return this
@ -44,20 +41,16 @@ fun DomainManga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, ref
} }
} }
fun Manga.removeCovers(coverCache: CoverCache = Injekt.get()): Int { fun Manga.removeCovers(coverCache: CoverCache = Injekt.get()): Manga {
if (toDomainManga()!!.isLocal()) return 0
cover_last_modified = Date().time
return coverCache.deleteFromCache(this, true)
}
fun DomainManga.removeCovers(coverCache: CoverCache = Injekt.get()): DomainManga {
if (isLocal()) return this if (isLocal()) return this
coverCache.deleteFromCache(this, true) return if (coverCache.deleteFromCache(this, true) > 0) {
return copy(coverLastModified = Date().time) return copy(coverLastModified = Date().time)
} else {
this
}
} }
fun DomainManga.shouldDownloadNewChapters(dbCategories: List<Long>, preferences: DownloadPreferences): Boolean { fun Manga.shouldDownloadNewChapters(dbCategories: List<Long>, preferences: DownloadPreferences): Boolean {
if (!favorite) return false if (!favorite) return false
val categories = dbCategories.ifEmpty { listOf(0L) } val categories = dbCategories.ifEmpty { listOf(0L) }
@ -82,7 +75,7 @@ fun DomainManga.shouldDownloadNewChapters(dbCategories: List<Long>, preferences:
return categories.any { it in includedCategories } return categories.any { it in includedCategories }
} }
suspend fun DomainManga.editCover( suspend fun Manga.editCover(
context: Context, context: Context,
stream: InputStream, stream: InputStream,
updateManga: UpdateManga = Injekt.get(), updateManga: UpdateManga = Injekt.get(),
@ -92,7 +85,7 @@ suspend fun DomainManga.editCover(
LocalSource.updateCover(context, toSManga(), stream) LocalSource.updateCover(context, toSManga(), stream)
updateManga.awaitUpdateCoverLastModified(id) updateManga.awaitUpdateCoverLastModified(id)
} else if (favorite) { } else if (favorite) {
coverCache.setCustomCoverToCache(toDbManga(), stream) coverCache.setCustomCoverToCache(this, stream)
updateManga.awaitUpdateCoverLastModified(id) updateManga.awaitUpdateCoverLastModified(id)
} }
} }