From 178582f3c49fc6fc2ac4c11a07d80f211ff9d2db Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 5 Nov 2025 19:03:01 -0500 Subject: [PATCH] Showing the list option in all Follow Buttons --- .../amethyst/ui/note/UserCompose.kt | 64 ++++++++++++++++++- .../amethyst/ui/note/ZapNoteCompose.kt | 60 ++--------------- .../screen/loggedIn/profile/FollowButtons.kt | 22 +++++++ .../loggedIn/profile/header/ProfileActions.kt | 25 +------- 4 files changed, 91 insertions(+), 80 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt index cb91b312c..1f053cb2f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt @@ -25,16 +25,27 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.User +import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.observeAccountIsHiddenUser +import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserIsFollowing +import com.vitorpamplona.amethyst.ui.navigation.navs.EmptyNav.nav import com.vitorpamplona.amethyst.ui.navigation.navs.INav +import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.navigation.routes.routeFor import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.FollowButton +import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.ListButton +import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.UnfollowButton +import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ShowUserButton import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.StdPadding +import com.vitorpamplona.amethyst.ui.theme.StdStartPadding @Composable fun UserCompose( @@ -49,7 +60,7 @@ fun UserCompose( ) { UserPicture(baseUser, Size55dp, accountViewModel = accountViewModel, nav = nav) - Column(modifier = remember { Modifier.padding(start = 10.dp).weight(1f) }) { + Column(modifier = remember { StdStartPadding.weight(1f) }) { Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseUser, accountViewModel = accountViewModel) } @@ -57,8 +68,55 @@ fun UserCompose( AboutDisplay(baseUser, accountViewModel) } - Column(modifier = remember { Modifier.padding(start = 10.dp) }) { - UserActionOptions(baseUser, accountViewModel) + Row(modifier = StdStartPadding) { + UserActionOptions(baseUser, accountViewModel, nav) + } + } +} + +@Composable +fun UserActionOptions( + baseAuthor: User, + accountViewModel: AccountViewModel, + nav: INav, +) { + val isHidden by observeAccountIsHiddenUser(accountViewModel.account, baseAuthor) + if (isHidden) { + ShowUserButton { accountViewModel.show(baseAuthor) } + } else { + ShowFollowingOrUnfollowingButton(baseAuthor, accountViewModel) + ListButton { nav.nav(Route.PeopleListManagement(baseAuthor.pubkeyHex)) } + } +} + +@Composable +fun ShowFollowingOrUnfollowingButton( + baseAuthor: User, + accountViewModel: AccountViewModel, +) { + val isFollowing = observeUserIsFollowing(accountViewModel.account.userProfile(), baseAuthor, accountViewModel) + + if (isFollowing.value) { + UnfollowButton(true) { + if (!accountViewModel.isWriteable()) { + accountViewModel.toastManager.toast( + R.string.read_only_user, + R.string.login_with_a_private_key_to_be_able_to_unfollow, + ) + } else { + accountViewModel.unfollow(baseAuthor) + } + } + } else { + FollowButton(R.string.follow, true) { + if (!accountViewModel.isWriteable()) { + accountViewModel.toastManager.toast( + R.string.read_only_user, + R.string.login_with_a_private_key_to_be_able_to_follow, + ) + } else { + accountViewModel.follow(baseAuthor) + } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt index bacbcfd81..1258ca406 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt @@ -39,22 +39,17 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.User -import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.observeAccountIsHiddenUser import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNote import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserAboutMe -import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserIsFollowing import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.routeFor import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.FollowButton -import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.UnfollowButton -import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ShowUserButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ZapReqResponse import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange import com.vitorpamplona.amethyst.ui.theme.Size55dp +import com.vitorpamplona.amethyst.ui.theme.StdStartPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent import kotlinx.coroutines.Dispatchers @@ -112,21 +107,21 @@ private fun RenderZapNote( UserPicture(baseAuthor, Size55dp, accountViewModel = accountViewModel, nav = nav) Column( - modifier = remember { Modifier.padding(start = 10.dp).weight(1f) }, + modifier = remember { StdStartPadding.weight(1f) }, ) { Row(verticalAlignment = Alignment.CenterVertically) { UsernameDisplay(baseAuthor, accountViewModel = accountViewModel) } Row(verticalAlignment = Alignment.CenterVertically) { AboutDisplay(baseAuthor, accountViewModel) } } Column( - modifier = remember { Modifier.padding(start = 10.dp) }, + modifier = StdStartPadding, verticalArrangement = Arrangement.Center, ) { ZapAmount(zapNote, accountViewModel) } - Column(modifier = Modifier.padding(start = 10.dp)) { - UserActionOptions(baseAuthor, accountViewModel) + Row(modifier = StdStartPadding) { + UserActionOptions(baseAuthor, accountViewModel, nav) } } } @@ -159,51 +154,6 @@ private fun ZapAmount( } } -@Composable -fun UserActionOptions( - baseAuthor: User, - accountViewModel: AccountViewModel, -) { - val isHidden by observeAccountIsHiddenUser(accountViewModel.account, baseAuthor) - if (isHidden) { - ShowUserButton { accountViewModel.show(baseAuthor) } - } else { - ShowFollowingOrUnfollowingButton(baseAuthor, accountViewModel) - } -} - -@Composable -fun ShowFollowingOrUnfollowingButton( - baseAuthor: User, - accountViewModel: AccountViewModel, -) { - val isFollowing = observeUserIsFollowing(accountViewModel.account.userProfile(), baseAuthor, accountViewModel) - - if (isFollowing.value) { - UnfollowButton { - if (!accountViewModel.isWriteable()) { - accountViewModel.toastManager.toast( - R.string.read_only_user, - R.string.login_with_a_private_key_to_be_able_to_unfollow, - ) - } else { - accountViewModel.unfollow(baseAuthor) - } - } - } else { - FollowButton { - if (!accountViewModel.isWriteable()) { - accountViewModel.toastManager.toast( - R.string.read_only_user, - R.string.login_with_a_private_key_to_be_able_to_follow, - ) - } else { - accountViewModel.follow(baseAuthor) - } - } - } -} - @Composable fun AboutDisplay( baseAuthor: User, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/FollowButtons.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/FollowButtons.kt index 94c9f6070..741831da3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/FollowButtons.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/FollowButtons.kt @@ -21,8 +21,14 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.List +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.FilledTonalButton +import androidx.compose.material3.Icon import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign @@ -32,6 +38,7 @@ import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonPadding import com.vitorpamplona.amethyst.ui.theme.LeftHalfCircleButtonBorder +import com.vitorpamplona.amethyst.ui.theme.ZeroPadding @Composable fun FollowButton( @@ -64,3 +71,18 @@ fun UnfollowButton( Text(text = stringRes(R.string.unfollow)) } } + +@Composable +fun ListButton(onClick: () -> Unit) { + TextButton( + onClick = onClick, + shape = ButtonBorder.copy(topStart = CornerSize(0f), bottomStart = CornerSize(0f)), + colors = ButtonDefaults.filledTonalButtonColors(), + contentPadding = ZeroPadding, + ) { + Icon( + imageVector = Icons.AutoMirrored.Filled.List, + contentDescription = stringRes(R.string.follow_set_profile_actions_menu_description), + ) + } +} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt index c69b46dff..0d9c6b30e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt @@ -20,26 +20,17 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.header -import androidx.compose.foundation.shape.CornerSize -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.automirrored.filled.List -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.Icon -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember -import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.observeAccountIsHiddenUser import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.ListButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ShowUserButton -import com.vitorpamplona.amethyst.ui.stringRes -import com.vitorpamplona.amethyst.ui.theme.ButtonBorder -import com.vitorpamplona.amethyst.ui.theme.ZeroPadding @Composable fun ProfileActions( @@ -62,17 +53,7 @@ fun ProfileActions( ShowUserButton { accountViewModel.showUser(baseUser.pubkeyHex) } } else { DisplayFollowUnfollowButton(baseUser, accountViewModel) - - TextButton( - onClick = { nav.nav(Route.PeopleListManagement(baseUser.pubkeyHex)) }, - shape = ButtonBorder.copy(topStart = CornerSize(0f), bottomStart = CornerSize(0f)), - colors = ButtonDefaults.filledTonalButtonColors(), - contentPadding = ZeroPadding, - ) { - Icon( - imageVector = Icons.AutoMirrored.Filled.List, - contentDescription = stringRes(R.string.follow_set_profile_actions_menu_description), - ) - } + + ListButton { nav.nav(Route.PeopleListManagement(baseUser.pubkeyHex)) } } }