some fixes for local manga

This commit is contained in:
Jay 2020-05-11 13:08:56 -04:00
parent 51c93bcd55
commit 2c3f8e6b62
3 changed files with 30 additions and 4 deletions

View File

@ -49,7 +49,7 @@ class LocalSource(private val context: Context) : CatalogueSource {
val cover = File("${dir.absolutePath}/${manga.url}", COVER_NAME)
// It might not exist if using the external SD card
cover.parentFile.mkdirs()
cover.parentFile?.mkdirs()
input.use {
cover.outputStream().use {
input.copyTo(it)
@ -140,7 +140,8 @@ class LocalSource(private val context: Context) : CatalogueSource {
override fun fetchLatestUpdates(page: Int) = fetchSearchManga(page, "", LATEST_FILTERS)
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
getBaseDirectories(context).mapNotNull { File(it, manga.url).listFiles()?.toList() }
val baseDirs = getBaseDirectories(context)
baseDirs.mapNotNull { File(it, manga.url).listFiles()?.toList() }
.flatten().filter { it.extension.equals("json") }.firstOrNull()?.apply {
val json = Gson().fromJson(
Scanner(this).useDelimiter("\\Z").next(),
@ -154,6 +155,28 @@ class LocalSource(private val context: Context) : CatalogueSource {
?: manga.genre
manga.status = json["status"]?.asInt ?: manga.status
}
val url = manga.url
// Try to find the cover
for (dir in baseDirs) {
val cover = File("${dir.absolutePath}/$url", COVER_NAME)
if (cover.exists()) {
manga.thumbnail_url = cover.absolutePath
break
}
}
// Copy the cover from the first chapter found.
if (manga.thumbnail_url == null) {
val chapters = fetchChapterList(manga).toBlocking().first()
if (chapters.isNotEmpty()) {
try {
val dest = updateCover(chapters.last(), manga)
manga.thumbnail_url = dest?.absolutePath
} catch (e: Exception) {
Timber.e(e)
}
}
}
return Observable.just(manga)
}

View File

@ -84,7 +84,9 @@ class MangaDetailsPresenter(
downloadManager.addListener(this)
LibraryUpdateService.setListener(this)
tracks = db.getTracks(manga).executeAsBlocking()
if (!manga.initialized) {
if (manga.source == LocalSource.ID) {
refreshAll()
} else if (!manga.initialized) {
isLoading = true
controller.setRefresh(true)
controller.updateHeader()
@ -368,7 +370,7 @@ class MangaDetailsPresenter(
/** Refresh Manga Info and Chapter List (not tracking) */
fun refreshAll() {
if (controller.isNotOnline()) return
if (controller.isNotOnline() && manga.source != LocalSource.ID) return
scope.launch {
isLoading = true
var mangaError: java.lang.Exception? = null

View File

@ -16,6 +16,7 @@
android:id="@+id/manga_cover"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:minWidth="50dp"
android:layout_height="150dp"
android:contentDescription="@string/cover_of_image"
android:background="@drawable/image_border_background"