|
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.RowScope
|
|
import androidx.compose.foundation.layout.RowScope
|
|
|
|
|
+import androidx.compose.foundation.layout.aspectRatio
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.padding
|
|
@@ -23,17 +24,15 @@ import androidx.compose.ui.draw.clip
|
|
|
import androidx.compose.ui.layout.ContentScale
|
|
import androidx.compose.ui.layout.ContentScale
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
+import coil.Coil.imageLoader
|
|
|
import coil.compose.AsyncImage
|
|
import coil.compose.AsyncImage
|
|
|
import coil.request.ImageRequest
|
|
import coil.request.ImageRequest
|
|
|
-
|
|
|
|
|
-private val DefaultCoverModifier = Modifier
|
|
|
|
|
- .width(48.dp)
|
|
|
|
|
- .height(68.dp)
|
|
|
|
|
|
|
+import io.legado.app.model.BookCover.coverImageLoader
|
|
|
|
|
|
|
|
@Composable
|
|
@Composable
|
|
|
fun Cover(
|
|
fun Cover(
|
|
|
path: Any?,
|
|
path: Any?,
|
|
|
- modifier: Modifier = DefaultCoverModifier,
|
|
|
|
|
|
|
+ modifier: Modifier = Modifier.width(48.dp),
|
|
|
badgeContent: (@Composable RowScope.() -> Unit)? = null,
|
|
badgeContent: (@Composable RowScope.() -> Unit)? = null,
|
|
|
loadOnlyWifi: Boolean = false,
|
|
loadOnlyWifi: Boolean = false,
|
|
|
sourceOrigin: String? = null,
|
|
sourceOrigin: String? = null,
|
|
@@ -41,40 +40,36 @@ fun Cover(
|
|
|
) {
|
|
) {
|
|
|
val context = LocalContext.current
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
- Box(modifier = modifier) {
|
|
|
|
|
- Box(
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .fillMaxSize()
|
|
|
|
|
- .clip(RoundedCornerShape(4.dp))
|
|
|
|
|
- .background(MaterialTheme.colorScheme.surfaceContainerLow),
|
|
|
|
|
- contentAlignment = Alignment.Center
|
|
|
|
|
- ) {
|
|
|
|
|
- if (path == null) {
|
|
|
|
|
- Icon(
|
|
|
|
|
- Icons.Default.Book,
|
|
|
|
|
- contentDescription = null,
|
|
|
|
|
- tint = MaterialTheme.colorScheme.surfaceContainerHighest,
|
|
|
|
|
- modifier = Modifier.size(24.dp)
|
|
|
|
|
- )
|
|
|
|
|
- } else {
|
|
|
|
|
- AsyncImage(
|
|
|
|
|
- model = ImageRequest.Builder(context)
|
|
|
|
|
- .data(path) // 可以是 URL、File、Uri、DrawableRes
|
|
|
|
|
- .crossfade(true)
|
|
|
|
|
- .apply {
|
|
|
|
|
- if (sourceOrigin != null) setParameter("sourceOrigin", sourceOrigin)
|
|
|
|
|
- if (loadOnlyWifi) setParameter("loadOnlyWifi", true)
|
|
|
|
|
- }
|
|
|
|
|
- .listener(
|
|
|
|
|
- onSuccess = { _, _ -> onLoadFinish?.invoke() },
|
|
|
|
|
- onError = { _, _ -> onLoadFinish?.invoke() }
|
|
|
|
|
- )
|
|
|
|
|
- .build(),
|
|
|
|
|
- contentDescription = null,
|
|
|
|
|
- contentScale = ContentScale.Crop,
|
|
|
|
|
- modifier = Modifier.fillMaxSize()
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val boxModifier = modifier
|
|
|
|
|
+ .aspectRatio(3f / 4f)
|
|
|
|
|
+ .clip(RoundedCornerShape(4.dp))
|
|
|
|
|
+ .background(MaterialTheme.colorScheme.surfaceContainerLow)
|
|
|
|
|
+
|
|
|
|
|
+ Box(modifier = boxModifier) {
|
|
|
|
|
+ if (path == null) {
|
|
|
|
|
+ Icon(
|
|
|
|
|
+ Icons.Default.Book,
|
|
|
|
|
+ contentDescription = null,
|
|
|
|
|
+ tint = MaterialTheme.colorScheme.surfaceContainerHighest,
|
|
|
|
|
+ modifier = Modifier.size(24.dp).align(Alignment.Center)
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ AsyncImage(
|
|
|
|
|
+ model = ImageRequest.Builder(context)
|
|
|
|
|
+ .data(path)
|
|
|
|
|
+ .crossfade(true)
|
|
|
|
|
+ .setParameter("sourceOrigin", sourceOrigin)
|
|
|
|
|
+ .setParameter("loadOnlyWifi", loadOnlyWifi)
|
|
|
|
|
+ .listener(
|
|
|
|
|
+ onSuccess = { _, _ -> onLoadFinish?.invoke() },
|
|
|
|
|
+ onError = { _, _ -> onLoadFinish?.invoke() }
|
|
|
|
|
+ )
|
|
|
|
|
+ .build(),
|
|
|
|
|
+ imageLoader = coverImageLoader,
|
|
|
|
|
+ contentDescription = null,
|
|
|
|
|
+ contentScale = ContentScale.Crop,
|
|
|
|
|
+ modifier = Modifier.fillMaxSize()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (badgeContent != null) {
|
|
if (badgeContent != null) {
|