Adjusting zap calculations

This commit is contained in:
Vitor Pamplona
2024-06-14 08:31:06 -04:00
parent 52a24d5223
commit 39efc2ef9b
2 changed files with 19 additions and 15 deletions
@@ -44,6 +44,7 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue 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.produceState
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
@@ -163,18 +164,7 @@ private fun Galeries(
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
if (multiSetCard.zapEvents.isNotEmpty()) { if (multiSetCard.zapEvents.isNotEmpty()) {
var zapEvents by DecryptAndRenderZapGallery(multiSetCard, backgroundColor, accountViewModel, nav)
remember(multiSetCard) {
mutableStateOf(
accountViewModel.cachedDecryptAmountMessageInGroup(multiSetCard.zapEvents),
)
}
LaunchedEffect(key1 = Unit) {
accountViewModel.decryptAmountMessageInGroup(multiSetCard.zapEvents) { zapEvents = it }
}
RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
} }
if (multiSetCard.boostEvents.isNotEmpty()) { if (multiSetCard.boostEvents.isNotEmpty()) {
@@ -229,12 +219,27 @@ fun RenderLikeGallery(
} }
} }
@Composable
fun DecryptAndRenderZapGallery(
multiSetCard: MultiSetCard,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
val zapEvents by
produceState(initialValue = accountViewModel.cachedDecryptAmountMessageInGroup(multiSetCard.zapEvents)) {
accountViewModel.decryptAmountMessageInGroup(multiSetCard.zapEvents) { value = it }
}
RenderZapGallery(zapEvents, backgroundColor, accountViewModel, nav)
}
@Composable @Composable
fun RenderZapGallery( fun RenderZapGallery(
zapEvents: ImmutableList<ZapAmountCommentNotification>, zapEvents: ImmutableList<ZapAmountCommentNotification>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
nav: (String) -> Unit,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) { ) {
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
Box( Box(
@@ -34,7 +34,6 @@ import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith import androidx.compose.animation.togetherWith
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@@ -494,8 +493,8 @@ private fun WatchZapAndRenderGallery(
RenderZapGallery( RenderZapGallery(
zapEvents, zapEvents,
backgroundColor, backgroundColor,
nav,
accountViewModel, accountViewModel,
nav,
) )
} }
} }