Spilt LargeGalleryPreview and NormalGalleryPreview

This commit is contained in:
tarsin committed 2023-05-01 11:16:54 +08:00
1 parent 7abeba8b87
commit f94a2350ab
3 files changed
+26 -15

No files matched your search

@@ -18,12 +18,23 @@ package com.hippo.ehviewer.client.data
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
interface GalleryPreview : Parcelable {
val imageUrl: String
val position: Int
}
@Parcelize
data class GalleryPreview(
val imageUrl: String,
val position: Int,
val offsetX: Int = Int.MIN_VALUE,
val offsetY: Int = Int.MIN_VALUE,
val clipWidth: Int = Int.MIN_VALUE,
val clipHeight: Int = Int.MIN_VALUE,
) : Parcelable
data class LargeGalleryPreview(
override val imageUrl: String,
override val position: Int,
) : GalleryPreview
@Parcelize
data class NormalGalleryPreview(
override val imageUrl: String,
override val position: Int,
val offsetX: Int,
val offsetY: Int,
val clipWidth: Int,
val clipHeight: Int,
) : GalleryPreview
@@ -27,6 +27,8 @@ import com.hippo.ehviewer.client.data.GalleryCommentList
import com.hippo.ehviewer.client.data.GalleryDetail
import com.hippo.ehviewer.client.data.GalleryPreview
import com.hippo.ehviewer.client.data.GalleryTagGroup
import com.hippo.ehviewer.client.data.LargeGalleryPreview
import com.hippo.ehviewer.client.data.NormalGalleryPreview
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.client.exception.OffensiveException
import com.hippo.ehviewer.client.exception.ParseException
@@ -480,7 +482,7 @@ object GalleryDetailParser {
val position = it.groupValues[2].toInt() - 1
val imageUrl = it.groupValues[3].trim()
val pageUrl = it.groupValues[1].trim()
GalleryPreview(imageUrl, position) to pageUrl
LargeGalleryPreview(imageUrl, position) to pageUrl
}.run {
first.toList() to second.toList()
}
@@ -496,7 +498,7 @@ object GalleryDetailParser {
val width = it.groupValues[1].toInt()
val height = it.groupValues[2].toInt()
val pageUrl = it.groupValues[5].trim()
GalleryPreview(imageUrl, position, xOffset, yOffset, width, height) to pageUrl
NormalGalleryPreview(imageUrl, position, xOffset, yOffset, width, height) to pageUrl
}.run {
first.toList() to second.toList()
}
@@ -18,6 +18,7 @@ import coil.compose.AsyncImage
import coil.compose.AsyncImagePainter
import coil.request.ImageRequest
import com.hippo.ehviewer.client.data.GalleryPreview
import com.hippo.ehviewer.client.data.NormalGalleryPreview
import com.hippo.ehviewer.coil.imageRequest
@Composable
@@ -38,9 +39,6 @@ fun EhAsyncThumb(
contentScale = contentScale,
)
private val GalleryPreview.shouldClip
get() = offsetX != Int.MIN_VALUE
/**
* Show a part of the original drawable, non-animated only implementation.
*/
@@ -56,7 +54,7 @@ fun EhAsyncPreview(
modifier = modifier,
transform = {
model.run {
if (it is AsyncImagePainter.State.Success && shouldClip) {
if (it is AsyncImagePainter.State.Success && this is NormalGalleryPreview) {
it.copy(
painter = BitmapPainter(
(it.result.drawable as BitmapDrawable).bitmap.asImageBitmap(),
@@ -72,7 +70,7 @@ fun EhAsyncPreview(
onState = {
if (it is AsyncImagePainter.State.Success) {
model.run {
if (shouldClip) {
if (this is NormalGalleryPreview) {
if (clipWidth.toFloat() / clipHeight in 0.5..0.8) {
if (contentScale == ContentScale.Fit) contentScale = ContentScale.Crop
}