diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt index 8a5e53afb..4cb65397a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt @@ -131,7 +131,7 @@ abstract class Channel(val idHex: String) { } open fun profilePicture(): String? { - return creator?.profilePicture() + return creator?.info?.banner } open fun updateChannelInfo( diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt index 222a748fa..708884a0f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChannelCardCompose.kt @@ -70,6 +70,7 @@ import com.vitorpamplona.amethyst.model.ParticipantListBuilder import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.ui.components.SensitivityWarning 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.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader @@ -307,29 +308,29 @@ fun RenderClassifiedsThumb( ), ) - RenderClassifiedsThumb(card, baseNote.author) + InnerRenderClassifiedsThumb(card, baseNote) } @Preview @Composable fun RenderClassifiedsThumbPreview() { Surface(Modifier.size(200.dp)) { - RenderClassifiedsThumb( + InnerRenderClassifiedsThumb( card = ClassifiedsThumb( image = null, title = "Like New", price = Price("800000", "SATS", null), ), - author = null, + note = Note("hex"), ) } } @Composable -fun RenderClassifiedsThumb( +fun InnerRenderClassifiedsThumb( card: ClassifiedsThumb, - author: User?, + note: Note, ) { Box( Modifier.fillMaxWidth().aspectRatio(1f), @@ -342,8 +343,7 @@ fun RenderClassifiedsThumb( contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize(), ) - } - ?: run { author?.let { DisplayAuthorBanner(it) } } + } ?: run { DisplayAuthorBanner(note) } Row( Modifier.fillMaxWidth().background(Color.Black.copy(0.6f)).padding(Size5dp), @@ -451,8 +451,7 @@ fun RenderLiveActivityThumb( contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize().clip(QuoteBorder), ) - } - ?: run { baseNote.author?.let { DisplayAuthorBanner(it) } } + } ?: run { DisplayAuthorBanner(baseNote) } Box(Modifier.padding(10.dp)) { Crossfade(targetState = card.status, label = "RenderLiveActivityThumb") { @@ -560,8 +559,7 @@ fun RenderCommunitiesThumb( modifier = Modifier.fillMaxSize().clip(QuoteBorder), ) } - } - ?: run { baseNote.author?.let { DisplayAuthorBanner(it) } } + } ?: run { DisplayAuthorBanner(baseNote) } }, onTitleRow = { Text( @@ -781,16 +779,13 @@ fun RenderChannelThumb( LeftPictureLayout( onImage = { cover?.let { - Box(contentAlignment = BottomStart) { - AsyncImage( - model = it, - contentDescription = null, - contentScale = ContentScale.Crop, - modifier = Modifier.fillMaxSize().clip(QuoteBorder), - ) - } - } - ?: run { baseNote.author?.let { DisplayAuthorBanner(it) } } + AsyncImage( + model = it, + contentDescription = null, + contentScale = ContentScale.Crop, + modifier = Modifier.fillMaxSize().clip(QuoteBorder), + ) + } ?: run { DisplayAuthorBanner(baseNote) } }, onTitleRow = { Text( @@ -857,18 +852,10 @@ fun Gallery( } @Composable -fun DisplayAuthorBanner(author: User) { - val picture by - author - .live() - .metadata - .map { it.user.info?.banner?.ifBlank { null } ?: it.user.info?.picture?.ifBlank { null } } - .observeAsState() +fun DisplayAuthorBanner(note: Note) { + val authorState by note.live().authorChanges.observeAsState(note.author) - AsyncImage( - model = picture, - contentDescription = null, - contentScale = ContentScale.Crop, - modifier = Modifier.fillMaxSize().clip(QuoteBorder), - ) + authorState?.let { author -> + BannerImage(author, Modifier.fillMaxSize().clip(QuoteBorder)) + } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DefaultImageHeader.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DefaultImageHeader.kt index 488cf5861..e021842b5 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DefaultImageHeader.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DefaultImageHeader.kt @@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.ui.note.elements import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn 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.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader -import com.vitorpamplona.amethyst.ui.theme.imageHeaderBannerSize @Composable fun DefaultImageHeader( @@ -63,7 +61,10 @@ fun DefaultImageHeader( } @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() currentInfo?.banner?.let { AsyncImage( @@ -73,18 +74,16 @@ private fun BoxScope.BannerImage(author: User) { R.string.preview_card_image_for, it, ), - contentScale = ContentScale.FillWidth, - modifier = - Modifier - .fillMaxWidth() - .heightIn(max = 200.dp), + contentScale = ContentScale.Crop, + modifier = imageModifier, + placeholder = painterResource(R.drawable.profile_banner), ) } ?: run { Image( painter = painterResource(R.drawable.profile_banner), contentDescription = stringResource(R.string.profile_banner), - contentScale = ContentScale.FillWidth, - modifier = imageHeaderBannerSize, + contentScale = ContentScale.Crop, + modifier = imageModifier, ) } }