refactor(source/local): Simplify code

This commit is contained in:
Ahmad Ansori Palembani 2024-07-28 14:06:56 +07:00
parent 630e23cff7
commit 4e75e70eee
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -187,28 +187,6 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
if (cover != null && cover.exists()) {
thumbnail_url = cover.uri.toString()
}
val manga = this
val chapters = getChapterList(manga)
if (chapters.isNotEmpty()) {
val chapter = chapters.last()
val format = getFormat(chapter)
if (format is Format.Epub) {
EpubFile(format.file.archiveReader(context)).use { epub ->
epub.fillMangaMetadata(manga)
}
}
// Copy the cover from the first chapter found.
if (thumbnail_url == null) {
try {
val dest = updateCover(chapter, manga)
thumbnail_url = dest?.filePath
} catch (e: Exception) {
Logger.e(e)
}
}
}
}
}
}.awaitAll()
@ -328,6 +306,22 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
}
.toList()
if (manga.thumbnail_url.isNullOrBlank()) {
chapters.lastOrNull()?.let { chapter ->
try {
val format = getFormat(chapter)
if (format is Format.Epub)
EpubFile(format.file.archiveReader(context)).use { epub ->
epub.fillMangaMetadata(manga)
}
// Copy the cover from the first chapter found.
updateCover(chapter, manga)
} catch (e: Exception) {
Logger.e(e)
}
}
}
chapters
}