From 2c3f8e6b62ac63fb3c2caaadbeca4489d05d78e4 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 11 May 2020 13:08:56 -0400 Subject: [PATCH] some fixes for local manga --- .../eu/kanade/tachiyomi/source/LocalSource.kt | 27 +++++++++++++++++-- .../ui/manga/MangaDetailsPresenter.kt | 6 +++-- app/src/main/res/layout/edit_manga_dialog.xml | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 2f03295530..39b35682ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -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 { - 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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index a034c41638..d30fc46ca1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -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 diff --git a/app/src/main/res/layout/edit_manga_dialog.xml b/app/src/main/res/layout/edit_manga_dialog.xml index fce6f57abf..8e40120de7 100644 --- a/app/src/main/res/layout/edit_manga_dialog.xml +++ b/app/src/main/res/layout/edit_manga_dialog.xml @@ -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"