Apply proper crop
This commit is contained in:
1 parent
4b0f62e058
commit
89b20b3cda
4 files changed
+34
-34
No files matched your search
@@ -2,6 +2,7 @@ package com.hippo.ehviewer.coil
|
||||
|
||||
import android.content.Context
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import com.hippo.ehviewer.client.getPreviewThumbKey
|
||||
|
||||
fun ImageRequest.Builder.ehUrl(url: String) = apply {
|
||||
@@ -9,6 +10,7 @@ fun ImageRequest.Builder.ehUrl(url: String) = apply {
|
||||
data(url)
|
||||
memoryCacheKey(key)
|
||||
diskCacheKey(key)
|
||||
size(Size.ORIGINAL)
|
||||
}
|
||||
|
||||
inline fun Context.imageRequest(
|
||||
|
||||
@@ -150,7 +150,7 @@ import com.hippo.ehviewer.ui.CommonOperations
|
||||
import com.hippo.ehviewer.ui.GalleryInfoBottomSheet
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene.Companion.toStartArgs
|
||||
import com.hippo.ehviewer.ui.widget.EhAsyncThumb
|
||||
import com.hippo.ehviewer.ui.widget.EhAsyncPreview
|
||||
import com.hippo.ehviewer.ui.widget.GalleryDetailHeaderCard
|
||||
import com.hippo.ehviewer.ui.widget.GalleryDetailRating
|
||||
import com.hippo.ehviewer.widget.GalleryRatingBar
|
||||
@@ -596,8 +596,8 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(0.6666667F)
|
||||
) {
|
||||
EhAsyncThumb(
|
||||
model = it.imageUrl,
|
||||
EhAsyncPreview(
|
||||
model = it,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@ package com.hippo.ehviewer.ui.widget
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import coil.compose.AsyncImage
|
||||
import coil.compose.AsyncImagePainter
|
||||
import coil.request.ImageRequest
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.coil.ehUrl
|
||||
|
||||
@Composable
|
||||
@@ -28,3 +34,26 @@ fun EhAsyncThumb(
|
||||
modifier = modifier,
|
||||
contentScale = contentScale,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun EhAsyncPreview(
|
||||
model: GalleryPreview,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
|
||||
AsyncImage(
|
||||
model = requestOf(model.imageUrl),
|
||||
contentDescription = "",
|
||||
modifier = modifier,
|
||||
onState = {
|
||||
if (it is AsyncImagePainter.State.Success) {
|
||||
it.result.drawable.run {
|
||||
if ((intrinsicWidth.toFloat() / intrinsicHeight) in 0.5..0.8) {
|
||||
if (contentScale == ContentScale.Fit) contentScale = ContentScale.Crop
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
contentScale = contentScale,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user