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.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,

View file

@ -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)
}
}
}

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.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
}
}

View file

@ -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
*

View file

@ -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

View file

@ -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)
}
}

View file

@ -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,
)
}
}

View file

@ -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() }
}

View file

@ -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)

View file

@ -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

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.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<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.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.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<String>, 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)
}
}

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.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(

View file

@ -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<PagingData<DomainManga>> {
fun getMangaList(): Flow<PagingData<Manga>> {
return remember(currentFilter) {
Pager(
PagingConfig(pageSize = 25),
@ -140,7 +140,7 @@ open class BrowseSourcePresenter(
}
@Composable
fun getManga(initialManga: DomainManga): State<DomainManga> {
fun getManga(initialManga: Manga): State<Manga> {
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<EnhancedTrackService>()
.filter { it.accept(source!!) }
@ -287,22 +287,22 @@ open class BrowseSourcePresenter(
*
* @return List of categories, not including the default category
*/
suspend fun getCategories(): List<DomainCategory> {
suspend fun getCategories(): List<Category> {
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<Long>) {
fun moveMangaToCategories(manga: Manga, categoryIds: List<Long>) {
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<CheckboxState.State<DomainCategory>>,
val manga: Manga,
val initialSelection: List<CheckboxState.State<Category>>,
) : 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.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()
},
)

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.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<DbManga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) {
fun removeMangas(mangaList: List<Manga>, 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)
}
}
}

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.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<Chapter>) {
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,
)

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.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()!!)
}
}

View file

@ -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<List<ReaderPage>> {
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) {

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.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)
}
}

View file

@ -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<Long>, preferences: DownloadPreferences): Boolean {
fun Manga.shouldDownloadNewChapters(dbCategories: List<Long>, preferences: DownloadPreferences): Boolean {
if (!favorite) return false
val categories = dbCategories.ifEmpty { listOf(0L) }
@ -82,7 +75,7 @@ fun DomainManga.shouldDownloadNewChapters(dbCategories: List<Long>, 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)
}
}