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

View File

@ -586,7 +586,7 @@ fun RenderCommunitiesThumb(baseNote: Note, accountViewModel: AccountViewModel, n
)
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)
ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
}
@ -700,7 +700,7 @@ fun RenderChannelThumb(baseNote: Note, channel: Channel, accountViewModel: Accou
)
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)
ZapReaction(baseNote = baseNote, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
}

View File

@ -553,7 +553,7 @@ private fun StatusRow(
Column(modifier = ReactionRowHeightChat) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = ReactionRowHeightChat) {
LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel)
LikeReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel, nav)
Spacer(modifier = StdHorzSpacer)
ZapReaction(baseNote, MaterialTheme.colors.placeholderText, accountViewModel)
Spacer(modifier = DoubleHorzSpacer)

View File

@ -712,7 +712,7 @@ private fun ShortCommunityActionOptions(
}
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)
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)) {
emojisToShow.forEach { emoji ->
if (onClick != null) {
@ -2046,14 +2046,14 @@ private fun EmojiListOptions(
@Composable
fun RemoveButton(onClick: () -> Unit) {
Button(
modifier = Modifier.padding(horizontal = 3.dp),
modifier = Modifier.padding(start = 3.dp),
onClick = onClick,
shape = ButtonBorder,
colors = ButtonDefaults
.buttonColors(
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)
}
@ -2069,7 +2069,7 @@ fun AddButton(text: Int = R.string.add, onClick: () -> Unit) {
.buttonColors(
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)
}

View File

@ -206,7 +206,7 @@ private fun InnerReactionRow(
) {
val (value, elapsed) = measureTimedValue {
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")
@ -713,6 +713,7 @@ fun LikeReaction(
baseNote: Note,
grayTint: Color,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
iconSize: Dp = 20.dp,
heartSize: Dp = 16.dp,
iconFontSize: TextUnit = Font14SP
@ -755,7 +756,11 @@ fun LikeReaction(
LikeText(baseNote, grayTint)
if (wantsToChangeReactionSymbol) {
UpdateReactionTypeDialog({ wantsToChangeReactionSymbol = false }, accountViewModel = accountViewModel)
UpdateReactionTypeDialog(
{ wantsToChangeReactionSymbol = false },
accountViewModel = accountViewModel,
nav
)
}
if (wantsToReact) {

View File

@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.ui.note
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
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.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
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.placeholderText
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
class UpdateReactionTypeViewModel(val account: Account) : ViewModel() {
var nextChoice by mutableStateOf(TextFieldValue(""))
@ -117,7 +120,11 @@ class UpdateReactionTypeViewModel(val account: Account) : ViewModel() {
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun UpdateReactionTypeDialog(onClose: () -> Unit, nip47uri: String? = null, accountViewModel: AccountViewModel) {
fun UpdateReactionTypeDialog(
onClose: () -> Unit,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
val postViewModel: UpdateReactionTypeViewModel = viewModel(
key = accountViewModel.userProfile().pubkeyHex,
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)
}
}
@ -297,7 +307,7 @@ private fun RenderReactionOption(
}
@Composable
private fun EmojiSelector(accountViewModel: AccountViewModel, onClick: ((EmojiUrl) -> Unit)? = null) {
private fun EmojiSelector(accountViewModel: AccountViewModel, nav: (String) -> Unit, onClick: ((EmojiUrl) -> Unit)? = null) {
LoadAddressableNote(
aTag = ATag(
EmojiPackSelectionEvent.kind,
@ -312,14 +322,14 @@ private fun EmojiSelector(accountViewModel: AccountViewModel, onClick: ((EmojiUr
}.distinctUntilChanged().observeAsState((usersEmojiList.event as? EmojiPackSelectionEvent)?.taggedAddresses())
collections?.let {
EmojiCollectionGallery(it, accountViewModel, onClick)
EmojiCollectionGallery(it, accountViewModel, nav, onClick)
}
}
}
}
@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 bgColor = remember { mutableStateOf(color) }
@ -331,7 +341,7 @@ fun EmojiCollectionGallery(emojiCollections: List<ATag>, accountViewModel: Accou
itemsIndexed(emojiCollections, key = { _, item -> item.toTag() }) { _, item ->
LoadAddressableNote(aTag = item) {
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
private fun WatchAndRenderNote(
it: AddressableNote,
emojiPack: AddressableNote,
bgColor: MutableState<Color>,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
onClick: ((EmojiUrl) -> Unit)?
) {
RenderEmojiPack(
baseNote = it,
actionable = false,
backgroundColor = bgColor,
accountViewModel = accountViewModel,
onClick = onClick
)
val scope = rememberCoroutineScope()
Column(
Modifier
.fillMaxWidth()
.clickable {
scope.launch {
routeFor(emojiPack, accountViewModel.userProfile())?.let {
nav(it)
}
}
}
) {
RenderEmojiPack(
baseNote = emojiPack,
actionable = false,
backgroundColor = bgColor,
accountViewModel = accountViewModel,
onClick = onClick
)
}
}

View File

@ -884,7 +884,7 @@ private fun ShortChannelActionOptions(
var popupExpanded by remember { mutableStateOf(false) }
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)
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
Spacer(modifier = StdHorzSpacer)
@ -947,7 +947,7 @@ private fun LiveChannelActionOptions(
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)
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
}

View File

@ -396,7 +396,7 @@ fun ReactionsColumn(baseNote: Note, accountViewModel: AccountViewModel, nav: (St
BoostReaction(baseNote, accountViewModel, iconSize = 40.dp) {
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)
ViewCountReaction(baseNote, grayTint = MaterialTheme.colors.onBackground, barChartSize = 39.dp, viewCountColorFilter = MaterialTheme.colors.onBackgroundColorFilter)
}