Store imageKey in GalleryPreview to mitigate Parcelable too large
This commit is contained in:
1 parent
f94a2350ab
commit
99ed2b35d3
7 files changed
+44
-12
No files matched your search
@@ -15,6 +15,14 @@
|
||||
*/
|
||||
package com.hippo.ehviewer.client
|
||||
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.client.data.NormalGalleryPreview
|
||||
|
||||
// ExHentai Large Preview: https://exhentai.org/t/***
|
||||
// ExHentai Normal Preview: https://exhentai.org/m/***
|
||||
// EHentai Normal Preview: https://ehgt.org/m/***
|
||||
// EHentai Large Preview: https://ehgt.org/***
|
||||
|
||||
private const val URL_PREFIX_THUMB_E = "https://ehgt.org/"
|
||||
private const val URL_PREFIX_THUMB_EX = "https://exhentai.org/"
|
||||
|
||||
@@ -27,3 +35,10 @@ fun getPreviewThumbKey(url: String): String {
|
||||
.removePrefix(URL_PREFIX_THUMB_EX)
|
||||
.removePrefix("t/")
|
||||
}
|
||||
|
||||
val GalleryPreview.url
|
||||
get() = if (this is NormalGalleryPreview) {
|
||||
if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX + imageKey else URL_PREFIX_THUMB_E + imageKey
|
||||
} else {
|
||||
if (EhUtils.isExHentai) URL_PREFIX_THUMB_EX + "t/" + imageKey else URL_PREFIX_THUMB_E + imageKey
|
||||
}
|
||||
@@ -19,19 +19,19 @@ import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
interface GalleryPreview : Parcelable {
|
||||
val imageUrl: String
|
||||
val imageKey: String
|
||||
val position: Int
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class LargeGalleryPreview(
|
||||
override val imageUrl: String,
|
||||
override val imageKey: String,
|
||||
override val position: Int,
|
||||
) : GalleryPreview
|
||||
|
||||
@Parcelize
|
||||
data class NormalGalleryPreview(
|
||||
override val imageUrl: String,
|
||||
override val imageKey: String,
|
||||
override val position: Int,
|
||||
val offsetX: Int,
|
||||
val offsetY: Int,
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.hippo.ehviewer.client.exception.EhException
|
||||
import com.hippo.ehviewer.client.exception.OffensiveException
|
||||
import com.hippo.ehviewer.client.exception.ParseException
|
||||
import com.hippo.ehviewer.client.exception.PiningException
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import com.hippo.util.JsoupUtils
|
||||
import com.hippo.yorozuya.NumberUtils
|
||||
@@ -480,9 +481,9 @@ object GalleryDetailParser {
|
||||
check(PATTERN_LARGE_PREVIEW.containsMatchIn(body))
|
||||
return PATTERN_LARGE_PREVIEW.findAll(body).unzip {
|
||||
val position = it.groupValues[2].toInt() - 1
|
||||
val imageUrl = it.groupValues[3].trim()
|
||||
val imageKey = getPreviewThumbKey(it.groupValues[3].trim())
|
||||
val pageUrl = it.groupValues[1].trim()
|
||||
LargeGalleryPreview(imageUrl, position) to pageUrl
|
||||
LargeGalleryPreview(imageKey, position) to pageUrl
|
||||
}.run {
|
||||
first.toList() to second.toList()
|
||||
}
|
||||
@@ -492,13 +493,13 @@ object GalleryDetailParser {
|
||||
check(PATTERN_NORMAL_PREVIEW.containsMatchIn(body))
|
||||
return PATTERN_NORMAL_PREVIEW.findAll(body).unzip {
|
||||
val position = it.groupValues[6].toInt() - 1
|
||||
val imageUrl = it.groupValues[3].trim()
|
||||
val imageKey = getPreviewThumbKey(it.groupValues[3].trim())
|
||||
val xOffset = it.groupValues[4].toIntOrNull() ?: 0
|
||||
val yOffset = 0
|
||||
val width = it.groupValues[1].toInt()
|
||||
val height = it.groupValues[2].toInt()
|
||||
val pageUrl = it.groupValues[5].trim()
|
||||
NormalGalleryPreview(imageUrl, position, xOffset, yOffset, width, height) to pageUrl
|
||||
NormalGalleryPreview(imageKey, position, xOffset, yOffset, width, height) to pageUrl
|
||||
}.run {
|
||||
first.toList() to second.toList()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import android.content.Context
|
||||
import coil.disk.DiskCache
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
import com.hippo.ehviewer.client.url
|
||||
|
||||
fun ImageRequest.Builder.ehUrl(url: String?) = apply {
|
||||
url?.let {
|
||||
@@ -16,5 +18,13 @@ fun ImageRequest.Builder.ehUrl(url: String?) = apply {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun Context.imageRequest(url: String?, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehUrl(url).apply(builder).build()
|
||||
fun ImageRequest.Builder.ehPreviewKey(key: GalleryPreview) = apply {
|
||||
data(key.url)
|
||||
memoryCacheKey(key.imageKey)
|
||||
diskCacheKey(key.imageKey)
|
||||
size(Size.ORIGINAL)
|
||||
}
|
||||
|
||||
inline fun Context.imageRequest(key: GalleryPreview, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehPreviewKey(key).apply(builder).build()
|
||||
inline fun Context.imageRequest(key: String?, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehUrl(key).apply(builder).build()
|
||||
inline fun diskCache(builder: DiskCache.Builder.() -> Unit) = DiskCache.Builder().apply(builder).build()
|
||||
@@ -837,7 +837,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
}
|
||||
Spacer(modifier = Modifier.size(dimensionResource(id = R.dimen.keyline_margin)))
|
||||
if (Settings.showComments) {
|
||||
GalleryDetailComment(galleryDetail.comments?.comments)
|
||||
GalleryDetailComment(galleryDetail.comments.comments)
|
||||
Spacer(modifier = Modifier.size(dimensionResource(id = R.dimen.strip_item_padding_v)))
|
||||
}
|
||||
}
|
||||
@@ -931,7 +931,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
lifecycleScope.launchIO {
|
||||
galleryDetail.previewList.forEach {
|
||||
context?.run {
|
||||
imageLoader.enqueue(imageRequest(it.imageUrl))
|
||||
imageLoader.enqueue(imageRequest(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class GalleryPreviewsScene : BaseToolbarScene() {
|
||||
val previewList = result.first.first
|
||||
previewList.forEach {
|
||||
context.run {
|
||||
imageLoader.enqueue(imageRequest(it.imageUrl))
|
||||
imageLoader.enqueue(imageRequest(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ fun requestOf(model: String?): ImageRequest {
|
||||
return LocalContext.current.imageRequest(model)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun requestOf(model: GalleryPreview): ImageRequest {
|
||||
return LocalContext.current.imageRequest(model)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EhAsyncThumb(
|
||||
model: String?,
|
||||
@@ -49,7 +55,7 @@ fun EhAsyncPreview(
|
||||
) {
|
||||
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
|
||||
AsyncImage(
|
||||
model = requestOf(model.imageUrl),
|
||||
model = requestOf(model),
|
||||
contentDescription = "",
|
||||
modifier = modifier,
|
||||
transform = {
|
||||
|
||||
Reference in new issue
Block a user