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) val cover = File("${dir.absolutePath}/${manga.url}", COVER_NAME)
// It might not exist if using the external SD card // It might not exist if using the external SD card
cover.parentFile.mkdirs() cover.parentFile?.mkdirs()
input.use { input.use {
cover.outputStream().use { cover.outputStream().use {
input.copyTo(it) 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 fetchLatestUpdates(page: Int) = fetchSearchManga(page, "", LATEST_FILTERS)
override fun fetchMangaDetails(manga: SManga): Observable<SManga> { 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 { .flatten().filter { it.extension.equals("json") }.firstOrNull()?.apply {
val json = Gson().fromJson( val json = Gson().fromJson(
Scanner(this).useDelimiter("\\Z").next(), Scanner(this).useDelimiter("\\Z").next(),
@ -154,6 +155,28 @@ class LocalSource(private val context: Context) : CatalogueSource {
?: manga.genre ?: manga.genre
manga.status = json["status"]?.asInt ?: manga.status 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) return Observable.just(manga)
} }

View file

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

View file

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