Cleanup custom info, fix custom genre not saving if you dont edit it

This commit is contained in:
Jobobby04 2021-01-20 21:00:58 -05:00
parent 0a4fcb480d
commit a17c4c151f
2 changed files with 7 additions and 11 deletions

View File

@ -14,16 +14,12 @@ class CustomMangaManager(val context: Context) {
private val editJson = File(context.getExternalFilesDir(null), "edits.json")
private var customMangaMap = mutableMapOf<Long, Manga>()
init {
fetchCustomData()
}
private val customMangaMap = fetchCustomData()
fun getManga(manga: Manga): Manga? = customMangaMap[manga.id]
private fun fetchCustomData() {
if (!editJson.exists() || !editJson.isFile) return
private fun fetchCustomData(): MutableMap<Long, Manga> {
if (!editJson.exists() || !editJson.isFile) return mutableMapOf()
val json = try {
Json.decodeFromString<MangaList>(
@ -31,10 +27,10 @@ class CustomMangaManager(val context: Context) {
)
} catch (e: Exception) {
null
} ?: return
} ?: return mutableMapOf()
val mangasJson = json.mangas ?: return
customMangaMap = mangasJson.mapNotNull { mangaJson ->
val mangasJson = json.mangas ?: return mutableMapOf()
return mangasJson.mapNotNull { mangaJson ->
val id = mangaJson.id ?: return@mapNotNull null
val manga = MangaImpl().apply {
this.id = id

View File

@ -317,7 +317,7 @@ class MangaPresenter(
LocalSource(downloadManager.context).updateMangaInfo(manga)
db.updateMangaInfo(manga).executeAsBlocking()
} else {
val genre = if (!tags.isNullOrEmpty() && tags.joinToString() != manga.genre) {
val genre = if (!tags.isNullOrEmpty() && tags.joinToString() != manga.originalGenre) {
tags
} else {
null