Moving more variables to remember clauses

This commit is contained in:
Vitor Pamplona
2023-05-22 20:04:23 -04:00
parent a3fc22a04a
commit 0bf94f316f
5 changed files with 26 additions and 13 deletions

View File

@ -84,8 +84,8 @@ private fun DisplayEvent(
noteBase?.let { noteBase?.let {
val noteState by it.live().metadata.observeAsState() val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return val note = remember(noteState) { noteState?.note } ?: return
val channel = note.channel() val channel = remember(noteState) { note.channel() }
if (note.event is ChannelCreateEvent) { if (note.event is ChannelCreateEvent) {
CreateClickableText( CreateClickableText(
@ -105,7 +105,7 @@ private fun DisplayEvent(
CreateClickableText( CreateClickableText(
clickablePart = channel.toBestDisplayName(), clickablePart = channel.toBestDisplayName(),
suffix = "${nip19.additionalChars} ", suffix = "${nip19.additionalChars} ",
route = "Channel/${note.channel()?.idHex}", route = "Channel/${channel.idHex}",
navController = navController navController = navController
) )
} else { } else {
@ -196,7 +196,7 @@ private fun DisplayAddress(
noteBase?.let { noteBase?.let {
val noteState by it.live().metadata.observeAsState() val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return val note = remember(noteState) { noteState?.note } ?: return
CreateClickableText( CreateClickableText(
clickablePart = "@${note.idDisplayNote()}", clickablePart = "@${note.idDisplayNote()}",

View File

@ -82,10 +82,15 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
} }
} }
val backgroundColor = if (isNew) { val primaryColor = MaterialTheme.colors.primary.copy(0.12f)
MaterialTheme.colors.primary.copy(0.12f).compositeOver(MaterialTheme.colors.background) val defaultBackgroundColor = MaterialTheme.colors.background
val backgroundColor = remember(isNew) {
if (isNew) {
primaryColor.compositeOver(defaultBackgroundColor)
} else { } else {
MaterialTheme.colors.background defaultBackgroundColor
}
} }
val columnModifier = remember(isNew) { val columnModifier = remember(isNew) {

View File

@ -19,6 +19,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.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -34,7 +35,7 @@ import com.vitorpamplona.amethyst.model.UserMetadata
import com.vitorpamplona.amethyst.service.Nip05Verifier import com.vitorpamplona.amethyst.service.Nip05Verifier
import com.vitorpamplona.amethyst.ui.theme.Nip05 import com.vitorpamplona.amethyst.ui.theme.Nip05
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.launch
import java.util.Date import java.util.Date
@Composable @Composable
@ -50,9 +51,11 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Bool
mutableStateOf(default) mutableStateOf(default)
} }
val scope = rememberCoroutineScope()
LaunchedEffect(key1 = user) { LaunchedEffect(key1 = user) {
if (nip05Verified.value == null) { if (nip05Verified.value == null) {
withContext(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
user.nip05?.ifBlank { null }?.let { nip05 -> user.nip05?.ifBlank { null }?.let { nip05 ->
Nip05Verifier().verifyNip05( Nip05Verifier().verifyNip05(
nip05, nip05,

View File

@ -1169,12 +1169,14 @@ private fun FirstUserInfoRow(
@Composable @Composable
fun TimeAgo(time: Long) { fun TimeAgo(time: Long) {
val context = LocalContext.current val context = LocalContext.current
var timeStr by remember { mutableStateOf("") } var timeStr by remember { mutableStateOf("") }
LaunchedEffect(key1 = time) { LaunchedEffect(key1 = time) {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
timeStr = timeAgo(time, context = context) val newTimeStr = timeAgo(time, context = context)
if (newTimeStr != timeStr) {
timeStr = newTimeStr
}
} }
} }

View File

@ -352,10 +352,13 @@ fun ZapReaction(
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
if (!wasZappedByLoggedInUser) { if (!wasZappedByLoggedInUser) {
wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote) wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote)
zappingProgress = 1f
} }
zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote)) zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote))
if (wasZappedByLoggedInUser) {
zappingProgress = 1f
}
} }
} }