From 03b76357ff423d69a39a48c0260c3e4fcd73cf38 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 7 Apr 2023 17:20:18 -0400 Subject: [PATCH] Migrates poll and invoice option availability to a mutable state --- .../amethyst/ui/actions/NewPostView.kt | 4 ++-- .../amethyst/ui/actions/NewPostViewModel.kt | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt index d65c5980d..82175a913 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt @@ -270,13 +270,13 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n postViewModel.upload(it, context) } - if (postViewModel.canUsePoll()) { + if (postViewModel.canUsePoll) { AddPollButton(postViewModel.wantsPoll) { postViewModel.wantsPoll = !postViewModel.wantsPoll } } - if (postViewModel.canAddLnInvoice()) { + if (postViewModel.canAddInvoice) { AddLnInvoiceButton(postViewModel.wantsInvoice) { postViewModel.wantsInvoice = !postViewModel.wantsInvoice } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt index 5c0a13b16..5765faf05 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt @@ -38,6 +38,7 @@ open class NewPostViewModel : ViewModel() { var userSuggestionAnchor: TextRange? = null // Polls + var canUsePoll by mutableStateOf(false) var wantsPoll by mutableStateOf(false) var zapRecipients = mutableStateListOf() var pollOptions = newStateMapPollOptions() @@ -53,6 +54,7 @@ open class NewPostViewModel : ViewModel() { var isValidClosedAt = mutableStateOf(true) // Invoices + var canAddInvoice by mutableStateOf(false) var wantsInvoice by mutableStateOf(false) open fun load(account: Account, replyingTo: Note?, quote: Note?) { @@ -79,6 +81,9 @@ open class NewPostViewModel : ViewModel() { message = TextFieldValue(message.text + "\n\n@${it.idNote()}") } + canAddInvoice = account.userProfile().info?.lnAddress() != null + canUsePoll = originalNote?.event !is PrivateDmEvent && originalNote?.channel() == null + this.account = account } @@ -190,12 +195,4 @@ open class NewPostViewModel : ViewModel() { return message.text.isNotBlank() && !isUploadingImage && !wantsInvoice && (!wantsPoll || pollOptions.values.all { it.isNotEmpty() }) } - - fun canUsePoll(): Boolean { - return originalNote?.event !is PrivateDmEvent && originalNote?.channel() == null - } - - fun canAddLnInvoice(): Boolean { - return account?.userProfile()?.info?.lnAddress() != null - } }