Fix bookmarks images loading
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package org.koitharu.kotatsu.bookmarks.domain
|
||||
|
||||
import org.koitharu.kotatsu.core.util.MimeTypes
|
||||
import org.koitharu.kotatsu.core.util.ext.isImage
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.local.data.hasImageExtension
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import java.time.Instant
|
||||
@@ -17,9 +18,6 @@ data class Bookmark(
|
||||
val percent: Float,
|
||||
) : ListModel {
|
||||
|
||||
val imageLoadData: Any
|
||||
get() = if (isImageUrlDirect()) imageUrl else toMangaPage()
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is Bookmark &&
|
||||
manga.id == other.manga.id &&
|
||||
@@ -30,11 +28,9 @@ data class Bookmark(
|
||||
fun toMangaPage() = MangaPage(
|
||||
id = pageId,
|
||||
url = imageUrl,
|
||||
preview = null,
|
||||
preview = imageUrl.takeIf {
|
||||
MimeTypes.getMimeTypeFromUrl(it)?.isImage == true
|
||||
},
|
||||
source = manga.source,
|
||||
)
|
||||
|
||||
private fun isImageUrlDirect(): Boolean {
|
||||
return hasImageExtension(imageUrl)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.koitharu.kotatsu.local.data.PagesCache
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.util.mimeType
|
||||
import org.koitharu.kotatsu.parsers.util.requireBody
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -42,6 +43,13 @@ class MangaPageFetcher(
|
||||
) : Fetcher {
|
||||
|
||||
override suspend fun fetch(): FetchResult? {
|
||||
if (!page.preview.isNullOrEmpty()) {
|
||||
runCatchingCancellable {
|
||||
imageLoader.fetch(checkNotNull(page.preview), options)
|
||||
}.onSuccess {
|
||||
return it
|
||||
}
|
||||
}
|
||||
val repo = mangaRepositoryFactory.create(page.source)
|
||||
val pageUrl = repo.getPageUrl(page)
|
||||
if (options.diskCachePolicy.readEnabled) {
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||
import org.koitharu.kotatsu.core.util.ext.mangaExtra
|
||||
import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra
|
||||
import org.koitharu.kotatsu.favourites.domain.model.Cover
|
||||
import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.nullIfEmpty
|
||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||
import kotlin.coroutines.resume
|
||||
import androidx.appcompat.R as appcompatR
|
||||
@@ -103,14 +103,14 @@ class CoverImageView @JvmOverloads constructor(
|
||||
|
||||
fun setImageAsync(page: ReaderPage) = enqueueRequest(
|
||||
newRequestBuilder()
|
||||
.data(page.preview?.nullIfEmpty() ?: page.toMangaPage())
|
||||
.data(page.toMangaPage())
|
||||
.mangaSourceExtra(page.source)
|
||||
.build(),
|
||||
)
|
||||
|
||||
fun setImageAsync(page: MangaPage) = enqueueRequest(
|
||||
newRequestBuilder()
|
||||
.data(page.preview?.nullIfEmpty() ?: page)
|
||||
.data(page)
|
||||
.mangaSourceExtra(page.source)
|
||||
.build(),
|
||||
)
|
||||
@@ -146,7 +146,7 @@ class CoverImageView @JvmOverloads constructor(
|
||||
bookmark: Bookmark
|
||||
) = enqueueRequest(
|
||||
newRequestBuilder()
|
||||
.data(bookmark.imageLoadData)
|
||||
.data(bookmark.toMangaPage())
|
||||
.decodeRegion(bookmark.scroll)
|
||||
.bookmarkExtra(bookmark)
|
||||
.build(),
|
||||
@@ -190,6 +190,7 @@ class CoverImageView @JvmOverloads constructor(
|
||||
is HttpException -> response.code.toString()
|
||||
is HttpStatusException -> statusCode.toString()
|
||||
is FileNotFoundException -> "404"
|
||||
is ParseException -> "</>"
|
||||
else -> cause?.getShortMessage()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun hasImageExtension(string: String): Boolean {
|
||||
val ext = string.substringAfterLast('.', "")
|
||||
return ext.equals("png", ignoreCase = true) || ext.equals("jpg", ignoreCase = true)
|
||||
|| ext.equals("jpeg", ignoreCase = true) || ext.equals("webp", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun hasImageExtension(file: File) = hasImageExtension(file.name)
|
||||
@@ -31,15 +31,15 @@ class CoverRestoreInterceptor @Inject constructor(
|
||||
val request = chain.request
|
||||
val result = chain.proceed()
|
||||
if (result is ErrorResult && result.throwable.shouldRestore()) {
|
||||
request.extras[mangaKey]?.let {
|
||||
return if (restoreManga(it)) {
|
||||
request.extras[bookmarkKey]?.let {
|
||||
return if (restoreBookmark(it)) {
|
||||
chain.withRequest(request.newBuilder().build()).proceed()
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
request.extras[bookmarkKey]?.let {
|
||||
return if (restoreBookmark(it)) {
|
||||
request.extras[mangaKey]?.let {
|
||||
return if (restoreManga(it)) {
|
||||
chain.withRequest(request.newBuilder().build()).proceed()
|
||||
} else {
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user