Skip to content

Commit

Permalink
Moving more variables to remember clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed May 23, 2023
1 parent a3fc22a commit 0bf94f3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ private fun DisplayEvent(

noteBase?.let {
val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return
val channel = note.channel()
val note = remember(noteState) { noteState?.note } ?: return
val channel = remember(noteState) { note.channel() }

if (note.event is ChannelCreateEvent) {
CreateClickableText(
Expand All @@ -105,7 +105,7 @@ private fun DisplayEvent(
CreateClickableText(
clickablePart = channel.toBestDisplayName(),
suffix = "${nip19.additionalChars} ",
route = "Channel/${note.channel()?.idHex}",
route = "Channel/${channel.idHex}",
navController = navController
)
} else {
Expand Down Expand Up @@ -196,7 +196,7 @@ private fun DisplayAddress(

noteBase?.let {
val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return
val note = remember(noteState) { noteState?.note } ?: return

CreateClickableText(
clickablePart = "@${note.idDisplayNote()}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
}
}

val backgroundColor = if (isNew) {
MaterialTheme.colors.primary.copy(0.12f).compositeOver(MaterialTheme.colors.background)
} else {
MaterialTheme.colors.background
val primaryColor = MaterialTheme.colors.primary.copy(0.12f)
val defaultBackgroundColor = MaterialTheme.colors.background

val backgroundColor = remember(isNew) {
if (isNew) {
primaryColor.compositeOver(defaultBackgroundColor)
} else {
defaultBackgroundColor
}
}

val columnModifier = remember(isNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -34,7 +35,7 @@ import com.vitorpamplona.amethyst.model.UserMetadata
import com.vitorpamplona.amethyst.service.Nip05Verifier
import com.vitorpamplona.amethyst.ui.theme.Nip05
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.coroutines.launch
import java.util.Date

@Composable
Expand All @@ -50,9 +51,11 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Bool
mutableStateOf(default)
}

val scope = rememberCoroutineScope()

LaunchedEffect(key1 = user) {
if (nip05Verified.value == null) {
withContext(Dispatchers.IO) {
scope.launch(Dispatchers.IO) {
user.nip05?.ifBlank { null }?.let { nip05 ->
Nip05Verifier().verifyNip05(
nip05,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,14 @@ private fun FirstUserInfoRow(
@Composable
fun TimeAgo(time: Long) {
val context = LocalContext.current

var timeStr by remember { mutableStateOf("") }

LaunchedEffect(key1 = time) {
withContext(Dispatchers.IO) {
timeStr = timeAgo(time, context = context)
val newTimeStr = timeAgo(time, context = context)
if (newTimeStr != timeStr) {
timeStr = newTimeStr
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ fun ZapReaction(
scope.launch(Dispatchers.IO) {
if (!wasZappedByLoggedInUser) {
wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote)
zappingProgress = 1f
}

zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote))

if (wasZappedByLoggedInUser) {
zappingProgress = 1f
}
}
}

Expand Down

0 comments on commit 0bf94f3

Please sign in to comment.