Cleanup custom info, fix custom genre not saving if you dont edit it
This commit is contained in:
parent
0a4fcb480d
commit
a17c4c151f
@ -14,16 +14,12 @@ class CustomMangaManager(val context: Context) {
|
|||||||
|
|
||||||
private val editJson = File(context.getExternalFilesDir(null), "edits.json")
|
private val editJson = File(context.getExternalFilesDir(null), "edits.json")
|
||||||
|
|
||||||
private var customMangaMap = mutableMapOf<Long, Manga>()
|
private val customMangaMap = fetchCustomData()
|
||||||
|
|
||||||
init {
|
|
||||||
fetchCustomData()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getManga(manga: Manga): Manga? = customMangaMap[manga.id]
|
fun getManga(manga: Manga): Manga? = customMangaMap[manga.id]
|
||||||
|
|
||||||
private fun fetchCustomData() {
|
private fun fetchCustomData(): MutableMap<Long, Manga> {
|
||||||
if (!editJson.exists() || !editJson.isFile) return
|
if (!editJson.exists() || !editJson.isFile) return mutableMapOf()
|
||||||
|
|
||||||
val json = try {
|
val json = try {
|
||||||
Json.decodeFromString<MangaList>(
|
Json.decodeFromString<MangaList>(
|
||||||
@ -31,10 +27,10 @@ class CustomMangaManager(val context: Context) {
|
|||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
} ?: return
|
} ?: return mutableMapOf()
|
||||||
|
|
||||||
val mangasJson = json.mangas ?: return
|
val mangasJson = json.mangas ?: return mutableMapOf()
|
||||||
customMangaMap = mangasJson.mapNotNull { mangaJson ->
|
return mangasJson.mapNotNull { mangaJson ->
|
||||||
val id = mangaJson.id ?: return@mapNotNull null
|
val id = mangaJson.id ?: return@mapNotNull null
|
||||||
val manga = MangaImpl().apply {
|
val manga = MangaImpl().apply {
|
||||||
this.id = id
|
this.id = id
|
||||||
|
@ -317,7 +317,7 @@ class MangaPresenter(
|
|||||||
LocalSource(downloadManager.context).updateMangaInfo(manga)
|
LocalSource(downloadManager.context).updateMangaInfo(manga)
|
||||||
db.updateMangaInfo(manga).executeAsBlocking()
|
db.updateMangaInfo(manga).executeAsBlocking()
|
||||||
} else {
|
} else {
|
||||||
val genre = if (!tags.isNullOrEmpty() && tags.joinToString() != manga.genre) {
|
val genre = if (!tags.isNullOrEmpty() && tags.joinToString() != manga.originalGenre) {
|
||||||
tags
|
tags
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user