Andreas adf02e53fd
Add error state to MangaCover composable (#7022)
* Add error state to MangaCover

- Add error drawable when thumbnailUrl isn't able to be loaded
- Tweak usage of MangaCover

* Change `contentDescription` to be nullable

As the invoke function makes default nulls
2022-04-27 09:24:35 -04:00

42 lines
1.3 KiB
Kotlin

package eu.kanade.presentation.components
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import eu.kanade.presentation.util.bitmapPainterResource
import eu.kanade.tachiyomi.R
enum class MangaCover(private val ratio: Float) {
Square(1f / 1f),
Book(2f / 3f);
@Composable
operator fun invoke(
modifier: Modifier = Modifier,
data: String?,
contentDescription: String? = null,
shape: Shape? = null
) {
AsyncImage(
model = data,
placeholder = ColorPainter(CoverPlaceholderColor),
error = bitmapPainterResource(id = R.drawable.cover_error),
contentDescription = contentDescription,
modifier = modifier
.aspectRatio(ratio)
.clip(shape ?: RoundedCornerShape(4.dp)),
contentScale = ContentScale.Crop,
)
}
}
private val CoverPlaceholderColor = Color(0x1F888888)