Add async image proxy for robohash images
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.components
|
package com.vitorpamplona.amethyst.ui.components
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
@@ -26,6 +30,48 @@ data class ResizeImage(val url: String?, val size: Dp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable fun AsyncUserImageProxy(
|
||||||
|
pubkeyHex: String,
|
||||||
|
model: ResizeImage,
|
||||||
|
contentDescription: String?,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
alignment: Alignment = Alignment.Center,
|
||||||
|
contentScale: ContentScale = ContentScale.Fit,
|
||||||
|
alpha: Float = DefaultAlpha,
|
||||||
|
colorFilter: ColorFilter? = null,
|
||||||
|
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
|
||||||
|
) {
|
||||||
|
var loading by remember { mutableStateOf(false) }
|
||||||
|
var error by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (model.url == null || loading || error) {
|
||||||
|
RoboHashAsyncImage(
|
||||||
|
message = pubkeyHex,
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
modifier = modifier,
|
||||||
|
alignment = alignment,
|
||||||
|
contentScale = contentScale,
|
||||||
|
alpha = alpha,
|
||||||
|
colorFilter = colorFilter,
|
||||||
|
filterQuality = filterQuality,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
AsyncImage(
|
||||||
|
model = model.proxyUrl(),
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
modifier = modifier,
|
||||||
|
onLoading = { loading = true },
|
||||||
|
onSuccess = { loading = false; error = false },
|
||||||
|
onError = { loading = false; error = true },
|
||||||
|
alignment = alignment,
|
||||||
|
contentScale = contentScale,
|
||||||
|
alpha = alpha,
|
||||||
|
colorFilter = colorFilter,
|
||||||
|
filterQuality = filterQuality
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AsyncImageProxy(
|
fun AsyncImageProxy(
|
||||||
model: ResizeImage,
|
model: ResizeImage,
|
||||||
|
|||||||
Reference in New Issue
Block a user