From 07e4c82c1b5eaba0c08d99a15bf6d11478ca595c Mon Sep 17 00:00:00 2001 From: maxmoney21m Date: Thu, 9 Mar 2023 01:24:43 +0800 Subject: [PATCH] Add (un)follow/delete to note quick actions --- .../amethyst/ui/note/NoteQuickActionMenu.kt | 30 ++++++++++++++++++- .../ui/screen/loggedIn/AccountViewModel.kt | 8 +++++ app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteQuickActionMenu.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteQuickActionMenu.kt index c3d449aa0..d570e1d76 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteQuickActionMenu.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteQuickActionMenu.kt @@ -21,7 +21,10 @@ import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AlternateEmail import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.FormatQuote +import androidx.compose.material.icons.filled.PersonAdd +import androidx.compose.material.icons.filled.PersonRemove import androidx.compose.material.icons.filled.Share import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -79,6 +82,8 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni val clipboardManager = LocalClipboardManager.current val scope = rememberCoroutineScope() var showSelectTextDialog by remember { mutableStateOf(false) } + val isOwnNote = note.author == accountViewModel.userProfile() + val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author!!) val showToast = { stringResource: Int -> scope.launch { @@ -124,8 +129,31 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni onDismiss() } } - Divider(color = primaryLight, modifier = Modifier.fillMaxWidth().width(1.dp)) + Divider( + color = primaryLight, + modifier = Modifier + .fillMaxWidth() + .width(1.dp) + ) Row(modifier = Modifier.height(IntrinsicSize.Min)) { + if (isOwnNote) { + NoteQuickActionItem(Icons.Default.Delete, stringResource(R.string.quick_action_delete)) { + accountViewModel.delete(note) + onDismiss() + } + } else if (isFollowingUser) { + NoteQuickActionItem(Icons.Default.PersonRemove, stringResource(R.string.quick_action_unfollow)) { + accountViewModel.unfollow(note.author!!) + onDismiss() + } + } else { + NoteQuickActionItem(Icons.Default.PersonAdd, stringResource(R.string.quick_action_follow)) { + accountViewModel.follow(note.author!!) + onDismiss() + } + } + + VerticalDivider(primaryLight) NoteQuickActionItem( icon = ImageVector.vectorResource(id = R.drawable.text_select_move_forward_character), label = stringResource(R.string.quick_action_select) 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 2b36d2fbb..9e9e5e78e 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 @@ -120,4 +120,12 @@ class AccountViewModel(private val account: Account) : ViewModel() { fun follow(user: User) { account.follow(user) } + + fun unfollow(user: User) { + account.unfollow(user) + } + + fun isFollowing(user: User): Boolean { + return account.userProfile().isFollowing(user) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dae1ded26..5335ee5f5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -202,4 +202,7 @@ Mention Quote Copy + Delete + Unfollow + Follow