I would like to show user contents of notifications that dispatched from this app since the app had been started.
This app is creating for my learning.
它使用LazyColumn Compose,但在有很多通知的情况下速度非常慢.
Probably it caused by taking long time to load drawable from Notification LargeIcon.
I want to load it asynchronously but I have no idea how should I do it in compose.
以下是LazyList项的部分代码.
@Composable
fun ListElement(notify: Notification) {
val drawableState = remember {mutableStateOf<Drawable?>(null)}
Row(modifier=Modifier.height(80.dp).fillMaxWidth().padding(start=10.dp, top=2.dp, bottom=0.dp, end=10.dp), horizontalArrangement = Arrangement.SpaceBetween) {
Column {
Text(
notify.extras.getString(Notification.EXTRA_TITLE, ""),
style = MaterialTheme.typography.titleMedium
)
Text(notify.extras.getString(Notification.EXTRA_TEXT, ""))
}
val icon = notify.getLargeIcon()
if (icon != null) {
icon.loadDrawableAsync(context=LocalContext.current, listener=(Icon.OnDrawableLoadedListener { d -> drawableState.value = d }), handler= Handler())
// I have no idea how to load asynchronously...
if (drawableState.value != null) {
val bitmap = drawableState.value!!.toBitmap()
Spacer(modifier = Modifier.height(10.dp))
Image(
bitmap = bitmap.asImageBitmap(),
contentDescription = "Icon",
modifier = Modifier.fillMaxHeight()
)
}
}}
}