Support edited manga info in domain

This commit is contained in:
Jobobby04 2022-06-04 11:31:11 -04:00
parent 0259da5648
commit 46bf8b58b5
7 changed files with 122 additions and 51 deletions

View File

@ -19,7 +19,9 @@ val historyWithRelationsMapper: (Long, Long, Long, String, String?, Float, Date?
id = historyId,
chapterId = chapterId,
mangaId = mangaId,
title = title,
// SY -->
ogTitle = title,
// SY <--
thumbnailUrl = thumbnailUrl ?: "",
chapterNumber = chapterNumber,
readAt = readAt,

View File

@ -14,12 +14,14 @@ val mangaMapper: (Long, Long, String, String?, String?, String?, List<String>?,
chapterFlags = chapterFlags,
coverLastModified = coverLastModified,
url = url,
title = title,
artist = artist,
author = author,
description = description,
genre = genre,
status = status,
// SY -->
ogTitle = title,
ogArtist = artist,
ogAuthor = author,
ogDescription = description,
ogGenre = genre,
ogStatus = status,
// SY <--
thumbnailUrl = thumbnailUrl,
initialized = initialized,
filteredScanlators = filteredScanlators,

View File

@ -1,14 +1,26 @@
package eu.kanade.domain.history.model
import eu.kanade.tachiyomi.data.library.CustomMangaManager
import uy.kohesive.injekt.injectLazy
import java.util.Date
data class HistoryWithRelations(
val id: Long,
val chapterId: Long,
val mangaId: Long,
val title: String,
// SY -->
val ogTitle: String,
// SY <--
val thumbnailUrl: String,
val chapterNumber: Float,
val readAt: Date?,
val readDuration: Long,
)
) {
// SY -->
val title: String = customMangaManager.getManga(mangaId)?.title ?: ogTitle
companion object {
private val customMangaManager: CustomMangaManager by injectLazy()
}
// SY <--
}

View File

@ -1,5 +1,8 @@
package eu.kanade.domain.manga.model
import eu.kanade.tachiyomi.data.library.CustomMangaManager
import uy.kohesive.injekt.injectLazy
data class Manga(
val id: Long,
val source: Long,
@ -10,12 +13,14 @@ data class Manga(
val chapterFlags: Long,
val coverLastModified: Long,
val url: String,
val title: String,
val artist: String?,
val author: String?,
val description: String?,
val genre: List<String>?,
val status: Long,
// SY -->
val ogTitle: String,
val ogArtist: String?,
val ogAuthor: String?,
val ogDescription: String?,
val ogGenre: List<String>?,
val ogStatus: Long,
// SY <--
val thumbnailUrl: String?,
val initialized: Boolean,
// SY -->
@ -23,6 +28,30 @@ data class Manga(
// 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
get() = chapterFlags and CHAPTER_SORTING_MASK
@ -35,5 +64,9 @@ data class Manga(
const val CHAPTER_SORTING_NUMBER = 0x00000100L
const val CHAPTER_SORTING_UPLOAD_DATE = 0x00000200L
const val CHAPTER_SORTING_MASK = 0x00000300L
// SY -->
private val customMangaManager: CustomMangaManager by injectLazy()
// SY <--
}
}

View File

@ -135,8 +135,8 @@ data class BackupManga(
backupManga.customArtist = it.artist
backupManga.customAuthor = it.author
backupManga.customDescription = it.description
backupManga.customGenre = it.getGenres()
backupManga.customStatus = it.status
backupManga.customGenre = it.genre
backupManga.customStatus = it.status ?: 0
}
}
// SY <--

View File

@ -12,10 +12,12 @@ open class MangaImpl : Manga {
override lateinit var url: String
// SY -->
private val customManga: CustomMangaManager.CustomMangaInfo?
get() = customMangaManager.getManga(this)
override var title: String
get() = if (favorite) {
val customTitle = customMangaManager.getManga(this)?.title
if (customTitle.isNullOrBlank()) ogTitle else customTitle
customManga?.title ?: ogTitle
} else {
ogTitle
}
@ -24,23 +26,23 @@ open class MangaImpl : Manga {
}
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 }
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 }
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 }
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 }
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 }
// SY <--

View File

@ -2,12 +2,12 @@ package eu.kanade.tachiyomi.data.library
import android.content.Context
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaImpl
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File
import eu.kanade.domain.manga.model.Manga as DomainManga
class CustomMangaManager(val context: Context) {
@ -15,9 +15,11 @@ class CustomMangaManager(val context: Context) {
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()
val json = try {
@ -29,10 +31,13 @@ class CustomMangaManager(val context: Context) {
} ?: return mutableMapOf()
val mangasJson = json.mangas ?: return mutableMapOf()
return mangasJson.mapNotNull { mangaJson ->
val id = mangaJson.id ?: return@mapNotNull null
id to mangaJson.toManga()
}.toMap().toMutableMap()
return mangasJson
.mapNotNull { mangaJson ->
val id = mangaJson.id ?: return@mapNotNull null
id to mangaJson.toManga()
}
.toMap()
.toMutableMap()
}
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
data class MangaList(
val mangas: List<MangaJson>? = null,
@ -87,14 +80,41 @@ class CustomMangaManager(val context: Context) {
val status: Int? = null,
) {
fun toManga() = MangaImpl().apply {
id = this@MangaJson.id
title = this@MangaJson.title ?: ""
author = this@MangaJson.author
artist = this@MangaJson.artist
description = this@MangaJson.description
genre = this@MangaJson.genre?.joinToString(", ")
status = this@MangaJson.status ?: 0
fun toManga() = CustomMangaInfo(
id = this@MangaJson.id!!,
title = this@MangaJson.title?.takeUnless { it.isBlank() },
author = this@MangaJson.author,
artist = this@MangaJson.artist,
description = this@MangaJson.description,
genre = this@MangaJson.genre,
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,
)
}
}
}