From 5e55bce5296c6e04809320021acc1e256b73cb1d Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 12 Jun 2023 10:54:12 +0300 Subject: [PATCH] Use indirect image url in bookmarks --- app/build.gradle | 6 +++--- .../koitharu/kotatsu/bookmarks/domain/Bookmark.kt | 15 +++++++++++++++ .../bookmarks/ui/adapter/BookmarkListAD.kt | 3 ++- .../kotatsu/core/ui/sheet/BaseAdaptiveSheet.kt | 3 +-- .../koitharu/kotatsu/reader/ui/ReaderViewModel.kt | 4 ++-- build.gradle | 2 +- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b2419c8ae..01c02c0c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { minSdkVersion 21 targetSdkVersion 33 versionCode 551 - versionName '5.2-a2' + versionName '5.2-b1' generatedDensities = [] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -83,13 +83,13 @@ dependencies { exclude group: 'org.json', module: 'json' } - implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.21' + implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.activity:activity-ktx:1.7.2' - implementation 'androidx.fragment:fragment-ktx:1.5.7' + implementation 'androidx.fragment:fragment-ktx:1.6.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-service:2.6.1' 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 421105155..98116f8a4 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,6 +1,7 @@ package org.koitharu.kotatsu.bookmarks.domain import org.koitharu.kotatsu.parsers.model.Manga +import org.koitharu.kotatsu.parsers.model.MangaPage import java.util.Date class Bookmark( @@ -14,6 +15,20 @@ class Bookmark( val percent: Float, ) { + val directImageUrl: String? + get() = if (isImageUrlDirect()) imageUrl else null + + fun toMangaPage() = MangaPage( + id = pageId, + url = imageUrl, + preview = null, + source = manga.source, + ) + + private fun isImageUrlDirect(): Boolean { + return imageUrl.substringAfterLast('.').length in 2..4 + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/adapter/BookmarkListAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/adapter/BookmarkListAD.kt index 886aba926..5996df31d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/adapter/BookmarkListAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/adapter/BookmarkListAD.kt @@ -28,7 +28,8 @@ fun bookmarkListAD( binding.root.setOnLongClickListener(listener) bind { - binding.imageViewThumb.newImageRequest(lifecycleOwner, item.imageUrl)?.run { + val data: Any = item.directImageUrl ?: item.toMangaPage() + binding.imageViewThumb.newImageRequest(lifecycleOwner, data)?.run { size(CoverSizeResolver(binding.imageViewThumb)) placeholder(R.drawable.ic_placeholder) fallback(R.drawable.ic_placeholder) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/sheet/BaseAdaptiveSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/sheet/BaseAdaptiveSheet.kt index ba6b5be97..d9941765d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/sheet/BaseAdaptiveSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/sheet/BaseAdaptiveSheet.kt @@ -6,7 +6,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams -import androidx.activity.ComponentDialog import androidx.activity.OnBackPressedDispatcher import androidx.appcompat.app.AppCompatDialogFragment import androidx.core.view.updateLayoutParams @@ -36,7 +35,7 @@ abstract class BaseAdaptiveSheet : AppCompatDialogFragment() { get() = behavior?.state == AdaptiveSheetBehavior.STATE_EXPANDED val onBackPressedDispatcher: OnBackPressedDispatcher - get() = (requireDialog() as ComponentDialog).onBackPressedDispatcher + get() = requireComponentDialog().onBackPressedDispatcher final override fun onCreateView( inflater: LayoutInflater, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index d95be359b..5bd2e8531 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -42,6 +42,7 @@ import org.koitharu.kotatsu.core.ui.BaseViewModel import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.requireValue import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase import org.koitharu.kotatsu.details.domain.model.DoubleManga @@ -56,7 +57,6 @@ import org.koitharu.kotatsu.reader.domain.DetectReaderModeUseCase import org.koitharu.kotatsu.reader.domain.PageLoader import org.koitharu.kotatsu.reader.ui.config.ReaderSettings import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState -import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import java.util.Date import javax.inject.Inject @@ -288,7 +288,7 @@ class ReaderViewModel @Inject constructor( chapterId = state.chapterId, page = state.page, scroll = state.scroll, - imageUrl = page.preview.ifNullOrEmpty { pageLoader.getPageUrl(page) }, + imageUrl = page.preview.ifNullOrEmpty { page.url }, createdAt = Date(), percent = computePercent(state.chapterId, state.page), ) diff --git a/build.gradle b/build.gradle index bd956dc1e..f0ec27d8a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:8.0.2' - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22' classpath 'com.google.dagger:hilt-android-gradle-plugin:2.46.1' } }