From c6c4c1c393aa8f7fe702ce7da9d7d04e0ad9005b Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 10 Nov 2022 22:42:44 -0500 Subject: [PATCH] Migrate to more domain model usages --- .../interactor/SyncChaptersWithSource.kt | 3 +- .../download/interactor/DeleteDownload.kt | 3 +- .../domain/manga/interactor/UpdateManga.kt | 5 ++- .../kanade/tachiyomi/data/cache/CoverCache.kt | 19 ++--------- .../tachiyomi/data/download/DownloadCache.kt | 2 +- .../data/download/DownloadManager.kt | 9 ++--- .../data/download/DownloadPendingDeleter.kt | 14 ++++---- .../data/download/DownloadProvider.kt | 5 ++- .../tachiyomi/data/download/Downloader.kt | 7 ++-- .../data/download/model/DownloadQueue.kt | 2 +- .../data/library/LibraryUpdateService.kt | 3 +- .../data/notification/NotificationReceiver.kt | 5 ++- .../migration/search/SearchPresenter.kt | 3 +- .../source/browse/BrowseSourcePresenter.kt | 34 +++++++++---------- .../tachiyomi/ui/library/LibraryController.kt | 3 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 11 +++--- .../tachiyomi/ui/manga/MangaScreenModel.kt | 7 ++-- .../tachiyomi/ui/reader/ReaderPresenter.kt | 7 ++-- .../ui/reader/loader/DownloadPageLoader.kt | 3 +- .../tachiyomi/ui/updates/UpdatesPresenter.kt | 5 ++- .../kanade/tachiyomi/util/MangaExtensions.kt | 29 ++++++---------- 21 files changed, 74 insertions(+), 105 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt index ef82b90d3e..0026c75807 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt @@ -4,7 +4,6 @@ import eu.kanade.data.chapter.CleanupChapterName import eu.kanade.data.chapter.NoChaptersException import eu.kanade.domain.chapter.model.Chapter 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.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.Manga @@ -111,7 +110,7 @@ class SyncChaptersWithSource( downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source) if (shouldRenameChapter) { - downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter()) + downloadManager.renameChapter(source, manga, dbChapter, chapter) } var toChangeChapter = dbChapter.copy( name = chapter.name, diff --git a/app/src/main/java/eu/kanade/domain/download/interactor/DeleteDownload.kt b/app/src/main/java/eu/kanade/domain/download/interactor/DeleteDownload.kt index c16a83be4a..80af9deefc 100644 --- a/app/src/main/java/eu/kanade/domain/download/interactor/DeleteDownload.kt +++ b/app/src/main/java/eu/kanade/domain/download/interactor/DeleteDownload.kt @@ -1,7 +1,6 @@ package eu.kanade.domain.download.interactor import eu.kanade.domain.chapter.model.Chapter -import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.source.SourceManager @@ -14,7 +13,7 @@ class DeleteDownload( suspend fun awaitAll(manga: Manga, vararg chapters: Chapter) = withNonCancellableContext { sourceManager.get(manga.source)?.let { source -> - downloadManager.deleteChapters(chapters.map { it.toDbChapter() }, manga, source) + downloadManager.deleteChapters(chapters.toList(), manga, source) } } } diff --git a/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt b/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt index f4bd0b3d1e..1e2dea4f24 100644 --- a/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/interactor/UpdateManga.kt @@ -4,7 +4,6 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.MangaUpdate import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.isLocal -import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.repository.MangaRepository import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.source.model.SManga @@ -46,11 +45,11 @@ class UpdateManga( !manualFetch && localManga.thumbnailUrl == remoteManga.thumbnail_url -> null localManga.isLocal() -> Date().time localManga.hasCustomCover(coverCache) -> { - coverCache.deleteFromCache(localManga.toDbManga(), false) + coverCache.deleteFromCache(localManga, false) null } else -> { - coverCache.deleteFromCache(localManga.toDbManga(), false) + coverCache.deleteFromCache(localManga, false) Date().time } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index 3ce2983d64..1195b75315 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -1,12 +1,11 @@ package eu.kanade.tachiyomi.data.cache 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 java.io.File import java.io.IOException import java.io.InputStream -import eu.kanade.domain.manga.model.Manga as DomainManga /** * Class used to create cover cache. @@ -76,7 +75,7 @@ class CoverCache(private val context: Context) { fun deleteFromCache(manga: Manga, deleteCustomCover: Boolean = false): Int { var deleted = 0 - getCoverFile(manga.thumbnail_url)?.let { + getCoverFile(manga.thumbnailUrl)?.let { if (it.exists() && it.delete()) ++deleted } @@ -87,20 +86,6 @@ class CoverCache(private val context: Context) { 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 * diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index e86b6f0491..1aedf7df7a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -4,9 +4,9 @@ import android.content.Context import androidx.core.net.toUri import com.hippo.unifile.UniFile import eu.kanade.core.util.mapNotNullKeys +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.data.database.models.Chapter import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager 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 7662fdea72..f4a12ab371 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 @@ -4,10 +4,11 @@ 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.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.Chapter +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 @@ -218,7 +219,7 @@ class DownloadManager( */ fun getChapterDownloadOrNull(chapter: Chapter): Download? { 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. */ 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) { @@ -244,7 +245,7 @@ class DownloadManager( downloadsByManga.map { entry -> val manga = entry.value.first().manga 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt index 12301a5d14..859c74e1b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadPendingDeleter.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import androidx.core.content.edit +import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.manga.model.Manga -import eu.kanade.tachiyomi.data.database.models.Chapter import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString @@ -181,11 +181,11 @@ class DownloadPendingDeleter(context: Context) { * Returns a chapter model from a chapter entry. */ private fun ChapterEntry.toModel(): Chapter { - return Chapter.create().also { - it.id = id - it.url = url - it.name = name - it.scanlator = scanlator - } + return Chapter.create().copy( + id = id, + url = url, + name = name, + scanlator = scanlator, + ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index be7300d50d..bc0652520b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import androidx.core.net.toUri import com.hippo.unifile.UniFile +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.Chapter import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.system.logcat @@ -16,7 +16,6 @@ import kotlinx.coroutines.flow.onEach import logcat.LogPriority import uy.kohesive.injekt.Injekt 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. @@ -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 || oldChapter.scanlator?.takeIf { it.isNotBlank() } != newChapter.scanlator?.takeIf { it.isNotBlank() } } 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 198746c69b..c916a88a3a 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,11 +4,12 @@ import android.content.Context import com.hippo.unifile.UniFile import com.jakewharton.rxrelay.BehaviorRelay 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.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.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier @@ -256,7 +257,7 @@ class Downloader( // Filter out those already downloaded. .filter { provider.findChapterDir(it.name, it.scanlator, manga.title, source) == null } // Add chapters to queue from the start. - .sortedByDescending { it.source_order } + .sortedByDescending { it.sourceOrder } } // Runs in main thread (synchronization needed). @@ -264,7 +265,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) } + .map { Download(source, manga, it.toDbChapter()) } if (chaptersToQueue.isNotEmpty()) { queue.addAll(chaptersToQueue) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt index 760111e9c5..9e83baaceb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.data.download.model import com.jakewharton.rxrelay.PublishRelay import eu.kanade.core.util.asFlow +import eu.kanade.domain.chapter.model.Chapter 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.source.model.Page import kotlinx.coroutines.flow.Flow diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 77bbbaaf76..ee843a0741 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -13,7 +13,6 @@ import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay 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.library.model.LibraryManga import eu.kanade.domain.library.service.LibraryPreferences @@ -415,7 +414,7 @@ class LibraryUpdateService( private fun downloadChapters(manga: Manga, chapters: List) { // 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.map { it.toDbChapter() }, false) + downloadManager.downloadChapters(manga, chapters, false) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index f538d5360b..913c71c16e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -12,7 +12,6 @@ import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.model.Chapter 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.manga.interactor.GetManga import eu.kanade.domain.manga.model.Manga @@ -253,7 +252,7 @@ class NotificationReceiver : BroadcastReceiver() { if (manga != null) { val source = sourceManager.get(manga.source) 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, mangaId: Long) { 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index 936814bbea..7ec6cb4e9e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -12,7 +12,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.hasCustomCover -import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.tachiyomi.core.preference.Preference @@ -189,7 +188,7 @@ class SearchPresenter( // Update custom cover (recheck if custom cover exists) if (migrateCustomCover && prevManga.hasCustomCover()) { @Suppress("BlockingMethodInNonBlockingContext") - coverCache.setCustomCoverToCache(manga.toDbManga(), coverCache.getCustomCoverFile(prevManga.id).inputStream()) + coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga.id).inputStream()) } updateManga.await( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index 929bf0c656..98992f195f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -22,6 +22,7 @@ import eu.kanade.core.prefs.mapAsCheckboxState import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.GetCategories 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.SetMangaDefaultChapterFlags 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.NetworkToLocalManga 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.toDomainManga import eu.kanade.domain.manga.model.toMangaUpdate @@ -76,8 +78,6 @@ import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get 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( private val sourceId: Long, @@ -121,7 +121,7 @@ open class BrowseSourcePresenter( } @Composable - fun getMangaList(): Flow> { + fun getMangaList(): Flow> { return remember(currentFilter) { Pager( PagingConfig(pageSize = 25), @@ -140,7 +140,7 @@ open class BrowseSourcePresenter( } @Composable - fun getManga(initialManga: DomainManga): State { + fun getManga(initialManga: Manga): State { return produceState(initialValue = initialManga) { getManga.subscribe(initialManga.url, initialManga.source) .collectLatest { manga -> @@ -186,7 +186,7 @@ open class BrowseSourcePresenter( * * @param manga to initialize. */ - private suspend fun initializeManga(manga: DomainManga) { + private suspend fun initializeManga(manga: Manga) { if (manga.thumbnailUrl != null || manga.initialized) return withNonCancellableContext { try { @@ -206,7 +206,7 @@ open class BrowseSourcePresenter( * * @param manga the manga to update. */ - fun changeMangaFavorite(manga: DomainManga) { + fun changeMangaFavorite(manga: Manga) { presenterScope.launch { var new = manga.copy( 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) } - fun addFavorite(manga: DomainManga) { + fun addFavorite(manga: Manga) { presenterScope.launch { val categories = getCategories() 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 .filterIsInstance() .filter { it.accept(source!!) } @@ -287,22 +287,22 @@ open class BrowseSourcePresenter( * * @return List of categories, not including the default category */ - suspend fun getCategories(): List { + suspend fun getCategories(): List { return getCategories.subscribe() .firstOrNull() ?.filterNot { it.isSystemCategory } ?: emptyList() } - suspend fun getDuplicateLibraryManga(manga: DomainManga): DomainManga? { + suspend fun getDuplicateLibraryManga(manga: Manga): Manga? { 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 }) } - fun moveMangaToCategories(manga: DomainManga, categoryIds: List) { + fun moveMangaToCategories(manga: Manga, categoryIds: List) { presenterScope.launchIO { setMangaCategories.await( mangaId = manga.id, @@ -328,11 +328,11 @@ open class BrowseSourcePresenter( } sealed class Dialog { - data class RemoveManga(val manga: DomainManga) : Dialog() - data class AddDuplicateManga(val manga: DomainManga, val duplicate: DomainManga) : Dialog() + data class RemoveManga(val manga: Manga) : Dialog() + data class AddDuplicateManga(val manga: Manga, val duplicate: Manga) : Dialog() data class ChangeMangaCategory( - val manga: DomainManga, - val initialSelection: List>, + val manga: Manga, + val initialSelection: List>, ) : Dialog() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 6f0d19b128..b63e8c62ca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -13,7 +13,6 @@ import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.manga.model.Manga 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.DeleteLibraryMangaDialog import eu.kanade.presentation.library.LibraryScreen @@ -102,7 +101,7 @@ class LibraryController( containsLocalManga = dialog.manga.any(Manga::isLocal), onDismissRequest = onDismissRequest, onConfirm = { deleteManga, deleteChapter -> - presenter.removeMangas(dialog.manga.map { it.toDbManga() }, deleteManga, deleteChapter) + presenter.removeMangas(dialog.manga, deleteManga, deleteChapter) presenter.clearSelection() }, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 559d875afb..a70cc9ee7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -20,7 +20,6 @@ import eu.kanade.domain.category.model.Category import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.SetReadStatus 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.library.model.LibraryManga 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.tachiyomi.R 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.DownloadManager import eu.kanade.tachiyomi.data.track.TrackManager @@ -64,7 +62,6 @@ import uy.kohesive.injekt.api.get import java.text.Collator import java.util.Collections import java.util.Locale -import eu.kanade.tachiyomi.data.database.models.Manga as DbManga /** * Class containing library information. @@ -432,7 +429,7 @@ class LibraryPresenter( } .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 deleteChapters whether to delete downloaded chapters. */ - fun removeMangas(mangaList: List, deleteFromLibrary: Boolean, deleteChapters: Boolean) { + fun removeMangas(mangaList: List, deleteFromLibrary: Boolean, deleteChapters: Boolean) { presenterScope.launchNonCancellable { val mangaToDelete = mangaList.distinctBy { it.id } @@ -469,7 +466,7 @@ class LibraryPresenter( it.removeCovers(coverCache) MangaUpdate( favorite = false, - id = it.id!!, + id = it.id, ) } updateManga.awaitAll(toDelete) @@ -479,7 +476,7 @@ class LibraryPresenter( mangaToDelete.forEach { manga -> val source = sourceManager.get(manga.source) as? HttpSource if (source != null) { - downloadManager.deleteManga(manga.toDomainManga()!!, source) + downloadManager.deleteManga(manga, source) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 97f35ed666..b63c06f04c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -19,7 +19,6 @@ import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.chapter.interactor.UpdateChapter 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.download.service.DownloadPreferences import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.manga.interactor.GetDuplicateLibraryManga @@ -289,7 +288,7 @@ class MangaInfoScreenModel( // Remove from library if (updateManga.awaitUpdateFavorite(manga.id, false)) { // Remove covers and update last modified in db - if (manga.toDbManga().removeCovers() > 0) { + if (manga.removeCovers() != manga) { updateManga.awaitUpdateCoverLastModified(manga.id) } withUIContext { onRemoved() } @@ -689,7 +688,7 @@ class MangaInfoScreenModel( */ private fun downloadChapters(chapters: List) { val manga = successState?.manga ?: return - downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() }) + downloadManager.downloadChapters(manga, chapters) toggleAllSelection(false) } @@ -717,7 +716,7 @@ class MangaInfoScreenModel( try { successState?.let { state -> downloadManager.deleteChapters( - chapters.map { it.toDbChapter() }, + chapters, state.manga, state.source, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 74504b4b64..5ee333d370 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -23,6 +23,7 @@ import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.service.TrackPreferences 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.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadProvider @@ -479,7 +480,7 @@ class ReaderPresenter( .take(amount) downloadManager.downloadChapters( manga.toDomainManga()!!, - chaptersToDownload.map { it.toDbChapter() }, + chaptersToDownload, ) } } @@ -489,7 +490,7 @@ class ReaderPresenter( * if setting is enabled and [currentChapter] is queued for download */ private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter): Download? { - return downloadManager.getChapterDownloadOrNull(currentChapter.chapter)?.apply { + return downloadManager.getChapterDownloadOrNull(currentChapter.chapter.toDomainChapter()!!)?.apply { downloadManager.deletePendingDownload(this) } } @@ -874,7 +875,7 @@ class ReaderPresenter( val manga = manga ?: return presenterScope.launchNonCancellable { - downloadManager.enqueueDeleteChapters(listOf(chapter.chapter), manga.toDomainManga()!!) + downloadManager.enqueueDeleteChapters(listOf(chapter.chapter.toDomainChapter()!!), manga.toDomainManga()!!) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt index ae852825e1..d9779cc500 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt @@ -4,6 +4,7 @@ import android.app.Application import android.net.Uri import com.hippo.unifile.UniFile 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.DownloadProvider import eu.kanade.tachiyomi.source.Source @@ -47,7 +48,7 @@ class DownloadPageLoader( } private fun getPagesFromDirectory(): Observable> { - return downloadManager.buildPageList(source, manga, chapter.chapter) + return downloadManager.buildPageList(source, manga, chapter.chapter.toDomainChapter()!!) .map { pages -> pages.map { page -> ReaderPage(page.index, page.url, page.imageUrl) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesPresenter.kt index b002e8c6c2..74bfd4e738 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesPresenter.kt @@ -9,7 +9,6 @@ import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.interactor.UpdateChapter 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.manga.interactor.GetManga import eu.kanade.domain.ui.UiPreferences @@ -242,7 +241,7 @@ class UpdatesPresenter( val manga = getManga.await(mangaId) ?: continue // Don't download if source isn't available 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) } } @@ -261,7 +260,7 @@ class UpdatesPresenter( .forEach { (mangaId, updates) -> val manga = getManga.await(mangaId) ?: 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt index 6c196e72af..f8b0b6e9a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt @@ -3,24 +3,21 @@ package eu.kanade.tachiyomi.util import android.content.Context import eu.kanade.domain.download.service.DownloadPreferences 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.isLocal -import eu.kanade.domain.manga.model.toDbManga 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.model.SManga import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.InputStream 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 */ -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 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 { - if (toDomainManga()!!.isLocal()) return 0 - - cover_last_modified = Date().time - return coverCache.deleteFromCache(this, true) -} - -fun DomainManga.removeCovers(coverCache: CoverCache = Injekt.get()): DomainManga { +fun Manga.removeCovers(coverCache: CoverCache = Injekt.get()): Manga { if (isLocal()) return this - coverCache.deleteFromCache(this, true) - return copy(coverLastModified = Date().time) + return if (coverCache.deleteFromCache(this, true) > 0) { + return copy(coverLastModified = Date().time) + } else { + this + } } -fun DomainManga.shouldDownloadNewChapters(dbCategories: List, preferences: DownloadPreferences): Boolean { +fun Manga.shouldDownloadNewChapters(dbCategories: List, preferences: DownloadPreferences): Boolean { if (!favorite) return false val categories = dbCategories.ifEmpty { listOf(0L) } @@ -82,7 +75,7 @@ fun DomainManga.shouldDownloadNewChapters(dbCategories: List, preferences: return categories.any { it in includedCategories } } -suspend fun DomainManga.editCover( +suspend fun Manga.editCover( context: Context, stream: InputStream, updateManga: UpdateManga = Injekt.get(), @@ -92,7 +85,7 @@ suspend fun DomainManga.editCover( LocalSource.updateCover(context, toSManga(), stream) updateManga.awaitUpdateCoverLastModified(id) } else if (favorite) { - coverCache.setCustomCoverToCache(toDbManga(), stream) + coverCache.setCustomCoverToCache(this, stream) updateManga.awaitUpdateCoverLastModified(id) } }