Skip to content

Commit

Permalink
Merge pull request #1207 from believethehype/main
Browse files Browse the repository at this point in the history
Content DVMS: show amount and personalized status in feed
  • Loading branch information
vitorpamplona authored Dec 2, 2024
2 parents fddb9b1 + 56450cf commit 95774dd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.ui.note

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -33,6 +34,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -55,8 +57,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.distinctUntilChanged
Expand Down Expand Up @@ -91,6 +95,8 @@ import com.vitorpamplona.amethyst.ui.theme.Size5dp
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
import com.vitorpamplona.amethyst.ui.theme.StdPadding
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.bitcoinColor
import com.vitorpamplona.amethyst.ui.theme.nip05
import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.quartz.events.AppDefinitionEvent
import com.vitorpamplona.quartz.events.ChannelCreateEvent
Expand Down Expand Up @@ -542,6 +548,8 @@ data class DVMCard(
val name: String,
val description: String?,
val cover: String?,
val amount: String?,
val personalized: Boolean?,
)

@Composable
Expand Down Expand Up @@ -838,6 +846,71 @@ fun RenderContentDVMThumb(
}
},
onBottomRow = {
card.amount?.let {
var color = Color.DarkGray
var amount = it
if (card.amount == "free" || card.amount == "0") {
color = MaterialTheme.colorScheme.secondary
amount = "Free"
} else if (card.amount == "flexible") {
color = MaterialTheme.colorScheme.primaryContainer
amount = "Flexible"
} else if (card.amount == "") {
color = MaterialTheme.colorScheme.secondaryContainer
amount = "Unknown"
} else {
color = MaterialTheme.colorScheme.primary
amount = card.amount + " Sats"
}
Spacer(modifier = StdVertSpacer)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Absolute.Right,
) {
Text(
textAlign = TextAlign.End,
text = " $amount ",
color = color,
maxLines = 3,
modifier =
Modifier
.padding(start = 4.dp)
.weight(1f, fill = false)
.border(Dp(.1f), color, shape = RoundedCornerShape(20)),
fontSize = 12.sp,
)
}
}
Spacer(modifier = StdHorzSpacer)
card.personalized?.let {
var color = Color.DarkGray
var name = "generic"
if (card.personalized == true) {
color = MaterialTheme.colorScheme.bitcoinColor
name = "Personalized"
} else {
color = MaterialTheme.colorScheme.nip05
name = "Generic"
}
Spacer(modifier = StdVertSpacer)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Absolute.Right,
) {
Text(
textAlign = TextAlign.End,
text = " $name ",
color = color,
maxLines = 3,
modifier =
Modifier
.padding(start = 4.dp)
.weight(1f, fill = false)
.border(Dp(.1f), color, shape = RoundedCornerShape(20)),
fontSize = 12.sp,
)
}
}
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ fun observeAppDefinition(appDefinitionNote: Note): DVMCard {
name = "",
description = "",
cover = null,
amount = "",
personalized = false,
)

val card by
Expand All @@ -647,13 +649,17 @@ fun observeAppDefinition(appDefinitionNote: Note): DVMCard {
name = noteEvent?.appMetaData()?.name ?: "",
description = noteEvent?.appMetaData()?.about ?: "",
cover = noteEvent?.appMetaData()?.profilePicture()?.ifBlank { null },
amount = noteEvent?.appMetaData()?.amount ?: "",
personalized = noteEvent?.appMetaData()?.personalized ?: false,
)
}.distinctUntilChanged()
.observeAsState(
DVMCard(
name = noteEvent.appMetaData()?.name ?: "",
description = noteEvent.appMetaData()?.about ?: "",
cover = noteEvent.appMetaData()?.profilePicture()?.ifBlank { null },
amount = noteEvent.appMetaData()?.amount ?: "",
personalized = noteEvent.appMetaData()?.personalized ?: false,
),
)

Expand Down

0 comments on commit 95774dd

Please sign in to comment.