From 696dc59ea5ebacb5c4fc36b04f3d4125d91385a7 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 3 Dec 2022 22:54:18 -0500 Subject: [PATCH] More domain model migrations --- .../kanade/domain/category/model/Category.kt | 1 - .../domain/library/model/LibrarySort.kt | 2 - .../tachiyomi/data/database/models/Chapter.kt | 6 --- .../tachiyomi/data/database/models/Manga.kt | 37 ------------------- .../data/track/EnhancedTrackService.kt | 7 ++-- .../tachiyomi/data/track/kavita/Kavita.kt | 7 ++-- .../tachiyomi/data/track/komga/Komga.kt | 7 ++-- .../source/browse/BrowseSourceScreenModel.kt | 3 +- .../tachiyomi/ui/manga/MangaScreenModel.kt | 3 +- .../ui/manga/track/TrackInfoDialog.kt | 3 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 28 ++++++-------- 11 files changed, 23 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/category/model/Category.kt b/app/src/main/java/eu/kanade/domain/category/model/Category.kt index fe89f74ae6..742e481d26 100644 --- a/app/src/main/java/eu/kanade/domain/category/model/Category.kt +++ b/app/src/main/java/eu/kanade/domain/category/model/Category.kt @@ -12,7 +12,6 @@ data class Category( val isSystemCategory: Boolean = id == UNCATEGORIZED_ID companion object { - const val UNCATEGORIZED_ID = 0L } } diff --git a/app/src/main/java/eu/kanade/domain/library/model/LibrarySort.kt b/app/src/main/java/eu/kanade/domain/library/model/LibrarySort.kt index b757ff4b9d..e7a74ce86d 100644 --- a/app/src/main/java/eu/kanade/domain/library/model/LibrarySort.kt +++ b/app/src/main/java/eu/kanade/domain/library/model/LibrarySort.kt @@ -32,7 +32,6 @@ data class LibrarySort( object DateAdded : Type(0b00011100) companion object { - fun valueOf(flag: Long): Type { return types.find { type -> type.flag == flag and type.mask } ?: default.type } @@ -49,7 +48,6 @@ data class LibrarySort( object Descending : Direction(0b00000000) companion object { - fun valueOf(flag: Long): Direction { return directions.find { direction -> direction.flag == flag and direction.mask } ?: default.direction } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.kt index 90bbfdce95..771ebb32ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.kt @@ -19,12 +19,6 @@ interface Chapter : SChapter, Serializable { var date_fetch: Long var source_order: Int - - companion object { - fun create(): Chapter = ChapterImpl().apply { - chapter_number = -1f - } - } } fun Chapter.toDomainChapter(): DomainChapter? { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index c4894636eb..e356129486 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -24,39 +24,10 @@ interface Manga : SManga { var cover_last_modified: Long - fun sortDescending(): Boolean { - return chapter_flags and DomainManga.CHAPTER_SORT_DIR_MASK.toInt() == DomainManga.CHAPTER_SORT_DESC.toInt() - } - - private fun setChapterFlags(flag: Int, mask: Int) { - chapter_flags = chapter_flags and mask.inv() or (flag and mask) - } - private fun setViewerFlags(flag: Int, mask: Int) { viewer_flags = viewer_flags and mask.inv() or (flag and mask) } - // Used to display the chapter's title one way or another - var displayMode: Int - get() = chapter_flags and DomainManga.CHAPTER_DISPLAY_MASK.toInt() - set(mode) = setChapterFlags(mode, DomainManga.CHAPTER_DISPLAY_MASK.toInt()) - - var readFilter: Int - get() = chapter_flags and DomainManga.CHAPTER_UNREAD_MASK.toInt() - set(filter) = setChapterFlags(filter, DomainManga.CHAPTER_UNREAD_MASK.toInt()) - - var downloadedFilter: Int - get() = chapter_flags and DomainManga.CHAPTER_DOWNLOADED_MASK.toInt() - set(filter) = setChapterFlags(filter, DomainManga.CHAPTER_DOWNLOADED_MASK.toInt()) - - var bookmarkedFilter: Int - get() = chapter_flags and DomainManga.CHAPTER_BOOKMARKED_MASK.toInt() - set(filter) = setChapterFlags(filter, DomainManga.CHAPTER_BOOKMARKED_MASK.toInt()) - - var sorting: Int - get() = chapter_flags and DomainManga.CHAPTER_SORTING_MASK.toInt() - set(sort) = setChapterFlags(sort, DomainManga.CHAPTER_SORTING_MASK.toInt()) - var readingModeType: Int get() = viewer_flags and ReadingModeType.MASK set(readingMode) = setViewerFlags(readingMode, ReadingModeType.MASK) @@ -64,14 +35,6 @@ interface Manga : SManga { var orientationType: Int get() = viewer_flags and OrientationType.MASK set(rotationType) = setViewerFlags(rotationType, OrientationType.MASK) - - companion object { - fun create(pathUrl: String, title: String, source: Long = 0): Manga = MangaImpl().apply { - url = pathUrl - this.title = title - this.source = source - } - } } fun Manga.toDomainManga(): DomainManga? { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt index 4c47ba67cc..21d1ee3326 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt @@ -1,10 +1,9 @@ package eu.kanade.tachiyomi.data.track +import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.track.model.Track -import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source -import eu.kanade.domain.manga.model.Manga as DomainManga /** * An Enhanced Track Service will never prompt the user to match a manga with the remote. @@ -31,10 +30,10 @@ interface EnhancedTrackService { /** * Checks whether the provided source/track/manga triplet is from this TrackService */ - fun isTrackFrom(track: Track, manga: DomainManga, source: Source?): Boolean + fun isTrackFrom(track: Track, manga: Manga, source: Source?): Boolean /** * Migrates the given track for the manga to the newSource, if possible */ - fun migrateTrack(track: Track, manga: DomainManga, newSource: Source): Track? + fun migrateTrack(track: Track, manga: Manga, newSource: Source): Track? } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt index f719c1a45e..f130fb2b33 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt @@ -4,8 +4,8 @@ import android.content.Context import android.content.SharedPreferences import android.graphics.Color import androidx.annotation.StringRes +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.database.models.Track import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.NoLoginTrackService @@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source import java.security.MessageDigest -import eu.kanade.domain.manga.model.Manga as DomainManga import eu.kanade.domain.track.model.Track as DomainTrack class Kavita(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService, NoLoginTrackService { @@ -104,10 +103,10 @@ class Kavita(private val context: Context, id: Long) : TrackService(id), Enhance null } - override fun isTrackFrom(track: DomainTrack, manga: DomainManga, source: Source?): Boolean = + override fun isTrackFrom(track: DomainTrack, manga: Manga, source: Source?): Boolean = track.remoteUrl == manga.url && source?.let { accept(it) } == true - override fun migrateTrack(track: DomainTrack, manga: DomainManga, newSource: Source): DomainTrack? = + override fun migrateTrack(track: DomainTrack, manga: Manga, newSource: Source): DomainTrack? = if (accept(newSource)) { track.copy(remoteUrl = manga.url) } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 454be6d918..1c918acd76 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.data.track.komga import android.content.Context import android.graphics.Color import androidx.annotation.StringRes +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.database.models.Track import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.NoLoginTrackService @@ -13,7 +13,6 @@ import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source import okhttp3.Dns import okhttp3.OkHttpClient -import eu.kanade.domain.manga.model.Manga as DomainManga import eu.kanade.domain.track.model.Track as DomainTrack class Komga(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService, NoLoginTrackService { @@ -107,10 +106,10 @@ class Komga(private val context: Context, id: Long) : TrackService(id), Enhanced null } - override fun isTrackFrom(track: DomainTrack, manga: DomainManga, source: Source?): Boolean = + override fun isTrackFrom(track: DomainTrack, manga: Manga, source: Source?): Boolean = track.remoteUrl == manga.url && source?.let { accept(it) } == true - override fun migrateTrack(track: DomainTrack, manga: DomainManga, newSource: Source): DomainTrack? = + override fun migrateTrack(track: DomainTrack, manga: Manga, newSource: Source): DomainTrack? = if (accept(newSource)) { track.copy(remoteUrl = manga.url) } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index 252a58de93..86a97bfc81 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -30,7 +30,6 @@ 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 import eu.kanade.domain.source.interactor.GetRemoteManga @@ -309,7 +308,7 @@ class BrowseSourceScreenModel( .filter { it.accept(source) } .forEach { service -> try { - service.match(manga.toDbManga())?.let { track -> + service.match(manga)?.let { track -> track.manga_id = manga.id (service as TrackService).bind(track) insertTrack.await(track.toDomainTrack()!!) 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 28b19548dd..56f95419ea 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 @@ -29,7 +29,6 @@ import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.TriStateFilter import eu.kanade.domain.manga.model.isLocal -import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.ui.UiPreferences @@ -344,7 +343,7 @@ class MangaInfoScreenModel( .forEach { service -> launchIO { try { - service.match(manga.toDbManga())?.let { track -> + service.match(manga)?.let { track -> (service as TrackService).registerTracking(track, mangaId) } } catch (e: Exception) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt index be6249c6ca..54161d4693 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt @@ -38,7 +38,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.GetMangaWithChapters -import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.track.interactor.DeleteTrack import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack @@ -211,7 +210,7 @@ data class TrackInfoDialogHomeScreen( fun registerEnhancedTracking(item: TrackItem) { item.service as EnhancedTrackService coroutineScope.launchNonCancellable { - val manga = Injekt.get().await(mangaId)?.toDbManga() ?: return@launchNonCancellable + val manga = Injekt.get().await(mangaId) ?: return@launchNonCancellable try { val matchResult = item.service.match(manga) ?: throw Exception() item.service.registerTracking(matchResult, mangaId) 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 862afa4724..c8b07a2271 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 @@ -149,8 +149,8 @@ class ReaderPresenter( * time in a background thread to avoid blocking the UI. */ private val chapterList by lazy { - val manga = manga!! - val chapters = runBlocking { getChapterByMangaId.await(manga.id!!) } + val manga = manga!!.toDomainManga()!! + val chapters = runBlocking { getChapterByMangaId.await(manga.id) } val selectedChapter = chapters.find { it.id == chapterId } ?: error("Requested chapter of id $chapterId not found in chapter list") @@ -161,12 +161,12 @@ class ReaderPresenter( when { readerPreferences.skipRead().get() && it.read -> true readerPreferences.skipFiltered().get() -> { - (manga.readFilter == DomainManga.CHAPTER_SHOW_READ.toInt() && !it.read) || - (manga.readFilter == DomainManga.CHAPTER_SHOW_UNREAD.toInt() && it.read) || - (manga.downloadedFilter == DomainManga.CHAPTER_SHOW_DOWNLOADED.toInt() && !downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) || - (manga.downloadedFilter == DomainManga.CHAPTER_SHOW_NOT_DOWNLOADED.toInt() && downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) || - (manga.bookmarkedFilter == DomainManga.CHAPTER_SHOW_BOOKMARKED.toInt() && !it.bookmark) || - (manga.bookmarkedFilter == DomainManga.CHAPTER_SHOW_NOT_BOOKMARKED.toInt() && it.bookmark) + (manga.unreadFilterRaw == DomainManga.CHAPTER_SHOW_READ && !it.read) || + (manga.unreadFilterRaw == DomainManga.CHAPTER_SHOW_UNREAD && it.read) || + (manga.downloadedFilterRaw == DomainManga.CHAPTER_SHOW_DOWNLOADED && !downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) || + (manga.downloadedFilterRaw == DomainManga.CHAPTER_SHOW_NOT_DOWNLOADED && downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) || + (manga.bookmarkedFilterRaw == DomainManga.CHAPTER_SHOW_BOOKMARKED && !it.bookmark) || + (manga.bookmarkedFilterRaw == DomainManga.CHAPTER_SHOW_NOT_BOOKMARKED && it.bookmark) } else -> false } @@ -182,7 +182,7 @@ class ReaderPresenter( } chaptersForReader - .sortedWith(getChapterSort(manga.toDomainManga()!!, sortDescending = false)) + .sortedWith(getChapterSort(manga, sortDescending = false)) .map { it.toDbChapter() } .map(::ReaderChapter) } @@ -653,11 +653,9 @@ class ReaderPresenter( fun setMangaReadingMode(readingModeType: Int) { val manga = manga ?: return manga.readingModeType = readingModeType - runBlocking { - setMangaViewerFlags.awaitSetMangaReadingMode(manga.id!!.toLong(), readingModeType.toLong()) - } coroutineScope.launchIO { + setMangaViewerFlags.awaitSetMangaReadingMode(manga.id!!.toLong(), readingModeType.toLong()) delay(250) val currChapters = viewerChaptersRelay.value if (currChapters != null) { @@ -692,13 +690,9 @@ class ReaderPresenter( fun setMangaOrientationType(rotationType: Int) { val manga = manga ?: return manga.orientationType = rotationType - runBlocking { - setMangaViewerFlags.awaitSetOrientationType(manga.id!!.toLong(), rotationType.toLong()) - } - - logcat(LogPriority.INFO) { "Manga orientation is ${manga.orientationType}" } coroutineScope.launchIO { + setMangaViewerFlags.awaitSetOrientationType(manga.id!!.toLong(), rotationType.toLong()) delay(250) val currChapters = viewerChaptersRelay.value if (currChapters != null) {