diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/domain/Bookmark.kt b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/domain/Bookmark.kt index acc4c74f6..f57d26727 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/domain/Bookmark.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/domain/Bookmark.kt @@ -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) - } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/MangaPageFetcher.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/MangaPageFetcher.kt index 6599dd281..cdc2bba8b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/MangaPageFetcher.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/pages/MangaPageFetcher.kt @@ -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) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/image/ui/CoverImageView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/image/ui/CoverImageView.kt index 4bcebba0c..6d9d7b01b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/image/ui/CoverImageView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/image/ui/CoverImageView.kt @@ -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() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/ImageFileFilter.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/ImageFileFilter.kt deleted file mode 100644 index 06a48f4eb..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/ImageFileFilter.kt +++ /dev/null @@ -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) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestoreInterceptor.kt b/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestoreInterceptor.kt index d2a1100eb..7ff4951e5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestoreInterceptor.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestoreInterceptor.kt @@ -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