Conditionally crop thumb, Resolve #1047
This commit is contained in:
1 parent
8986289702
commit
e8ad2f2185
4 files changed
+27
-9
No files matched your search
@@ -32,7 +32,6 @@ import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
@@ -67,7 +66,7 @@ import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener
|
||||
import com.hippo.ehviewer.download.DownloadService
|
||||
import com.hippo.ehviewer.download.DownloadService.Companion.clear
|
||||
import com.hippo.ehviewer.spider.SpiderDen
|
||||
import com.hippo.ehviewer.ui.widget.EhAsyncThumb
|
||||
import com.hippo.ehviewer.ui.widget.EhAsyncCropThumb
|
||||
import com.hippo.ehviewer.ui.widget.setMD3Content
|
||||
import com.hippo.unifile.UniFile
|
||||
import com.hippo.view.ViewTransition
|
||||
@@ -865,9 +864,8 @@ class DownloadsScene :
|
||||
Card(
|
||||
onClick = ::onClick.partially1(binding.thumb),
|
||||
) {
|
||||
EhAsyncThumb(
|
||||
EhAsyncCropThumb(
|
||||
model = info.thumb,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.height(height)
|
||||
.aspectRatio(0.6666667F),
|
||||
|
||||
@@ -52,6 +52,29 @@ fun EhAsyncThumb(
|
||||
contentScale = contentScale,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun EhAsyncCropThumb(
|
||||
model: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var contentScale by remember { mutableStateOf(ContentScale.Fit) }
|
||||
AsyncImage(
|
||||
model = requestOf(model),
|
||||
contentDescription = null,
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a part of the original drawable, non-animated only implementation.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -128,9 +127,8 @@ fun GalleryDetailHeaderCard(
|
||||
) {
|
||||
Row {
|
||||
Card {
|
||||
EhAsyncThumb(
|
||||
EhAsyncCropThumb(
|
||||
model = galleryInfo.thumb,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.height(dimensionResource(id = R.dimen.gallery_detail_thumb_height))
|
||||
.width(dimensionResource(id = R.dimen.gallery_detail_thumb_width)),
|
||||
|
||||
@@ -53,9 +53,8 @@ fun GalleryInfoListItem(
|
||||
),
|
||||
) {
|
||||
Card {
|
||||
EhAsyncThumb(
|
||||
EhAsyncCropThumb(
|
||||
model = info.thumb,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = modifier.aspectRatio(0.6666667F),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user