From 52af109b4eb8ea91716de96090693d584b32e2c4 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 26 Jun 2023 20:38:06 -0400 Subject: [PATCH] Minor adjustments in threading --- .../amethyst/service/model/Event.kt | 2 +- .../amethyst/ui/note/ReactionsRow.kt | 22 +++++++++++++------ .../vitorpamplona/amethyst/ui/theme/Shape.kt | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/model/Event.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/model/Event.kt index 2ccc74610..8a753d7c2 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/model/Event.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/model/Event.kt @@ -55,7 +55,7 @@ open class Event( } override fun zapraiserAmount() = tags.firstOrNull() { - (it.size > 1 && it[0].equals("zapraiser", true)) + (it.size > 1 && it[0] == "zapraiser") }?.get(1)?.toLongOrNull() override fun zapAddress() = tags.firstOrNull { it.size > 1 && it[0] == "zap" }?.get(1) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt index 2249fd46f..2e46aadaa 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt @@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.material.Button import androidx.compose.material.ButtonDefaults import androidx.compose.material.CircularProgressIndicator @@ -83,6 +82,7 @@ import com.vitorpamplona.amethyst.ui.theme.Font14SP import com.vitorpamplona.amethyst.ui.theme.HalfDoubleVertSpacer import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding import com.vitorpamplona.amethyst.ui.theme.Height4dpModifier +import com.vitorpamplona.amethyst.ui.theme.ModifierWidth3dp import com.vitorpamplona.amethyst.ui.theme.NoSoTinyBorders import com.vitorpamplona.amethyst.ui.theme.ReactionRowExpandButton import com.vitorpamplona.amethyst.ui.theme.ReactionRowHeight @@ -522,7 +522,7 @@ private fun SlidingAnimation(baseCount: Int, textColor: Color) { } ) { count -> Text( - text = remember { showCount(count) }, + text = remember(count) { showCount(count) }, fontSize = Font14SP, color = textColor, modifier = HalfStartPadding, @@ -723,7 +723,9 @@ fun LikeIcon( launch(Dispatchers.Default) { val newReactionType = reactionsState?.note?.isReactedBy(accountViewModel.userProfile())?.firstFullChar() if (reactionType != newReactionType) { - reactionType = newReactionType + launch(Dispatchers.Main) { + reactionType = newReactionType + } } } } @@ -791,7 +793,9 @@ fun LikeText(baseNote: Note, grayTint: Color) { launch(Dispatchers.Default) { val newReactionsCount = reactionsState?.note?.countReactions() ?: 0 if (reactionsCount != newReactionsCount) { - reactionsCount = newReactionsCount + launch(Dispatchers.Main) { + reactionsCount = newReactionsCount + } } } } @@ -923,7 +927,7 @@ fun ZapReaction( } if (zappingProgress > 0.00001 && zappingProgress < 0.99999) { - Spacer(Modifier.width(3.dp)) + Spacer(ModifierWidth3dp) CircularProgressIndicator( progress = animateFloatAsState( @@ -1020,7 +1024,9 @@ private fun ZapIcon( val newWasZapped = accountViewModel.calculateIfNoteWasZappedByAccount(it) if (wasZappedByLoggedInUser != newWasZapped) { - wasZappedByLoggedInUser = newWasZapped + launch(Dispatchers.Main) { + wasZappedByLoggedInUser = newWasZapped + } } } } @@ -1061,7 +1067,9 @@ private fun ZapAmountText( zapsState?.note?.let { val newZapAmount = showAmount(accountViewModel.calculateZapAmount(it)) if (newZapAmount != zapAmountTxt) { - zapAmountTxt = newZapAmount + launch(Dispatchers.Main) { + zapAmountTxt = newZapAmount + } } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt index e753dfdf7..29bc4c2b8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt @@ -90,3 +90,5 @@ val ShowMoreRelaysButtonIconModifier = Modifier.size(15.dp) val ShowMoreRelaysButtonBoxModifer = Modifier.fillMaxWidth().height(25.dp) val ChatBubbleMaxSizeModifier = Modifier.fillMaxWidth(0.85f) + +val ModifierWidth3dp = Modifier.width(3.dp)