Removing the X to delete reaction in favor of a Selected background

This commit is contained in:
Vitor Pamplona
2024-06-21 13:18:48 -04:00
parent 7a22b3df71
commit d2f06f5310
4 changed files with 77 additions and 64 deletions

View File

@@ -48,15 +48,12 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.ripple.rememberRipple import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ElevatedCard import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProgressIndicatorDefaults import androidx.compose.material3.ProgressIndicatorDefaults
@@ -135,6 +132,8 @@ import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
import com.vitorpamplona.amethyst.ui.theme.TinyBorders import com.vitorpamplona.amethyst.ui.theme.TinyBorders
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
import com.vitorpamplona.amethyst.ui.theme.reactionBox
import com.vitorpamplona.amethyst.ui.theme.selectedReactionBoxModifier
import com.vitorpamplona.quartz.encoders.Nip30CustomEmoji import com.vitorpamplona.quartz.encoders.Nip30CustomEmoji
import com.vitorpamplona.quartz.events.BaseTextNoteEvent import com.vitorpamplona.quartz.events.BaseTextNoteEvent
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
@@ -1305,7 +1304,6 @@ private fun BoostTypeChoicePopup(
} }
} }
@OptIn(ExperimentalLayoutApi::class)
@Composable @Composable
fun ReactionChoicePopup( fun ReactionChoicePopup(
baseNote: Note, baseNote: Note,
@@ -1357,7 +1355,7 @@ fun ReactionChoicePopupContent(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
) { ) {
FlowRow( FlowRow(
modifier = HalfPadding, modifier = Modifier.padding(horizontal = 3.dp),
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
) { ) {
@@ -1394,72 +1392,60 @@ fun ReactionChoicePopupPeeview() {
), ),
onClick = {}, onClick = {},
onChangeAmount = {}, onChangeAmount = {},
toRemove = persistentSetOf(), toRemove = persistentSetOf("\uD83D\uDE80"),
) )
} }
} }
@Composable @Composable
@OptIn(ExperimentalFoundationApi::class)
private fun ActionableReactionButton( private fun ActionableReactionButton(
reactionType: String, reactionType: String,
onClick: () -> Unit, onClick: () -> Unit,
onChangeAmount: () -> Unit, onChangeAmount: () -> Unit,
toRemove: ImmutableSet<String>, toRemove: ImmutableSet<String>,
) { ) {
val thisModifier = ClickableBox(
Modifier modifier = if (reactionType in toRemove) MaterialTheme.colorScheme.selectedReactionBoxModifier else reactionBox,
.padding(horizontal = 8.dp, vertical = 5.dp) onClick = onClick,
.height(Size20dp) onLongClick = onChangeAmount,
.combinedClickable( ) {
role = Role.Button, RenderReaction(reactionType)
interactionSource = remember { MutableInteractionSource() }, }
indication = rememberRipple(bounded = false, radius = Size24dp), }
onClick = onClick,
onLongClick = onChangeAmount,
)
Row(thisModifier, verticalAlignment = Alignment.CenterVertically) { @Composable
if (reactionType.startsWith(":")) { fun RenderReaction(reactionType: String) {
val noStartColon = reactionType.removePrefix(":") if (reactionType.startsWith(":")) {
val url = noStartColon.substringAfter(":") val noStartColon = reactionType.removePrefix(":")
val url = noStartColon.substringAfter(":")
InLineIconRenderer( InLineIconRenderer(
persistentListOf( persistentListOf(
Nip30CustomEmoji.ImageUrlType(url), Nip30CustomEmoji.ImageUrlType(url),
), ),
style = SpanStyle(color = MaterialTheme.colorScheme.onBackground), style = SpanStyle(color = MaterialTheme.colorScheme.onBackground),
maxLines = 1, maxLines = 1,
) )
} else { } else {
when (reactionType) { when (reactionType) {
"+" -> { "+" -> {
LikedIcon(modifier = Modifier.size(20.dp)) LikedIcon(modifier = Size20Modifier)
}
"-" -> {
Text(
text = "\uD83D\uDC4E",
color = MaterialTheme.colorScheme.onBackground,
maxLines = 1,
)
}
else -> {
Text(
"$reactionType",
color = MaterialTheme.colorScheme.onBackground,
maxLines = 1,
)
}
} }
}
if (reactionType in toRemove) { "-" -> {
Icon( Text(
imageVector = Icons.Default.Cancel, text = "\uD83D\uDC4E",
contentDescription = null, color = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.padding(start = 2.dp).size(14.dp), maxLines = 1,
) )
}
else -> {
Text(
reactionType,
color = MaterialTheme.colorScheme.onBackground,
maxLines = 1,
)
}
} }
} }
} }

View File

@@ -277,8 +277,7 @@ private fun RenderReactionOption(
width = 1.dp, width = 1.dp,
color = MaterialTheme.colorScheme.surfaceDim, color = MaterialTheme.colorScheme.surfaceDim,
shape = RoundedCornerShape(8.dp), shape = RoundedCornerShape(8.dp),
) ).padding(8.dp),
.padding(8.dp),
) { ) {
if (reactionType.startsWith(":")) { if (reactionType.startsWith(":")) {
val noStartColon = reactionType.removePrefix(":") val noStartColon = reactionType.removePrefix(":")
@@ -298,13 +297,15 @@ private fun RenderReactionOption(
} else { } else {
when (reactionType) { when (reactionType) {
"+" -> { "+" -> {
LikedIcon(modifier = Modifier.size(16.dp), tint = MaterialTheme.colorScheme.onBackground) Row {
LikedIcon(modifier = Modifier.size(20.dp), tint = Color.Unspecified)
Text( Text(
text = "", text = "",
color = MaterialTheme.colorScheme.onBackground, color = MaterialTheme.colorScheme.onBackground,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
) )
}
} }
"-" -> "-" ->
Text( Text(

View File

@@ -268,3 +268,9 @@ val hashVerifierMark = Modifier.width(40.dp).height(40.dp).padding(10.dp)
val noteComposeRelayBox = Modifier.width(55.dp).heightIn(min = 17.dp).padding(start = 2.dp, end = 1.dp) val noteComposeRelayBox = Modifier.width(55.dp).heightIn(min = 17.dp).padding(start = 2.dp, end = 1.dp)
val previewCardImageModifier = Modifier.fillMaxWidth().heightIn(max = 200.dp).padding(bottom = 5.dp) val previewCardImageModifier = Modifier.fillMaxWidth().heightIn(max = 200.dp).padding(bottom = 5.dp)
val reactionBox =
Modifier
.padding(horizontal = 3.dp, vertical = 6.dp)
.height(Size30dp)
.padding(5.dp)

View File

@@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
@@ -162,6 +163,22 @@ val LightInnerPostBorderModifier =
.clip(shape = QuoteBorder) .clip(shape = QuoteBorder)
.border(1.dp, LightSubtleBorder, QuoteBorder) .border(1.dp, LightSubtleBorder, QuoteBorder)
val DarkSelectedReactionBoxModifier =
Modifier
.padding(horizontal = 3.dp, vertical = 6.dp)
.height(Size30dp)
.clip(shape = SmallBorder)
.background(DarkColorPalette.secondaryContainer)
.padding(5.dp)
val LightSelectedReactionBoxModifier =
Modifier
.padding(horizontal = 3.dp, vertical = 6.dp)
.height(Size30dp)
.clip(shape = SmallBorder)
.background(LightColorPalette.secondaryContainer)
.padding(5.dp)
val DarkChannelNotePictureModifier = val DarkChannelNotePictureModifier =
Modifier Modifier
.size(30.dp) .size(30.dp)
@@ -361,6 +378,9 @@ val ColorScheme.relayIconModifier: Modifier
val ColorScheme.largeRelayIconModifier: Modifier val ColorScheme.largeRelayIconModifier: Modifier
get() = if (isLight) LightLargeRelayIconModifier else DarkLargeRelayIconModifier get() = if (isLight) LightLargeRelayIconModifier else DarkLargeRelayIconModifier
val ColorScheme.selectedReactionBoxModifier: Modifier
get() = if (isLight) LightSelectedReactionBoxModifier else DarkSelectedReactionBoxModifier
val ColorScheme.chartStyle: ChartStyle val ColorScheme.chartStyle: ChartStyle
get() { get() {
val defaultColors = if (isLight) DefaultColors.Light else DefaultColors.Dark val defaultColors = if (isLight) DefaultColors.Light else DefaultColors.Dark