Simplifying some of the chat rendering process
This commit is contained in:
@@ -11,7 +11,6 @@ import coil.fetch.Fetcher
|
|||||||
import coil.fetch.SourceResult
|
import coil.fetch.SourceResult
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import coil.size.Size
|
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
@@ -61,7 +60,6 @@ private fun svgString(msg: String): String {
|
|||||||
|
|
||||||
class HashImageFetcher(
|
class HashImageFetcher(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val size: Size,
|
|
||||||
private val data: Uri
|
private val data: Uri
|
||||||
) : Fetcher {
|
) : Fetcher {
|
||||||
|
|
||||||
@@ -81,17 +79,16 @@ class HashImageFetcher(
|
|||||||
|
|
||||||
object Factory : Fetcher.Factory<Uri> {
|
object Factory : Fetcher.Factory<Uri> {
|
||||||
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher {
|
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher {
|
||||||
return HashImageFetcher(options.context, options.size, data)
|
return HashImageFetcher(options.context, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
object Robohash {
|
object Robohash {
|
||||||
fun imageRequest(context: Context, message: String, robotSize: Size): ImageRequest {
|
fun imageRequest(context: Context, message: String): ImageRequest {
|
||||||
return ImageRequest
|
return ImageRequest
|
||||||
.Builder(context)
|
.Builder(context)
|
||||||
.data("robohash:$message")
|
.data("robohash:$message")
|
||||||
.fetcherFactory(HashImageFetcher.Factory)
|
.fetcherFactory(HashImageFetcher.Factory)
|
||||||
.size(robotSize)
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ import androidx.compose.ui.graphics.FilterQuality
|
|||||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
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.platform.LocalDensity
|
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import coil.compose.AsyncImagePainter
|
import coil.compose.AsyncImagePainter
|
||||||
import coil.compose.rememberAsyncImagePainter
|
import coil.compose.rememberAsyncImagePainter
|
||||||
import coil.size.Size
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -33,18 +31,9 @@ fun RobohashAsyncImage(
|
|||||||
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality
|
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val size = with(LocalDensity.current) {
|
|
||||||
remember {
|
|
||||||
robotSize.roundToPx()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val imageRequest = remember(robotSize, robot) {
|
val imageRequest = remember(robot) {
|
||||||
Robohash.imageRequest(
|
Robohash.imageRequest(context, robot)
|
||||||
context,
|
|
||||||
robot,
|
|
||||||
Size(size, size)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
@@ -92,15 +81,9 @@ fun RobohashFallbackAsyncImage(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val painter = with(LocalDensity.current) {
|
val painter = rememberAsyncImagePainter(
|
||||||
rememberAsyncImagePainter(
|
model = Robohash.imageRequest(context, robot)
|
||||||
model = Robohash.imageRequest(
|
)
|
||||||
context,
|
|
||||||
robot,
|
|
||||||
Size(robotSize.roundToPx(), robotSize.roundToPx())
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = model,
|
model = model,
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.ChatBubbleShapeMe
|
import com.vitorpamplona.amethyst.ui.theme.ChatBubbleShapeMe
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ChatBubbleShapeThem
|
import com.vitorpamplona.amethyst.ui.theme.ChatBubbleShapeThem
|
||||||
import com.vitorpamplona.amethyst.ui.theme.RelayIconFilter
|
import com.vitorpamplona.amethyst.ui.theme.RelayIconFilter
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.Size13dp
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
@@ -359,13 +361,7 @@ private fun StatusRow(
|
|||||||
fun ChatTimeAgo(time: Long) {
|
fun ChatTimeAgo(time: Long) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
var timeStr by remember { mutableStateOf("") }
|
val timeStr = remember { timeAgoShort(time, context = context) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = time) {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
timeStr = timeAgoShort(time, context = context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
timeStr,
|
timeStr,
|
||||||
@@ -553,13 +549,13 @@ private fun RelayBadges(baseNote: Note) {
|
|||||||
|
|
||||||
if (state.shouldDisplayExpandButton && !expanded) {
|
if (state.shouldDisplayExpandButton && !expanded) {
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.then(Modifier.size(15.dp)),
|
modifier = Size15Modifier,
|
||||||
onClick = { expanded = true }
|
onClick = { expanded = true }
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.ChevronRight,
|
imageVector = Icons.Default.ChevronRight,
|
||||||
null,
|
null,
|
||||||
modifier = Modifier.size(15.dp),
|
modifier = Size15Modifier,
|
||||||
tint = MaterialTheme.colors.placeholderText
|
tint = MaterialTheme.colors.placeholderText
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -599,7 +595,7 @@ fun RenderRelay(dirtyUrl: String) {
|
|||||||
) {
|
) {
|
||||||
RobohashFallbackAsyncImage(
|
RobohashFallbackAsyncImage(
|
||||||
robot = iconUrl,
|
robot = iconUrl,
|
||||||
robotSize = remember { 13.dp },
|
robotSize = Size13dp,
|
||||||
model = iconUrl,
|
model = iconUrl,
|
||||||
contentDescription = stringResource(id = R.string.relay_icon),
|
contentDescription = stringResource(id = R.string.relay_icon),
|
||||||
colorFilter = RelayIconFilter,
|
colorFilter = RelayIconFilter,
|
||||||
|
|||||||
@@ -26,5 +26,8 @@ val StdHorzSpacer = Modifier.width(5.dp)
|
|||||||
val DoubleHorzSpacer = Modifier.width(10.dp)
|
val DoubleHorzSpacer = Modifier.width(10.dp)
|
||||||
|
|
||||||
val Size35dp = 35.dp
|
val Size35dp = 35.dp
|
||||||
|
val Size13dp = 13.dp
|
||||||
|
|
||||||
val StdPadding = Modifier.padding(10.dp)
|
val StdPadding = Modifier.padding(10.dp)
|
||||||
|
|
||||||
|
val Size15Modifier = Modifier.size(15.dp)
|
||||||
|
|||||||
Reference in New Issue
Block a user