From 2f2914077b2e2745b077d3a26fdb3fd1e84636b8 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 28 Oct 2023 16:38:12 -0400 Subject: [PATCH] Speeding up the boost method --- .../amethyst/ui/note/ReactionsRow.kt | 25 ++++--------------- .../ui/screen/loggedIn/AccountViewModel.kt | 24 ++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) 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 ba6a1405d..a01690803 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 @@ -645,25 +645,8 @@ fun BoostReaction( IconButton( modifier = iconButtonModifier, onClick = { - if (accountViewModel.isWriteable()) { - if (accountViewModel.hasBoosted(baseNote)) { - accountViewModel.deleteBoostsTo(baseNote) - } else { - wantsToBoost = true - } - } else { - if (accountViewModel.loggedInWithExternalSigner()) { - if (accountViewModel.hasBoosted(baseNote)) { - accountViewModel.deleteBoostsTo(baseNote) - } else { - wantsToBoost = true - } - } else { - accountViewModel.toast( - R.string.read_only_user, - R.string.login_with_a_private_key_to_be_able_to_boost_posts - ) - } + accountViewModel.tryBoost(baseNote) { + wantsToBoost = true } } ) { @@ -697,7 +680,9 @@ fun BoostIcon(baseNote: Note, iconSize: Dp = Size20dp, grayTint: Color, accountV baseNote.live().boosts.map { if (it.note.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint }.distinctUntilChanged() - }.observeAsState(grayTint) + }.observeAsState( + if (baseNote.isBoostedBy(accountViewModel.userProfile())) Color.Unspecified else grayTint + ) val iconModifier = remember { Modifier.size(iconSize) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 66362fb0e..8fe2f8239 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -14,6 +14,7 @@ import androidx.lifecycle.map import androidx.lifecycle.viewModelScope import coil.imageLoader import coil.request.ImageRequest +import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.AccountState import com.vitorpamplona.amethyst.model.AddressableNote @@ -915,6 +916,29 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View onReady(newSortedMentions) } } + + fun tryBoost(baseNote: Note, onMore: () -> Unit) { + if (isWriteable()) { + if (hasBoosted(baseNote)) { + deleteBoostsTo(baseNote) + } else { + onMore() + } + } else { + if (loggedInWithExternalSigner()) { + if (hasBoosted(baseNote)) { + deleteBoostsTo(baseNote) + } else { + onMore() + } + } else { + toast( + R.string.read_only_user, + R.string.login_with_a_private_key_to_be_able_to_boost_posts + ) + } + } + } } class HasNotificationDot(bottomNavigationItems: ImmutableList, val account: Account) {