mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-26 15:16:04 +03:00
More domain model usage
This commit is contained in:
parent
b3dd8b7355
commit
68697e59d7
12 changed files with 29 additions and 57 deletions
|
@ -4,16 +4,18 @@ import android.content.Context
|
|||
import android.net.Uri
|
||||
import eu.kanade.data.DatabaseHandler
|
||||
import eu.kanade.data.toLong
|
||||
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.domain.manga.interactor.GetFavorites
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainManga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import data.Mangas as DbManga
|
||||
|
@ -27,6 +29,7 @@ abstract class AbstractBackupManager(protected val context: Context) {
|
|||
internal val trackManager: TrackManager = Injekt.get()
|
||||
protected val preferences: PreferencesHelper = Injekt.get()
|
||||
private val getFavorites: GetFavorites = Injekt.get()
|
||||
private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get()
|
||||
|
||||
abstract suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String
|
||||
|
||||
|
@ -50,12 +53,12 @@ abstract class AbstractBackupManager(protected val context: Context) {
|
|||
internal suspend fun restoreChapters(source: Source, manga: Manga, chapters: List<Chapter>): Pair<List<Chapter>, List<Chapter>> {
|
||||
val fetchedChapters = source.getChapterList(manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
val syncedChapters = syncChaptersWithSource(fetchedChapters, manga, source)
|
||||
val syncedChapters = syncChaptersWithSource.await(fetchedChapters, manga.toDomainManga()!!, source)
|
||||
if (syncedChapters.first.isNotEmpty()) {
|
||||
chapters.forEach { it.manga_id = manga.id }
|
||||
updateChapters(chapters)
|
||||
}
|
||||
return syncedChapters
|
||||
return syncedChapters.first.map { it.toDbChapter() } to syncedChapters.second.map { it.toDbChapter() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.cache
|
|||
import android.content.Context
|
||||
import android.text.format.Formatter
|
||||
import com.jakewharton.disklrucache.DiskLruCache
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import eu.kanade.tachiyomi.util.storage.saveTo
|
||||
|
@ -207,6 +207,6 @@ class ChapterCache(private val context: Context) {
|
|||
}
|
||||
|
||||
private fun getKey(chapter: Chapter): String {
|
||||
return "${chapter.manga_id}${chapter.url}"
|
||||
return "${chapter.mangaId}${chapter.url}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ open class BrowseSourcePresenter(
|
|||
if (!manga.favorite) {
|
||||
manga.removeCovers(coverCache)
|
||||
} else {
|
||||
ChapterSettingsHelper.applySettingDefaults(manga)
|
||||
ChapterSettingsHelper.applySettingDefaults(manga.toDomainManga()!!)
|
||||
|
||||
autoAddTrack(manga)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.view.View
|
|||
import androidx.core.view.isVisible
|
||||
import com.bluelinelabs.conductor.Router
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.domain.manga.model.toTriStateGroupState
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaPresenter
|
||||
|
@ -79,7 +78,7 @@ class ChaptersSettingsSheet(
|
|||
onMenuItemClick = {
|
||||
when (itemId) {
|
||||
R.id.set_as_default -> {
|
||||
SetChapterSettingsDialog(presenter.manga!!.toDbManga()).showDialog(router)
|
||||
SetChapterSettingsDialog(presenter.manga!!).showDialog(router)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.app.Dialog
|
|||
import android.os.Bundle
|
||||
import androidx.core.os.bundleOf
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
|
|
|
@ -267,7 +267,7 @@ class ReaderPresenter(
|
|||
|
||||
val context = Injekt.get<Application>()
|
||||
val source = sourceManager.getOrStub(manga.source)
|
||||
loader = ChapterLoader(context, downloadManager, manga, source)
|
||||
loader = ChapterLoader(context, downloadManager, manga.toDomainManga()!!, source)
|
||||
|
||||
Observable.just(manga).subscribeLatestCache(ReaderActivity::setManga)
|
||||
viewerChaptersRelay.subscribeLatestCache(ReaderActivity::setChapters)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package eu.kanade.tachiyomi.ui.reader.loader
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
|
|
|
@ -3,7 +3,8 @@ package eu.kanade.tachiyomi.ui.reader.loader
|
|||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
|
@ -45,7 +46,7 @@ class DownloadPageLoader(
|
|||
}
|
||||
|
||||
private fun getPagesFromDirectory(): Observable<List<ReaderPage>> {
|
||||
return downloadManager.buildPageList(source, manga, chapter.chapter)
|
||||
return downloadManager.buildPageList(source, manga.toDbManga(), chapter.chapter)
|
||||
.map { pages ->
|
||||
pages.map { page ->
|
||||
ReaderPage(page.index, page.url, page.imageUrl) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.tachiyomi.ui.reader.loader
|
||||
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
|
@ -73,7 +74,7 @@ class HttpPageLoader(
|
|||
.fromAction {
|
||||
// Convert to pages without reader information
|
||||
val pagesToSave = pages.map { Page(it.index, it.url, it.imageUrl) }
|
||||
chapterCache.putPageListToCache(chapter.chapter, pagesToSave)
|
||||
chapterCache.putPageListToCache(chapter.chapter.toDomainChapter()!!, pagesToSave)
|
||||
}
|
||||
.onErrorComplete()
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -86,7 +87,7 @@ class HttpPageLoader(
|
|||
* the local cache, otherwise fallbacks to network.
|
||||
*/
|
||||
override fun getPages(): Observable<List<ReaderPage>> {
|
||||
return Observable.fromCallable { chapterCache.getPageListFromCache(chapter.chapter) }
|
||||
return Observable.fromCallable { chapterCache.getPageListFromCache(chapter.chapter.toDomainChapter()!!) }
|
||||
.onErrorResumeNext { source.fetchPageList(chapter.chapter) }
|
||||
.map { pages ->
|
||||
pages.mapIndexed { index, page ->
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.tachiyomi.ui.reader.viewer
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import kotlin.math.floor
|
||||
|
||||
|
@ -8,7 +9,7 @@ private val pattern = Regex("""\d+""")
|
|||
|
||||
fun hasMissingChapters(higherReaderChapter: ReaderChapter?, lowerReaderChapter: ReaderChapter?): Boolean {
|
||||
if (higherReaderChapter == null || lowerReaderChapter == null) return false
|
||||
return hasMissingChapters(higherReaderChapter.chapter, lowerReaderChapter.chapter)
|
||||
return hasMissingChapters(higherReaderChapter.chapter.toDomainChapter(), lowerReaderChapter.chapter.toDomainChapter())
|
||||
}
|
||||
|
||||
fun hasMissingChapters(higherChapter: Chapter?, lowerChapter: Chapter?): Boolean {
|
||||
|
@ -17,7 +18,7 @@ fun hasMissingChapters(higherChapter: Chapter?, lowerChapter: Chapter?): Boolean
|
|||
if (!pattern.containsMatchIn(higherChapter.name) || !pattern.containsMatchIn(lowerChapter.name)) return false
|
||||
// Check if potential chapter number was recognized as chapter number
|
||||
if (!higherChapter.isRecognizedNumber || !lowerChapter.isRecognizedNumber) return false
|
||||
return hasMissingChapters(higherChapter.chapter_number, lowerChapter.chapter_number)
|
||||
return hasMissingChapters(higherChapter.chapterNumber, lowerChapter.chapterNumber)
|
||||
}
|
||||
|
||||
fun hasMissingChapters(higherChapterNumber: Float, lowerChapterNumber: Float): Boolean {
|
||||
|
@ -27,7 +28,7 @@ fun hasMissingChapters(higherChapterNumber: Float, lowerChapterNumber: Float): B
|
|||
|
||||
fun calculateChapterDifference(higherReaderChapter: ReaderChapter?, lowerReaderChapter: ReaderChapter?): Float {
|
||||
if (higherReaderChapter == null || lowerReaderChapter == null) return 0f
|
||||
return calculateChapterDifference(higherReaderChapter.chapter, lowerReaderChapter.chapter)
|
||||
return calculateChapterDifference(higherReaderChapter.chapter.toDomainChapter(), lowerReaderChapter.chapter.toDomainChapter())
|
||||
}
|
||||
|
||||
fun calculateChapterDifference(higherChapter: Chapter?, lowerChapter: Chapter?): Float {
|
||||
|
@ -36,7 +37,7 @@ fun calculateChapterDifference(higherChapter: Chapter?, lowerChapter: Chapter?):
|
|||
if (!pattern.containsMatchIn(higherChapter.name) || !pattern.containsMatchIn(lowerChapter.name)) return 0f
|
||||
// Check if potential chapter number was recognized as chapter number
|
||||
if (!higherChapter.isRecognizedNumber || !lowerChapter.isRecognizedNumber) return 0f
|
||||
return calculateChapterDifference(higherChapter.chapter_number, lowerChapter.chapter_number)
|
||||
return calculateChapterDifference(higherChapter.chapterNumber, lowerChapter.chapterNumber)
|
||||
}
|
||||
|
||||
fun calculateChapterDifference(higherChapterNumber: Float, lowerChapterNumber: Float): Float {
|
||||
|
|
|
@ -2,7 +2,8 @@ package eu.kanade.tachiyomi.util.chapter
|
|||
|
||||
import eu.kanade.domain.manga.interactor.GetFavorites
|
||||
import eu.kanade.domain.manga.interactor.SetMangaChapterFlags
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.toDbManga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -17,7 +18,7 @@ object ChapterSettingsHelper {
|
|||
* Updates the global Chapter Settings in Preferences.
|
||||
*/
|
||||
fun setGlobalSettings(manga: Manga) {
|
||||
prefs.setChapterSettingsDefault(manga)
|
||||
prefs.setChapterSettingsDefault(manga.toDbManga())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,7 @@ object ChapterSettingsHelper {
|
|||
fun applySettingDefaults(manga: Manga) {
|
||||
launchIO {
|
||||
setMangaChapterFlags.awaitSetAllFlags(
|
||||
mangaId = manga.id!!,
|
||||
mangaId = manga.id,
|
||||
unreadFilter = prefs.filterChapterByRead().toLong(),
|
||||
downloadedFilter = prefs.filterChapterByDownloaded().toLong(),
|
||||
bookmarkedFilter = prefs.filterChapterByBookmarked().toLong(),
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package eu.kanade.tachiyomi.util.chapter
|
||||
|
||||
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
|
||||
import eu.kanade.domain.chapter.model.toDbChapter
|
||||
import eu.kanade.tachiyomi.data.database.models.toDomainManga
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga as DbManga
|
||||
|
||||
/**
|
||||
* Helper method for syncing the list of chapters from the source with the ones from the database.
|
||||
*
|
||||
* @param rawSourceChapters a list of chapters from the source.
|
||||
* @param manga the manga of the chapters.
|
||||
* @param source the source of the chapters.
|
||||
* @return a pair of new insertions and deletions.
|
||||
*/
|
||||
suspend fun syncChaptersWithSource(
|
||||
rawSourceChapters: List<SChapter>,
|
||||
manga: DbManga,
|
||||
source: Source,
|
||||
syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(),
|
||||
): Pair<List<DbChapter>, List<DbChapter>> {
|
||||
val domainManga = manga.toDomainManga() ?: return Pair(emptyList(), emptyList())
|
||||
val (added, deleted) = syncChaptersWithSource.await(rawSourceChapters, domainManga, source)
|
||||
|
||||
val addedDbChapters = added.map { it.toDbChapter() }
|
||||
val deletedDbChapters = deleted.map { it.toDbChapter() }
|
||||
|
||||
return Pair(addedDbChapters, deletedDbChapters)
|
||||
}
|
Loading…
Reference in a new issue