mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 03:58:56 +01:00
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
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package eu.kanade.presentation.util
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.PluralsRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
|
||||
/**
|
||||
* Load a quantity string resource.
|
||||
@@ -30,3 +36,19 @@ fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs
|
||||
val context = LocalContext.current
|
||||
return context.resources.getQuantityString(id, quantity, *formatArgs)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapPainter from an drawable resource.
|
||||
*
|
||||
* > Only use this if [androidx.compose.ui.res.painterResource] doesn't work.
|
||||
*
|
||||
* @param id the resource identifier
|
||||
* @return the bitmap associated with the resource
|
||||
*/
|
||||
@Composable
|
||||
fun bitmapPainterResource(@DrawableRes id: Int): BitmapPainter {
|
||||
val context = LocalContext.current
|
||||
val drawable = ContextCompat.getDrawable(context, id)
|
||||
?: throw Resources.NotFoundException()
|
||||
return BitmapPainter(drawable.toBitmap().asImageBitmap())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user