From c31b99b1dc4e971bb477b913090a9128c97a3571 Mon Sep 17 00:00:00 2001 From: toadlyBroodle Date: Mon, 13 Mar 2023 16:32:38 +0900 Subject: [PATCH] add consensus threshold component/preview, change value range placeholder strings --- .../amethyst/ui/actions/NewPollView.kt | 7 ++- .../ui/components/PollConsensusThreshold.kt | 54 +++++++++++++++++++ .../ui/components/PollVoteValueRange.kt | 4 +- app/src/main/res/values/strings.xml | 13 +++-- 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollConsensusThreshold.kt diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPollView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPollView.kt index 06727d56f..881666593 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPollView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPollView.kt @@ -26,10 +26,7 @@ import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.service.model.TextNoteEvent -import com.vitorpamplona.amethyst.ui.components.PollOption -import com.vitorpamplona.amethyst.ui.components.PollPrimaryDescription -import com.vitorpamplona.amethyst.ui.components.PollRecipientsField -import com.vitorpamplona.amethyst.ui.components.PollVoteValueRange +import com.vitorpamplona.amethyst.ui.components.* import com.vitorpamplona.amethyst.ui.note.ReplyInformation import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine import kotlinx.coroutines.delay @@ -113,6 +110,7 @@ fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n } } + Text(stringResource(R.string.poll_heading_required)) PollRecipientsField() PollPrimaryDescription(pollViewModel = pollViewModel) PollOption(0) @@ -132,6 +130,7 @@ fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n } Text(stringResource(R.string.poll_heading_optional)) PollVoteValueRange() + PollConsensusThreshold() } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollConsensusThreshold.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollConsensusThreshold.kt new file mode 100644 index 000000000..6debc95ff --- /dev/null +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollConsensusThreshold.kt @@ -0,0 +1,54 @@ +package com.vitorpamplona.amethyst.ui.components + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.MaterialTheme +import androidx.compose.material.OutlinedTextField +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.vitorpamplona.amethyst.R + +@Composable +fun PollConsensusThreshold() { + var text by rememberSaveable { mutableStateOf("") } + + Row( + horizontalArrangement = Arrangement.Center + ) { + OutlinedTextField( + value = text, + onValueChange = { text = it }, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), + modifier = Modifier.width(150.dp), + label = { + Text( + text = stringResource(R.string.poll_consensus_threshold), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + }, + placeholder = { + Text( + text = stringResource(R.string.poll_consensus_threshold_percent), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + } + ) + } +} + +@Preview +@Composable +fun PollConsensusThresholdPreview() { + PollConsensusThreshold() +} diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.kt index b4064d379..c4240b237 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.kt @@ -42,7 +42,7 @@ fun PollVoteValueRange() { }, placeholder = { Text( - text = stringResource(R.string.poll_vote_value_min), + text = stringResource(R.string.poll_vote_value_min_zap_amount), color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) ) } @@ -60,7 +60,7 @@ fun PollVoteValueRange() { }, placeholder = { Text( - text = stringResource(R.string.poll_vote_value_max), + text = stringResource(R.string.poll_vote_value_max_zap_amount), color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) ) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6639bf010..c4bda6c0a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -221,12 +221,17 @@ "<Unable to decrypt private message>\n\nYou were cited in a private/encrypted conversation between %1$s and %2$s." Post Poll - Primary poll description… - Poll option description - Option %s + Required fields: Zap recipients - Optional: + Primary poll description… + Option %s + Poll option description + Optional fields: Vote minimum Vote maximum + Consensus threshold + % + Minimum zap + Maximum zap