Fixes Chat preview images when no image has been set.

This commit is contained in:
Vitor Pamplona
2024-03-21 08:50:37 -04:00
parent c1756b75a7
commit 64909bfb32
3 changed files with 31 additions and 45 deletions
@@ -131,7 +131,7 @@ abstract class Channel(val idHex: String) {
} }
open fun profilePicture(): String? { open fun profilePicture(): String? {
return creator?.profilePicture() return creator?.info?.banner
} }
open fun updateChannelInfo( open fun updateChannelInfo(
@@ -70,6 +70,7 @@ import com.vitorpamplona.amethyst.model.ParticipantListBuilder
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.layouts.LeftPictureLayout import com.vitorpamplona.amethyst.ui.layouts.LeftPictureLayout
import com.vitorpamplona.amethyst.ui.note.elements.BannerImage
import com.vitorpamplona.amethyst.ui.screen.equalImmutableLists import com.vitorpamplona.amethyst.ui.screen.equalImmutableLists
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader
@@ -307,29 +308,29 @@ fun RenderClassifiedsThumb(
), ),
) )
RenderClassifiedsThumb(card, baseNote.author) InnerRenderClassifiedsThumb(card, baseNote)
} }
@Preview @Preview
@Composable @Composable
fun RenderClassifiedsThumbPreview() { fun RenderClassifiedsThumbPreview() {
Surface(Modifier.size(200.dp)) { Surface(Modifier.size(200.dp)) {
RenderClassifiedsThumb( InnerRenderClassifiedsThumb(
card = card =
ClassifiedsThumb( ClassifiedsThumb(
image = null, image = null,
title = "Like New", title = "Like New",
price = Price("800000", "SATS", null), price = Price("800000", "SATS", null),
), ),
author = null, note = Note("hex"),
) )
} }
} }
@Composable @Composable
fun RenderClassifiedsThumb( fun InnerRenderClassifiedsThumb(
card: ClassifiedsThumb, card: ClassifiedsThumb,
author: User?, note: Note,
) { ) {
Box( Box(
Modifier.fillMaxWidth().aspectRatio(1f), Modifier.fillMaxWidth().aspectRatio(1f),
@@ -342,8 +343,7 @@ fun RenderClassifiedsThumb(
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) )
} } ?: run { DisplayAuthorBanner(note) }
?: run { author?.let { DisplayAuthorBanner(it) } }
Row( Row(
Modifier.fillMaxWidth().background(Color.Black.copy(0.6f)).padding(Size5dp), Modifier.fillMaxWidth().background(Color.Black.copy(0.6f)).padding(Size5dp),
@@ -451,8 +451,7 @@ fun RenderLiveActivityThumb(
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize().clip(QuoteBorder), modifier = Modifier.fillMaxSize().clip(QuoteBorder),
) )
} } ?: run { DisplayAuthorBanner(baseNote) }
?: run { baseNote.author?.let { DisplayAuthorBanner(it) } }
Box(Modifier.padding(10.dp)) { Box(Modifier.padding(10.dp)) {
Crossfade(targetState = card.status, label = "RenderLiveActivityThumb") { Crossfade(targetState = card.status, label = "RenderLiveActivityThumb") {
@@ -560,8 +559,7 @@ fun RenderCommunitiesThumb(
modifier = Modifier.fillMaxSize().clip(QuoteBorder), modifier = Modifier.fillMaxSize().clip(QuoteBorder),
) )
} }
} } ?: run { DisplayAuthorBanner(baseNote) }
?: run { baseNote.author?.let { DisplayAuthorBanner(it) } }
}, },
onTitleRow = { onTitleRow = {
Text( Text(
@@ -781,16 +779,13 @@ fun RenderChannelThumb(
LeftPictureLayout( LeftPictureLayout(
onImage = { onImage = {
cover?.let { cover?.let {
Box(contentAlignment = BottomStart) { AsyncImage(
AsyncImage( model = it,
model = it, contentDescription = null,
contentDescription = null, contentScale = ContentScale.Crop,
contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize().clip(QuoteBorder),
modifier = Modifier.fillMaxSize().clip(QuoteBorder), )
) } ?: run { DisplayAuthorBanner(baseNote) }
}
}
?: run { baseNote.author?.let { DisplayAuthorBanner(it) } }
}, },
onTitleRow = { onTitleRow = {
Text( Text(
@@ -857,18 +852,10 @@ fun Gallery(
} }
@Composable @Composable
fun DisplayAuthorBanner(author: User) { fun DisplayAuthorBanner(note: Note) {
val picture by val authorState by note.live().authorChanges.observeAsState(note.author)
author
.live()
.metadata
.map { it.user.info?.banner?.ifBlank { null } ?: it.user.info?.picture?.ifBlank { null } }
.observeAsState()
AsyncImage( authorState?.let { author ->
model = picture, BannerImage(author, Modifier.fillMaxSize().clip(QuoteBorder))
contentDescription = null, }
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize().clip(QuoteBorder),
)
} }
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.ui.note.elements
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -42,7 +41,6 @@ import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.Size55dp
import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader
import com.vitorpamplona.amethyst.ui.theme.imageHeaderBannerSize
@Composable @Composable
fun DefaultImageHeader( fun DefaultImageHeader(
@@ -63,7 +61,10 @@ fun DefaultImageHeader(
} }
@Composable @Composable
private fun BoxScope.BannerImage(author: User) { fun BannerImage(
author: User,
imageModifier: Modifier = Modifier.fillMaxWidth().heightIn(max = 200.dp),
) {
val currentInfo by author.live().userMetadataInfo.observeAsState() val currentInfo by author.live().userMetadataInfo.observeAsState()
currentInfo?.banner?.let { currentInfo?.banner?.let {
AsyncImage( AsyncImage(
@@ -73,18 +74,16 @@ private fun BoxScope.BannerImage(author: User) {
R.string.preview_card_image_for, R.string.preview_card_image_for,
it, it,
), ),
contentScale = ContentScale.FillWidth, contentScale = ContentScale.Crop,
modifier = modifier = imageModifier,
Modifier placeholder = painterResource(R.drawable.profile_banner),
.fillMaxWidth()
.heightIn(max = 200.dp),
) )
} ?: run { } ?: run {
Image( Image(
painter = painterResource(R.drawable.profile_banner), painter = painterResource(R.drawable.profile_banner),
contentDescription = stringResource(R.string.profile_banner), contentDescription = stringResource(R.string.profile_banner),
contentScale = ContentScale.FillWidth, contentScale = ContentScale.Crop,
modifier = imageHeaderBannerSize, modifier = imageModifier,
) )
} }
} }