Adjustments to allow removing of the selected emoji packs from the reaction setup

This commit is contained in:
Vitor Pamplona
2023-07-12 18:19:20 -04:00
parent 24a0be9c3a
commit 135eb6763a
7 changed files with 57 additions and 27 deletions
@@ -586,7 +586,7 @@ fun RenderCommunitiesThumb(baseNote: Note, accountViewModel: AccountViewModel, n
) )
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
LikeReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) LikeReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
} }
@@ -700,7 +700,7 @@ fun RenderChannelThumb(baseNote: Note, channel: Channel, accountViewModel: Accou
) )
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
LikeReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) LikeReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
} }
@@ -553,7 +553,7 @@ private fun StatusRow(
Column(modifier = ReactionRowHeightChat) { Column(modifier = ReactionRowHeightChat) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = ReactionRowHeightChat) { Row(verticalAlignment = Alignment.CenterVertically, modifier = ReactionRowHeightChat) {
LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel) LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel) ZapReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel)
Spacer(modifier = DoubleHorzSpacer) Spacer(modifier = DoubleHorzSpacer)
@@ -712,7 +712,7 @@ private fun ShortCommunityActionOptions(
} }
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
LikeReaction(baseNote = note, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) LikeReaction(baseNote = note, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote = note, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) ZapReaction(baseNote = note, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
@@ -1962,7 +1962,7 @@ public fun RenderEmojiPack(
} }
} }
Box { Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.TopCenter) {
FlowRow(modifier = Modifier.padding(top = 5.dp)) { FlowRow(modifier = Modifier.padding(top = 5.dp)) {
emojisToShow.forEach { emoji -> emojisToShow.forEach { emoji ->
if (onClick != null) { if (onClick != null) {
@@ -2046,14 +2046,14 @@ private fun EmojiListOptions(
@Composable @Composable
fun RemoveButton(onClick: () -> Unit) { fun RemoveButton(onClick: () -> Unit) {
Button( Button(
modifier = Modifier.padding(horizontal = 3.dp), modifier = Modifier.padding(start = 3.dp),
onClick = onClick, onClick = onClick,
shape = ButtonBorder, shape = ButtonBorder,
colors = ButtonDefaults colors = ButtonDefaults
.buttonColors( .buttonColors(
backgroundColor = MaterialTheme.colors.primary backgroundColor = MaterialTheme.colors.primary
), ),
contentPadding = PaddingValues(vertical = 6.dp, horizontal = 16.dp) contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp)
) { ) {
Text(text = stringResource(R.string.remove), color = Color.White) Text(text = stringResource(R.string.remove), color = Color.White)
} }
@@ -2069,7 +2069,7 @@ fun AddButton(text: Int = R.string.add, onClick: () -> Unit) {
.buttonColors( .buttonColors(
backgroundColor = MaterialTheme.colors.primary backgroundColor = MaterialTheme.colors.primary
), ),
contentPadding = PaddingValues(vertical = 6.dp, horizontal = 16.dp) contentPadding = PaddingValues(vertical = 0.dp, horizontal = 16.dp)
) { ) {
Text(text = stringResource(text), color = Color.White, textAlign = TextAlign.Center) Text(text = stringResource(text), color = Color.White, textAlign = TextAlign.Center)
} }
@@ -206,7 +206,7 @@ private fun InnerReactionRow(
) { ) {
val (value, elapsed) = measureTimedValue { val (value, elapsed) = measureTimedValue {
Row(verticalAlignment = CenterVertically) { Row(verticalAlignment = CenterVertically) {
LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel) LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel, nav)
} }
} }
Log.d("Rendering Metrics", "Reaction Likes: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed") Log.d("Rendering Metrics", "Reaction Likes: ${baseNote.event?.content()?.split("\n")?.getOrNull(0)?.take(15)}.. $elapsed")
@@ -713,6 +713,7 @@ fun LikeReaction(
baseNote: Note, baseNote: Note,
grayTint: Color, grayTint: Color,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit,
iconSize: Dp = 20.dp, iconSize: Dp = 20.dp,
heartSize: Dp = 16.dp, heartSize: Dp = 16.dp,
iconFontSize: TextUnit = Font14SP iconFontSize: TextUnit = Font14SP
@@ -755,7 +756,11 @@ fun LikeReaction(
LikeText(baseNote, grayTint) LikeText(baseNote, grayTint)
if (wantsToChangeReactionSymbol) { if (wantsToChangeReactionSymbol) {
UpdateReactionTypeDialog({ wantsToChangeReactionSymbol = false }, accountViewModel = accountViewModel) UpdateReactionTypeDialog(
{ wantsToChangeReactionSymbol = false },
accountViewModel = accountViewModel,
nav
)
} }
if (wantsToReact) { if (wantsToReact) {
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.ui.note package com.vitorpamplona.amethyst.ui.note
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.ExperimentalLayoutApi
@@ -32,6 +33,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -67,6 +69,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
class UpdateReactionTypeViewModel(val account: Account) : ViewModel() { class UpdateReactionTypeViewModel(val account: Account) : ViewModel() {
var nextChoice by mutableStateOf(TextFieldValue("")) var nextChoice by mutableStateOf(TextFieldValue(""))
@@ -117,7 +120,11 @@ class UpdateReactionTypeViewModel(val account: Account) : ViewModel() {
@OptIn(ExperimentalLayoutApi::class) @OptIn(ExperimentalLayoutApi::class)
@Composable @Composable
fun UpdateReactionTypeDialog(onClose: () -> Unit, nip47uri: String? = null, accountViewModel: AccountViewModel) { fun UpdateReactionTypeDialog(
onClose: () -> Unit,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
val postViewModel: UpdateReactionTypeViewModel = viewModel( val postViewModel: UpdateReactionTypeViewModel = viewModel(
key = accountViewModel.userProfile().pubkeyHex, key = accountViewModel.userProfile().pubkeyHex,
factory = UpdateReactionTypeViewModel.Factory(accountViewModel.account) factory = UpdateReactionTypeViewModel.Factory(accountViewModel.account)
@@ -227,7 +234,10 @@ fun UpdateReactionTypeDialog(onClose: () -> Unit, nip47uri: String? = null, acco
} }
} }
EmojiSelector(accountViewModel) { EmojiSelector(
accountViewModel = accountViewModel,
nav = nav
) {
postViewModel.addChoice(it) postViewModel.addChoice(it)
} }
} }
@@ -297,7 +307,7 @@ private fun RenderReactionOption(
} }
@Composable @Composable
private fun EmojiSelector(accountViewModel: AccountViewModel, onClick: ((EmojiUrl) -> Unit)? = null) { private fun EmojiSelector(accountViewModel: AccountViewModel, nav: (String) -> Unit, onClick: ((EmojiUrl) -> Unit)? = null) {
LoadAddressableNote( LoadAddressableNote(
aTag = ATag( aTag = ATag(
EmojiPackSelectionEvent.kind, EmojiPackSelectionEvent.kind,
@@ -312,14 +322,14 @@ private fun EmojiSelector(accountViewModel: AccountViewModel, onClick: ((EmojiUr
}.distinctUntilChanged().observeAsState((usersEmojiList.event as? EmojiPackSelectionEvent)?.taggedAddresses()) }.distinctUntilChanged().observeAsState((usersEmojiList.event as? EmojiPackSelectionEvent)?.taggedAddresses())
collections?.let { collections?.let {
EmojiCollectionGallery(it, accountViewModel, onClick) EmojiCollectionGallery(it, accountViewModel, nav, onClick)
} }
} }
} }
} }
@Composable @Composable
fun EmojiCollectionGallery(emojiCollections: List<ATag>, accountViewModel: AccountViewModel, onClick: ((EmojiUrl) -> Unit)? = null) { fun EmojiCollectionGallery(emojiCollections: List<ATag>, accountViewModel: AccountViewModel, nav: (String) -> Unit, onClick: ((EmojiUrl) -> Unit)? = null) {
val color = MaterialTheme.colors.background val color = MaterialTheme.colors.background
val bgColor = remember { mutableStateOf(color) } val bgColor = remember { mutableStateOf(color) }
@@ -331,7 +341,7 @@ fun EmojiCollectionGallery(emojiCollections: List<ATag>, accountViewModel: Accou
itemsIndexed(emojiCollections, key = { _, item -> item.toTag() }) { _, item -> itemsIndexed(emojiCollections, key = { _, item -> item.toTag() }) { _, item ->
LoadAddressableNote(aTag = item) { LoadAddressableNote(aTag = item) {
it?.let { it?.let {
WatchAndRenderNote(it, bgColor, accountViewModel, onClick) WatchAndRenderNote(it, bgColor, accountViewModel, nav, onClick)
} }
} }
} }
@@ -340,16 +350,31 @@ fun EmojiCollectionGallery(emojiCollections: List<ATag>, accountViewModel: Accou
@Composable @Composable
private fun WatchAndRenderNote( private fun WatchAndRenderNote(
it: AddressableNote, emojiPack: AddressableNote,
bgColor: MutableState<Color>, bgColor: MutableState<Color>,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onClick: ((EmojiUrl) -> Unit)? onClick: ((EmojiUrl) -> Unit)?
) { ) {
RenderEmojiPack( val scope = rememberCoroutineScope()
baseNote = it,
actionable = false, Column(
backgroundColor = bgColor, Modifier
accountViewModel = accountViewModel, .fillMaxWidth()
onClick = onClick .clickable {
) scope.launch {
routeFor(emojiPack, accountViewModel.userProfile())?.let {
nav(it)
}
}
}
) {
RenderEmojiPack(
baseNote = emojiPack,
actionable = false,
backgroundColor = bgColor,
accountViewModel = accountViewModel,
onClick = onClick
)
}
} }
@@ -884,7 +884,7 @@ private fun ShortChannelActionOptions(
var popupExpanded by remember { mutableStateOf(false) } var popupExpanded by remember { mutableStateOf(false) }
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
@@ -947,7 +947,7 @@ private fun LiveChannelActionOptions(
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
} }
LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel, nav)
Spacer(modifier = StdHorzSpacer) Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
} }
@@ -396,7 +396,7 @@ fun ReactionsColumn(baseNote: Note, accountViewModel: AccountViewModel, nav: (St
BoostReaction(baseNote, accountViewModel, iconSize = 40.dp) { BoostReaction(baseNote, accountViewModel, iconSize = 40.dp) {
wantsToQuote = baseNote wantsToQuote = baseNote
}*/ }*/
LikeReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, accountViewModel, iconSize = 40.dp, heartSize = Size35dp, 28.sp) LikeReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, accountViewModel, nav, iconSize = 40.dp, heartSize = Size35dp, 28.sp)
ZapReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, accountViewModel, iconSize = 40.dp, animationSize = Size35dp) ZapReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, accountViewModel, iconSize = 40.dp, animationSize = Size35dp)
ViewCountReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, barChartSize = 39.dp, viewCountColorFilter = MaterialTheme.colors.onBackgroundColorFilter) ViewCountReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, barChartSize = 39.dp, viewCountColorFilter = MaterialTheme.colors.onBackgroundColorFilter)
} }