Move more models to domain module
(cherry picked from commit b53e24e0dbd4affd6066a03ce543c3ecc88bdb99) # Conflicts: # app/src/main/java/eu/kanade/data/history/HistoryRepositoryImpl.kt # app/src/main/java/eu/kanade/data/updates/UpdatesMapper.kt # app/src/main/java/eu/kanade/domain/category/interactor/SetDisplayModeForCategory.kt # app/src/main/java/eu/kanade/domain/category/interactor/SetSortModeForCategory.kt # app/src/main/java/eu/kanade/domain/history/repository/HistoryRepository.kt # app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt # app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceToolbar.kt # app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt # app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/MigrateDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt # domain/src/main/java/tachiyomi/domain/history/model/HistoryWithRelations.kt # domain/src/main/java/tachiyomi/domain/updates/model/UpdatesWithRelations.kt
This commit is contained in:
@@ -10,10 +10,17 @@ android {
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(kotlinx.coroutines.bom))
|
||||
implementation(kotlinx.bundles.coroutines)
|
||||
|
||||
implementation(project(":source-api"))
|
||||
|
||||
// SY -->
|
||||
implementation(libs.injekt.core)
|
||||
// SY <--
|
||||
|
||||
testImplementation(libs.junit)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package tachiyomi.domain.history.model
|
||||
|
||||
import java.util.Date
|
||||
|
||||
data class History(
|
||||
val id: Long,
|
||||
val chapterId: Long,
|
||||
val readAt: Date?,
|
||||
val readDuration: Long,
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package tachiyomi.domain.history.model
|
||||
|
||||
import java.util.Date
|
||||
|
||||
data class HistoryUpdate(
|
||||
val chapterId: Long,
|
||||
val readAt: Date,
|
||||
val sessionReadDuration: Long,
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package tachiyomi.domain.history.model
|
||||
|
||||
import tachiyomi.domain.manga.interactor.GetCustomMangaInfo
|
||||
import tachiyomi.domain.manga.model.MangaCover
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
|
||||
data class HistoryWithRelations(
|
||||
val id: Long,
|
||||
val chapterId: Long,
|
||||
val mangaId: Long,
|
||||
// SY -->
|
||||
val ogTitle: String,
|
||||
// SY <--
|
||||
val chapterNumber: Float,
|
||||
val readAt: Date?,
|
||||
val readDuration: Long,
|
||||
val coverData: MangaCover,
|
||||
) {
|
||||
// SY -->
|
||||
val title: String = customMangaManager.get(mangaId)?.title ?: ogTitle
|
||||
|
||||
companion object {
|
||||
private val customMangaManager: GetCustomMangaInfo by injectLazy()
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
interface Flag {
|
||||
val flag: Long
|
||||
}
|
||||
|
||||
interface Mask {
|
||||
val mask: Long
|
||||
}
|
||||
|
||||
interface FlagWithMask : Flag, Mask
|
||||
|
||||
operator fun Long.contains(other: Flag): Boolean {
|
||||
return if (other is Mask) {
|
||||
other.flag == this and other.mask
|
||||
} else {
|
||||
other.flag == this
|
||||
}
|
||||
}
|
||||
|
||||
operator fun Long.plus(other: Flag): Long {
|
||||
return if (other is Mask) {
|
||||
this and other.mask.inv() or (other.flag and other.mask)
|
||||
} else {
|
||||
this or other.flag
|
||||
}
|
||||
}
|
||||
|
||||
operator fun Flag.plus(other: Flag): Long {
|
||||
return if (other is Mask) {
|
||||
this.flag and other.mask.inv() or (other.flag and other.mask)
|
||||
} else {
|
||||
this.flag or other.flag
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
|
||||
sealed class LibraryDisplayMode(
|
||||
override val flag: Long,
|
||||
) : FlagWithMask {
|
||||
|
||||
override val mask: Long = 0b00000011L
|
||||
|
||||
object CompactGrid : LibraryDisplayMode(0b00000000)
|
||||
object ComfortableGrid : LibraryDisplayMode(0b00000001)
|
||||
object List : LibraryDisplayMode(0b00000010)
|
||||
object CoverOnlyGrid : LibraryDisplayMode(0b00000011)
|
||||
|
||||
object Serializer {
|
||||
fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
return LibraryDisplayMode.deserialize(serialized)
|
||||
}
|
||||
|
||||
fun serialize(value: LibraryDisplayMode): String {
|
||||
return value.serialize()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val values = setOf(CompactGrid, ComfortableGrid, List, CoverOnlyGrid)
|
||||
val default = CompactGrid
|
||||
|
||||
fun valueOf(flag: Long?): LibraryDisplayMode {
|
||||
if (flag == null) return default
|
||||
return values
|
||||
.find { mode -> mode.flag == flag and mode.mask }
|
||||
?: default
|
||||
}
|
||||
|
||||
fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
return when (serialized) {
|
||||
"COMFORTABLE_GRID" -> ComfortableGrid
|
||||
"COMPACT_GRID" -> CompactGrid
|
||||
"COVER_ONLY_GRID" -> CoverOnlyGrid
|
||||
"LIST" -> List
|
||||
else -> default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun serialize(): String {
|
||||
return when (this) {
|
||||
ComfortableGrid -> "COMFORTABLE_GRID"
|
||||
CompactGrid -> "COMPACT_GRID"
|
||||
CoverOnlyGrid -> "COVER_ONLY_GRID"
|
||||
List -> "LIST"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Category.display: LibraryDisplayMode
|
||||
get() = LibraryDisplayMode.valueOf(flags)
|
||||
@@ -0,0 +1,127 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
|
||||
data class LibrarySort(
|
||||
val type: Type,
|
||||
val direction: Direction,
|
||||
) : FlagWithMask {
|
||||
|
||||
override val flag: Long
|
||||
get() = type + direction
|
||||
|
||||
override val mask: Long
|
||||
get() = type.mask or direction.mask
|
||||
|
||||
val isAscending: Boolean
|
||||
get() = direction == Direction.Ascending
|
||||
|
||||
sealed class Type(
|
||||
override val flag: Long,
|
||||
) : FlagWithMask {
|
||||
|
||||
override val mask: Long = 0b00111100L
|
||||
|
||||
object Alphabetical : Type(0b00000000)
|
||||
object LastRead : Type(0b00000100)
|
||||
object LastUpdate : Type(0b00001000)
|
||||
object UnreadCount : Type(0b00001100)
|
||||
object TotalChapters : Type(0b00010000)
|
||||
object LatestChapter : Type(0b00010100)
|
||||
object ChapterFetchDate : Type(0b00011000)
|
||||
object DateAdded : Type(0b00011100)
|
||||
|
||||
// SY -->
|
||||
object TagList : Type(0b00100100)
|
||||
// SY <--
|
||||
|
||||
companion object {
|
||||
fun valueOf(flag: Long): Type {
|
||||
return types.find { type -> type.flag == flag and type.mask } ?: default.type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Direction(
|
||||
override val flag: Long,
|
||||
) : FlagWithMask {
|
||||
|
||||
override val mask: Long = 0b01000000L
|
||||
|
||||
object Ascending : Direction(0b01000000)
|
||||
object Descending : Direction(0b00000000)
|
||||
|
||||
companion object {
|
||||
fun valueOf(flag: Long): Direction {
|
||||
return directions.find { direction -> direction.flag == flag and direction.mask } ?: default.direction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Serializer {
|
||||
fun deserialize(serialized: String): LibrarySort {
|
||||
return LibrarySort.deserialize(serialized)
|
||||
}
|
||||
|
||||
fun serialize(value: LibrarySort): String {
|
||||
return value.serialize()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val types = setOf(Type.Alphabetical, Type.LastRead, Type.LastUpdate, Type.UnreadCount, Type.TotalChapters, Type.LatestChapter, Type.ChapterFetchDate, Type.DateAdded)
|
||||
val directions = setOf(Direction.Ascending, Direction.Descending)
|
||||
val default = LibrarySort(Type.Alphabetical, Direction.Ascending)
|
||||
|
||||
fun valueOf(flag: Long): LibrarySort {
|
||||
return LibrarySort(
|
||||
Type.valueOf(flag),
|
||||
Direction.valueOf(flag),
|
||||
)
|
||||
}
|
||||
|
||||
fun deserialize(serialized: String): LibrarySort {
|
||||
if (serialized.isEmpty()) return default
|
||||
return try {
|
||||
val values = serialized.split(",")
|
||||
val type = when (values[0]) {
|
||||
"ALPHABETICAL" -> Type.Alphabetical
|
||||
"LAST_READ" -> Type.LastRead
|
||||
"LAST_MANGA_UPDATE" -> Type.LastUpdate
|
||||
"UNREAD_COUNT" -> Type.UnreadCount
|
||||
"TOTAL_CHAPTERS" -> Type.TotalChapters
|
||||
"LATEST_CHAPTER" -> Type.LatestChapter
|
||||
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
|
||||
"DATE_ADDED" -> Type.DateAdded
|
||||
// SY -->
|
||||
"TAG_LIST" -> Type.TagList
|
||||
// SY <--
|
||||
else -> Type.Alphabetical
|
||||
}
|
||||
val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending
|
||||
LibrarySort(type, ascending)
|
||||
} catch (e: Exception) {
|
||||
default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun serialize(): String {
|
||||
val type = when (type) {
|
||||
Type.Alphabetical -> "ALPHABETICAL"
|
||||
Type.LastRead -> "LAST_READ"
|
||||
Type.LastUpdate -> "LAST_MANGA_UPDATE"
|
||||
Type.UnreadCount -> "UNREAD_COUNT"
|
||||
Type.TotalChapters -> "TOTAL_CHAPTERS"
|
||||
Type.LatestChapter -> "LATEST_CHAPTER"
|
||||
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
|
||||
Type.DateAdded -> "DATE_ADDED"
|
||||
Type.TagList -> "TAG_LIST"
|
||||
}
|
||||
val direction = if (direction == Direction.Ascending) "ASCENDING" else "DESCENDING"
|
||||
return "$type,$direction"
|
||||
}
|
||||
}
|
||||
|
||||
val Category.sort: LibrarySort
|
||||
get() = LibrarySort.valueOf(flags)
|
||||
@@ -0,0 +1,10 @@
|
||||
package tachiyomi.domain.manga.interactor
|
||||
|
||||
import tachiyomi.domain.manga.repository.CustomMangaRepository
|
||||
|
||||
class GetCustomMangaInfo(
|
||||
private val customMangaRepository: CustomMangaRepository,
|
||||
) {
|
||||
|
||||
fun get(mangaId: Long) = customMangaRepository.get(mangaId)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package tachiyomi.domain.manga.interactor
|
||||
|
||||
import tachiyomi.domain.manga.model.CustomMangaInfo
|
||||
import tachiyomi.domain.manga.repository.CustomMangaRepository
|
||||
|
||||
class SetCustomMangaInfo(
|
||||
private val customMangaRepository: CustomMangaRepository,
|
||||
) {
|
||||
|
||||
fun set(mangaInfo: CustomMangaInfo) = customMangaRepository.set(mangaInfo)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package tachiyomi.domain.manga.model
|
||||
|
||||
data class CustomMangaInfo(
|
||||
val id: Long,
|
||||
val title: String?,
|
||||
val author: String? = null,
|
||||
val artist: String? = null,
|
||||
val description: String? = null,
|
||||
val genre: List<String>? = null,
|
||||
val status: Long? = null,
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package tachiyomi.domain.manga.model
|
||||
|
||||
/**
|
||||
* Contains the required data for MangaCoverFetcher
|
||||
*/
|
||||
data class MangaCover(
|
||||
val mangaId: Long,
|
||||
val sourceId: Long,
|
||||
val isMangaFavorite: Boolean,
|
||||
val url: String?,
|
||||
val lastModified: Long,
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package tachiyomi.domain.manga.model
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
|
||||
data class MangaUpdate(
|
||||
val id: Long,
|
||||
val source: Long? = null,
|
||||
val favorite: Boolean? = null,
|
||||
val lastUpdate: Long? = null,
|
||||
val dateAdded: Long? = null,
|
||||
val viewerFlags: Long? = null,
|
||||
val chapterFlags: Long? = null,
|
||||
val coverLastModified: Long? = null,
|
||||
val url: String? = null,
|
||||
val title: String? = null,
|
||||
val artist: String? = null,
|
||||
val author: String? = null,
|
||||
val description: String? = null,
|
||||
val genre: List<String>? = null,
|
||||
val status: Long? = null,
|
||||
val thumbnailUrl: String? = null,
|
||||
val updateStrategy: UpdateStrategy? = null,
|
||||
val initialized: Boolean? = null,
|
||||
// SY -->
|
||||
val filteredScanlators: List<String>? = null,
|
||||
// SY <--
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package tachiyomi.domain.manga.repository
|
||||
|
||||
import tachiyomi.domain.manga.model.CustomMangaInfo
|
||||
|
||||
interface CustomMangaRepository {
|
||||
|
||||
fun get(mangaId: Long): CustomMangaInfo?
|
||||
|
||||
fun set(mangaInfo: CustomMangaInfo)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package tachiyomi.domain.source.model
|
||||
|
||||
data class SourceData(
|
||||
val id: Long,
|
||||
val lang: String,
|
||||
val name: String,
|
||||
) {
|
||||
|
||||
val isMissingInfo: Boolean = name.isBlank() || lang.isBlank()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package tachiyomi.domain.updates.model
|
||||
|
||||
import tachiyomi.domain.manga.interactor.GetCustomMangaInfo
|
||||
import tachiyomi.domain.manga.model.MangaCover
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
data class UpdatesWithRelations(
|
||||
val mangaId: Long,
|
||||
// SY -->
|
||||
val ogMangaTitle: String,
|
||||
// SY <--
|
||||
val chapterId: Long,
|
||||
val chapterName: String,
|
||||
val scanlator: String?,
|
||||
val read: Boolean,
|
||||
val bookmark: Boolean,
|
||||
val lastPageRead: Long,
|
||||
val sourceId: Long,
|
||||
val dateFetch: Long,
|
||||
val coverData: MangaCover,
|
||||
) {
|
||||
// SY -->
|
||||
val mangaTitle: String = getCustomMangaInfo.get(mangaId)?.title ?: ogMangaTitle
|
||||
|
||||
companion object {
|
||||
private val getCustomMangaInfo: GetCustomMangaInfo by injectLazy()
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class LibraryFlagsTest {
|
||||
|
||||
@Test
|
||||
fun `Check the amount of flags`() {
|
||||
assertEquals(4, LibraryDisplayMode.values.size)
|
||||
assertEquals(8, LibrarySort.types.size)
|
||||
assertEquals(2, LibrarySort.directions.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator (LibraryDisplayMode)`() {
|
||||
val current = LibraryDisplayMode.List
|
||||
val new = LibraryDisplayMode.CoverOnlyGrid
|
||||
val flag = current + new
|
||||
|
||||
assertEquals(0b00000011, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator (LibrarySort)`() {
|
||||
val current = LibrarySort(LibrarySort.Type.LastRead, LibrarySort.Direction.Ascending)
|
||||
val new = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
|
||||
val flag = current + new
|
||||
|
||||
assertEquals(0b01011100, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator`() {
|
||||
val display = LibraryDisplayMode.CoverOnlyGrid
|
||||
val sort = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
|
||||
val flag = display + sort
|
||||
|
||||
assertEquals(0b01011111, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator with old flag as base`() {
|
||||
val currentDisplay = LibraryDisplayMode.List
|
||||
val currentSort = LibrarySort(LibrarySort.Type.UnreadCount, LibrarySort.Direction.Descending)
|
||||
val currentFlag = currentDisplay + currentSort
|
||||
|
||||
val display = LibraryDisplayMode.CoverOnlyGrid
|
||||
val sort = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
|
||||
val flag = currentFlag + display + sort
|
||||
|
||||
assertEquals(0b00001110, currentFlag)
|
||||
assertEquals(0b01011111, flag)
|
||||
assertNotEquals(currentFlag, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test default flags`() {
|
||||
val sort = LibrarySort.default
|
||||
val display = LibraryDisplayMode.default
|
||||
val flag = display + sort.type + sort.direction
|
||||
|
||||
assertEquals(0b01000000, flag)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user