mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(source/local): Simplify code
This commit is contained in:
parent
630e23cff7
commit
4e75e70eee
1 changed files with 16 additions and 22 deletions
|
@ -187,28 +187,6 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
||||||
if (cover != null && cover.exists()) {
|
if (cover != null && cover.exists()) {
|
||||||
thumbnail_url = cover.uri.toString()
|
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()
|
}.awaitAll()
|
||||||
|
@ -328,6 +306,22 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
||||||
}
|
}
|
||||||
.toList()
|
.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
|
chapters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue