Support edited manga info in domain
This commit is contained in:
parent
0259da5648
commit
46bf8b58b5
@ -19,7 +19,9 @@ val historyWithRelationsMapper: (Long, Long, Long, String, String?, Float, Date?
|
|||||||
id = historyId,
|
id = historyId,
|
||||||
chapterId = chapterId,
|
chapterId = chapterId,
|
||||||
mangaId = mangaId,
|
mangaId = mangaId,
|
||||||
title = title,
|
// SY -->
|
||||||
|
ogTitle = title,
|
||||||
|
// SY <--
|
||||||
thumbnailUrl = thumbnailUrl ?: "",
|
thumbnailUrl = thumbnailUrl ?: "",
|
||||||
chapterNumber = chapterNumber,
|
chapterNumber = chapterNumber,
|
||||||
readAt = readAt,
|
readAt = readAt,
|
||||||
|
@ -14,12 +14,14 @@ val mangaMapper: (Long, Long, String, String?, String?, String?, List<String>?,
|
|||||||
chapterFlags = chapterFlags,
|
chapterFlags = chapterFlags,
|
||||||
coverLastModified = coverLastModified,
|
coverLastModified = coverLastModified,
|
||||||
url = url,
|
url = url,
|
||||||
title = title,
|
// SY -->
|
||||||
artist = artist,
|
ogTitle = title,
|
||||||
author = author,
|
ogArtist = artist,
|
||||||
description = description,
|
ogAuthor = author,
|
||||||
genre = genre,
|
ogDescription = description,
|
||||||
status = status,
|
ogGenre = genre,
|
||||||
|
ogStatus = status,
|
||||||
|
// SY <--
|
||||||
thumbnailUrl = thumbnailUrl,
|
thumbnailUrl = thumbnailUrl,
|
||||||
initialized = initialized,
|
initialized = initialized,
|
||||||
filteredScanlators = filteredScanlators,
|
filteredScanlators = filteredScanlators,
|
||||||
|
@ -1,14 +1,26 @@
|
|||||||
package eu.kanade.domain.history.model
|
package eu.kanade.domain.history.model
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.data.library.CustomMangaManager
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
data class HistoryWithRelations(
|
data class HistoryWithRelations(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val chapterId: Long,
|
val chapterId: Long,
|
||||||
val mangaId: Long,
|
val mangaId: Long,
|
||||||
val title: String,
|
// SY -->
|
||||||
|
val ogTitle: String,
|
||||||
|
// SY <--
|
||||||
val thumbnailUrl: String,
|
val thumbnailUrl: String,
|
||||||
val chapterNumber: Float,
|
val chapterNumber: Float,
|
||||||
val readAt: Date?,
|
val readAt: Date?,
|
||||||
val readDuration: Long,
|
val readDuration: Long,
|
||||||
)
|
) {
|
||||||
|
// SY -->
|
||||||
|
val title: String = customMangaManager.getManga(mangaId)?.title ?: ogTitle
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val customMangaManager: CustomMangaManager by injectLazy()
|
||||||
|
}
|
||||||
|
// SY <--
|
||||||
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package eu.kanade.domain.manga.model
|
package eu.kanade.domain.manga.model
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.data.library.CustomMangaManager
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
data class Manga(
|
data class Manga(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val source: Long,
|
val source: Long,
|
||||||
@ -10,12 +13,14 @@ data class Manga(
|
|||||||
val chapterFlags: Long,
|
val chapterFlags: Long,
|
||||||
val coverLastModified: Long,
|
val coverLastModified: Long,
|
||||||
val url: String,
|
val url: String,
|
||||||
val title: String,
|
// SY -->
|
||||||
val artist: String?,
|
val ogTitle: String,
|
||||||
val author: String?,
|
val ogArtist: String?,
|
||||||
val description: String?,
|
val ogAuthor: String?,
|
||||||
val genre: List<String>?,
|
val ogDescription: String?,
|
||||||
val status: Long,
|
val ogGenre: List<String>?,
|
||||||
|
val ogStatus: Long,
|
||||||
|
// SY <--
|
||||||
val thumbnailUrl: String?,
|
val thumbnailUrl: String?,
|
||||||
val initialized: Boolean,
|
val initialized: Boolean,
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -23,6 +28,30 @@ data class Manga(
|
|||||||
// SY <--
|
// SY <--
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
// SY -->
|
||||||
|
private val customMangaInfo = if (favorite) {
|
||||||
|
customMangaManager.getManga(this)
|
||||||
|
} else null
|
||||||
|
|
||||||
|
val title: String
|
||||||
|
get() = customMangaInfo?.title ?: ogTitle
|
||||||
|
|
||||||
|
val author: String?
|
||||||
|
get() = customMangaInfo?.author ?: ogAuthor
|
||||||
|
|
||||||
|
val artist: String?
|
||||||
|
get() = customMangaInfo?.artist ?: ogArtist
|
||||||
|
|
||||||
|
val description: String?
|
||||||
|
get() = customMangaInfo?.description ?: ogDescription
|
||||||
|
|
||||||
|
val genre: List<String>?
|
||||||
|
get() = customMangaInfo?.genre ?: ogGenre
|
||||||
|
|
||||||
|
val status: Long
|
||||||
|
get() = customMangaInfo?.statusLong ?: ogStatus
|
||||||
|
// SY <--
|
||||||
|
|
||||||
val sorting: Long
|
val sorting: Long
|
||||||
get() = chapterFlags and CHAPTER_SORTING_MASK
|
get() = chapterFlags and CHAPTER_SORTING_MASK
|
||||||
|
|
||||||
@ -35,5 +64,9 @@ data class Manga(
|
|||||||
const val CHAPTER_SORTING_NUMBER = 0x00000100L
|
const val CHAPTER_SORTING_NUMBER = 0x00000100L
|
||||||
const val CHAPTER_SORTING_UPLOAD_DATE = 0x00000200L
|
const val CHAPTER_SORTING_UPLOAD_DATE = 0x00000200L
|
||||||
const val CHAPTER_SORTING_MASK = 0x00000300L
|
const val CHAPTER_SORTING_MASK = 0x00000300L
|
||||||
|
|
||||||
|
// SY -->
|
||||||
|
private val customMangaManager: CustomMangaManager by injectLazy()
|
||||||
|
// SY <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,8 @@ data class BackupManga(
|
|||||||
backupManga.customArtist = it.artist
|
backupManga.customArtist = it.artist
|
||||||
backupManga.customAuthor = it.author
|
backupManga.customAuthor = it.author
|
||||||
backupManga.customDescription = it.description
|
backupManga.customDescription = it.description
|
||||||
backupManga.customGenre = it.getGenres()
|
backupManga.customGenre = it.genre
|
||||||
backupManga.customStatus = it.status
|
backupManga.customStatus = it.status ?: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
|
@ -12,10 +12,12 @@ open class MangaImpl : Manga {
|
|||||||
override lateinit var url: String
|
override lateinit var url: String
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
|
private val customManga: CustomMangaManager.CustomMangaInfo?
|
||||||
|
get() = customMangaManager.getManga(this)
|
||||||
|
|
||||||
override var title: String
|
override var title: String
|
||||||
get() = if (favorite) {
|
get() = if (favorite) {
|
||||||
val customTitle = customMangaManager.getManga(this)?.title
|
customManga?.title ?: ogTitle
|
||||||
if (customTitle.isNullOrBlank()) ogTitle else customTitle
|
|
||||||
} else {
|
} else {
|
||||||
ogTitle
|
ogTitle
|
||||||
}
|
}
|
||||||
@ -24,23 +26,23 @@ open class MangaImpl : Manga {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var author: String?
|
override var author: String?
|
||||||
get() = if (favorite) customMangaManager.getManga(this)?.author ?: ogAuthor else ogAuthor
|
get() = if (favorite) customManga?.author ?: ogAuthor else ogAuthor
|
||||||
set(value) { ogAuthor = value }
|
set(value) { ogAuthor = value }
|
||||||
|
|
||||||
override var artist: String?
|
override var artist: String?
|
||||||
get() = if (favorite) customMangaManager.getManga(this)?.artist ?: ogArtist else ogArtist
|
get() = if (favorite) customManga?.artist ?: ogArtist else ogArtist
|
||||||
set(value) { ogArtist = value }
|
set(value) { ogArtist = value }
|
||||||
|
|
||||||
override var description: String?
|
override var description: String?
|
||||||
get() = if (favorite) customMangaManager.getManga(this)?.description ?: ogDesc else ogDesc
|
get() = if (favorite) customManga?.description ?: ogDesc else ogDesc
|
||||||
set(value) { ogDesc = value }
|
set(value) { ogDesc = value }
|
||||||
|
|
||||||
override var genre: String?
|
override var genre: String?
|
||||||
get() = if (favorite) customMangaManager.getManga(this)?.genre ?: ogGenre else ogGenre
|
get() = if (favorite) customManga?.genreString ?: ogGenre else ogGenre
|
||||||
set(value) { ogGenre = value }
|
set(value) { ogGenre = value }
|
||||||
|
|
||||||
override var status: Int
|
override var status: Int
|
||||||
get() = if (favorite) customMangaManager.getManga(this)?.status?.takeUnless { it == 0 } ?: ogStatus else ogStatus
|
get() = if (favorite) customManga?.status ?: ogStatus else ogStatus
|
||||||
set(value) { ogStatus = value }
|
set(value) { ogStatus = value }
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ package eu.kanade.tachiyomi.data.library
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import eu.kanade.domain.manga.model.Manga as DomainManga
|
||||||
|
|
||||||
class CustomMangaManager(val context: Context) {
|
class CustomMangaManager(val context: Context) {
|
||||||
|
|
||||||
@ -15,9 +15,11 @@ class CustomMangaManager(val context: Context) {
|
|||||||
|
|
||||||
private val customMangaMap = fetchCustomData()
|
private val customMangaMap = fetchCustomData()
|
||||||
|
|
||||||
fun getManga(manga: Manga): Manga? = customMangaMap[manga.id]
|
fun getManga(manga: Manga): CustomMangaInfo? = customMangaMap[manga.id]
|
||||||
|
fun getManga(manga: DomainManga): CustomMangaInfo? = customMangaMap[manga.id]
|
||||||
|
fun getManga(mangaId: Long): CustomMangaInfo? = customMangaMap[mangaId]
|
||||||
|
|
||||||
private fun fetchCustomData(): MutableMap<Long, Manga> {
|
private fun fetchCustomData(): MutableMap<Long, CustomMangaInfo> {
|
||||||
if (!editJson.exists() || !editJson.isFile) return mutableMapOf()
|
if (!editJson.exists() || !editJson.isFile) return mutableMapOf()
|
||||||
|
|
||||||
val json = try {
|
val json = try {
|
||||||
@ -29,10 +31,13 @@ class CustomMangaManager(val context: Context) {
|
|||||||
} ?: return mutableMapOf()
|
} ?: return mutableMapOf()
|
||||||
|
|
||||||
val mangasJson = json.mangas ?: return mutableMapOf()
|
val mangasJson = json.mangas ?: return mutableMapOf()
|
||||||
return mangasJson.mapNotNull { mangaJson ->
|
return mangasJson
|
||||||
|
.mapNotNull { mangaJson ->
|
||||||
val id = mangaJson.id ?: return@mapNotNull null
|
val id = mangaJson.id ?: return@mapNotNull null
|
||||||
id to mangaJson.toManga()
|
id to mangaJson.toManga()
|
||||||
}.toMap().toMutableMap()
|
}
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveMangaInfo(manga: MangaJson) {
|
fun saveMangaInfo(manga: MangaJson) {
|
||||||
@ -59,18 +64,6 @@ class CustomMangaManager(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Manga.toJson(): MangaJson {
|
|
||||||
return MangaJson(
|
|
||||||
id!!,
|
|
||||||
title,
|
|
||||||
author,
|
|
||||||
artist,
|
|
||||||
description,
|
|
||||||
genre?.split(", "),
|
|
||||||
status,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MangaList(
|
data class MangaList(
|
||||||
val mangas: List<MangaJson>? = null,
|
val mangas: List<MangaJson>? = null,
|
||||||
@ -87,14 +80,41 @@ class CustomMangaManager(val context: Context) {
|
|||||||
val status: Int? = null,
|
val status: Int? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun toManga() = MangaImpl().apply {
|
fun toManga() = CustomMangaInfo(
|
||||||
id = this@MangaJson.id
|
id = this@MangaJson.id!!,
|
||||||
title = this@MangaJson.title ?: ""
|
title = this@MangaJson.title?.takeUnless { it.isBlank() },
|
||||||
author = this@MangaJson.author
|
author = this@MangaJson.author,
|
||||||
artist = this@MangaJson.artist
|
artist = this@MangaJson.artist,
|
||||||
description = this@MangaJson.description
|
description = this@MangaJson.description,
|
||||||
genre = this@MangaJson.genre?.joinToString(", ")
|
genre = this@MangaJson.genre,
|
||||||
status = this@MangaJson.status ?: 0
|
status = this@MangaJson.status?.takeUnless { it == 0 },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CustomMangaInfo(
|
||||||
|
var id: Long,
|
||||||
|
val title: String?,
|
||||||
|
val author: String? = null,
|
||||||
|
val artist: String? = null,
|
||||||
|
val description: String? = null,
|
||||||
|
val genre: List<String>? = null,
|
||||||
|
val status: Int? = null,
|
||||||
|
) {
|
||||||
|
val genreString by lazy {
|
||||||
|
genre?.joinToString()
|
||||||
|
}
|
||||||
|
val statusLong = status?.toLong()
|
||||||
|
|
||||||
|
fun toJson(): MangaJson {
|
||||||
|
return MangaJson(
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
author,
|
||||||
|
artist,
|
||||||
|
description,
|
||||||
|
genre,
|
||||||
|
status,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user