More domain model migrations

This commit is contained in:
arkon 2022-12-03 22:54:18 -05:00
parent 5f6666a438
commit 696dc59ea5
11 changed files with 23 additions and 81 deletions

View file

@ -12,7 +12,6 @@ data class Category(
val isSystemCategory: Boolean = id == UNCATEGORIZED_ID
companion object {
const val UNCATEGORIZED_ID = 0L
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<GetManga>().await(mangaId)?.toDbManga() ?: return@launchNonCancellable
val manga = Injekt.get<GetManga>().await(mangaId) ?: return@launchNonCancellable
try {
val matchResult = item.service.match(manga) ?: throw Exception()
item.service.registerTracking(matchResult, mangaId)

View file

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