Minor refactoring.

This commit is contained in:
Vitor Pamplona
2023-12-12 17:49:49 -05:00
parent b2e35cdb3e
commit be9100dc5e
13 changed files with 73 additions and 81 deletions
@@ -90,12 +90,12 @@ fun RobohashFallbackAsyncImage(
}
if (isBase64) {
val painter = rememberAsyncImagePainter(
val base64Painter = rememberAsyncImagePainter(
model = Base64Requester.imageRequest(context, model)
)
Image(
painter = painter,
painter = base64Painter,
contentDescription = null,
modifier = modifier,
alignment = alignment,
@@ -129,33 +129,6 @@ fun RobohashFallbackAsyncImage(
}
}
@Composable
fun RobohashAsyncImageProxy(
robot: String,
model: String?,
contentDescription: String?,
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Fit,
alpha: Float = DefaultAlpha,
colorFilter: ColorFilter? = null,
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
loadProfilePicture: Boolean
) {
RobohashFallbackAsyncImage(
robot = robot,
model = model,
contentDescription = contentDescription,
modifier = modifier,
alignment = alignment,
contentScale = contentScale,
alpha = alpha,
colorFilter = colorFilter,
filterQuality = filterQuality,
loadProfilePicture = loadProfilePicture
)
}
object Base64Requester {
fun imageRequest(context: Context, message: String): ImageRequest {
return ImageRequest
@@ -48,7 +48,7 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.note.ArrowBackIcon
import com.vitorpamplona.amethyst.ui.note.toShortenHex
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
@@ -220,7 +220,7 @@ private fun ActiveMarker(acc: AccountInfo, accountViewModel: AccountViewModel) {
private fun AccountPicture(user: User, loadProfilePicture: Boolean) {
val profilePicture by user.live().profilePictureChanges.observeAsState()
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = remember(user) { user.pubkeyHex },
model = profilePicture,
contentDescription = stringResource(R.string.profile_image),
@@ -81,7 +81,7 @@ import com.vitorpamplona.amethyst.service.NostrVideoDataSource
import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.amethyst.service.relays.Client
import com.vitorpamplona.amethyst.service.relays.RelayPool
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.note.AmethystIcon
import com.vitorpamplona.amethyst.ui.note.ArrowBackIcon
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
@@ -526,7 +526,7 @@ private fun LoggedInUserPictureDrawer(
IconButton(
onClick = onClick
) {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = pubkeyHex,
model = profilePicture,
contentDescription = stringResource(id = R.string.profile_image),
@@ -67,8 +67,9 @@ import com.vitorpamplona.amethyst.service.relays.RelayPool
import com.vitorpamplona.amethyst.service.relays.RelayPoolStatus
import com.vitorpamplona.amethyst.ui.actions.NewRelayListView
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.note.LoadStatuses
import com.vitorpamplona.amethyst.ui.qrcode.ShowQRDialog
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountBackupDialog
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog
@@ -204,7 +205,7 @@ fun ProfileContentTemplate(
}
Column(modifier = modifier) {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = profilePubHex,
model = profilePicture,
contentDescription = stringResource(id = R.string.profile_image),
@@ -50,7 +50,7 @@ import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ChatHeadlineBorders
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
@@ -450,7 +450,7 @@ fun ChannelName(
) {
ChannelName(
channelPicture = {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = channelIdHex,
model = channelPicture,
contentDescription = stringResource(R.string.channel_image),
@@ -48,7 +48,7 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@@ -784,7 +784,7 @@ private fun UserIcon(
nav: (String) -> Unit,
route: String
) {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = pubkeyHex,
model = userProfilePicture,
contentDescription = stringResource(id = R.string.profile_image),
@@ -47,7 +47,7 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.ImageUrlType
import com.vitorpamplona.amethyst.ui.components.InLineIconRenderer
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.screen.CombinedZap
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
@@ -529,7 +529,7 @@ fun WatchUserMetadataAndFollowsAndRenderUserProfilePicture(
WatchUserMetadata(author) { baseUserPicture ->
// Crossfade(targetState = baseUserPicture) { userPicture ->
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = author.pubkeyHex,
model = baseUserPicture,
contentDescription = stringResource(id = R.string.profile_image),
@@ -99,7 +99,7 @@ import com.vitorpamplona.amethyst.ui.components.LoadNote
import com.vitorpamplona.amethyst.ui.components.LoadThumbAndThenVideoView
import com.vitorpamplona.amethyst.ui.components.MeasureSpaceWidth
import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.ShowMoreButton
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
@@ -739,7 +739,7 @@ fun ShortCommunityHeader(baseNote: AddressableNote, accountViewModel: AccountVie
Row(verticalAlignment = CenterVertically) {
noteEvent.image()?.let {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = baseNote.idHex,
model = it,
contentDescription = stringResource(R.string.profile_image),
@@ -2896,7 +2896,7 @@ private fun ChannelNotePicture(baseChannel: Channel, loadProfilePicture: Boolean
}
Box(Size30Modifier) {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = baseChannel.idHex,
model = model,
contentDescription = stringResource(R.string.group_picture),
@@ -47,7 +47,7 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImage
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ReportNoteDialog
import com.vitorpamplona.quartz.encoders.HexKey
@@ -336,7 +336,7 @@ fun InnerUserPicture(
accountViewModel.settings.showProfilePictures.value
}
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = userHex,
model = userPicture,
contentDescription = stringResource(id = R.string.profile_image),
@@ -1,4 +1,4 @@
package com.vitorpamplona.amethyst.ui.navigation
package com.vitorpamplona.amethyst.ui.qrcode
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
@@ -19,6 +19,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.zxing.EncodeHintType
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
@@ -28,6 +29,12 @@ import com.google.zxing.qrcode.encoder.QRCode
const val QR_MARGIN_PX = 100f
@Preview
@Composable
fun QrCodeDrawerPreview() {
QrCodeDrawer("Test QR data")
}
@Composable
fun QrCodeDrawer(contents: String, modifier: Modifier = Modifier) {
val qrCode = remember(contents) {
@@ -1,4 +1,4 @@
package com.vitorpamplona.amethyst.ui.navigation
package com.vitorpamplona.amethyst.ui.qrcode
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
@@ -35,11 +36,32 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.actions.CloseButton
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.qrcode.NIP19QrCodeScanner
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.theme.Size35dp
import com.vitorpamplona.quartz.events.UserMetadata
import com.vitorpamplona.quartz.events.toImmutableListOfLists
@Preview
@Composable
fun ShowQRDialogPreview() {
val user = User("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c")
user.info = UserMetadata().apply {
name = "My Name"
picture = "Picture"
banner = "http://banner.com/test"
website = "http://mywebsite.com/test"
about = "This is the about me"
}
ShowQRDialog(
user = user,
loadProfilePicture = false,
onScan = {},
onClose = {}
)
}
@Composable
fun ShowQRDialog(user: User, loadProfilePicture: Boolean, onScan: (String) -> Unit, onClose: () -> Unit) {
var presenting by remember { mutableStateOf(true) }
@@ -48,16 +70,10 @@ fun ShowQRDialog(user: User, loadProfilePicture: Boolean, onScan: (String) -> Un
onDismissRequest = onClose,
properties = DialogProperties(usePlatformDefaultWidth = false)
) {
Surface(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.background(MaterialTheme.colorScheme.background)
.fillMaxSize()
) {
Surface {
Column {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
modifier = Modifier.padding(10.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
@@ -65,15 +81,16 @@ fun ShowQRDialog(user: User, loadProfilePicture: Boolean, onScan: (String) -> Un
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 10.dp),
modifier = Modifier.fillMaxSize().padding(horizontal = 10.dp),
verticalArrangement = Arrangement.SpaceAround
) {
if (presenting) {
Column(modifier = Modifier.fillMaxWidth()) {
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) {
RobohashAsyncImageProxy(
Column() {
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth()
) {
RobohashFallbackAsyncImage(
robot = user.pubkeyHex,
model = user.profilePicture(),
contentDescription = stringResource(R.string.profile_image),
@@ -86,7 +103,10 @@ fun ShowQRDialog(user: User, loadProfilePicture: Boolean, onScan: (String) -> Un
loadProfilePicture = loadProfilePicture
)
}
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth().padding(top = 5.dp)) {
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth().padding(top = 5.dp)
) {
CreateTextWithEmoji(
text = user.bestDisplayName() ?: user.bestUsername() ?: "",
tags = user.info?.latestMetadata?.tags?.toImmutableListOfLists(),
@@ -98,25 +118,16 @@ fun ShowQRDialog(user: User, loadProfilePicture: Boolean, onScan: (String) -> Un
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Size35dp)
modifier = Modifier.fillMaxWidth().padding(horizontal = Size35dp)
) {
QrCodeDrawer("nostr:${user.pubkeyNpub()}")
}
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 30.dp)
) {
Row(modifier = Modifier.padding(horizontal = 30.dp)) {
Button(
onClick = { presenting = false },
shape = RoundedCornerShape(Size35dp),
modifier = Modifier
.fillMaxWidth()
.height(50.dp),
modifier = Modifier.fillMaxWidth().height(50.dp),
colors = ButtonDefaults
.buttonColors(
containerColor = MaterialTheme.colorScheme.primary
@@ -93,7 +93,7 @@ import com.vitorpamplona.amethyst.ui.actions.NewPostViewModel
import com.vitorpamplona.amethyst.ui.actions.ServerOption
import com.vitorpamplona.amethyst.ui.actions.UploadFromGallery
import com.vitorpamplona.amethyst.ui.components.LoadNote
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
@@ -699,7 +699,7 @@ fun ShortChannelHeader(
}
} else {
channel.profilePicture()?.let {
RobohashAsyncImageProxy(
RobohashFallbackAsyncImage(
robot = channel.idHex,
model = it,
contentDescription = stringResource(R.string.profile_image),
@@ -109,13 +109,13 @@ import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
import com.vitorpamplona.amethyst.ui.navigation.ShowQRDialog
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
import com.vitorpamplona.amethyst.ui.note.ErrorMessageDialog
import com.vitorpamplona.amethyst.ui.note.LightningAddressIcon
import com.vitorpamplona.amethyst.ui.note.LoadAddressableNote
import com.vitorpamplona.amethyst.ui.note.payViaIntent
import com.vitorpamplona.amethyst.ui.note.routeToMessage
import com.vitorpamplona.amethyst.ui.qrcode.ShowQRDialog
import com.vitorpamplona.amethyst.ui.screen.FeedState
import com.vitorpamplona.amethyst.ui.screen.LnZapFeedView
import com.vitorpamplona.amethyst.ui.screen.NostrUserAppRecommendationsFeedViewModel