From 851ec71f4a97d616054a08a5464dfdbccd78302f Mon Sep 17 00:00:00 2001 From: toadlyBroodle Date: Mon, 13 Mar 2023 15:46:48 +0900 Subject: [PATCH] add PollVoteValueRange component, add PollOption, PollVoteValueRange component previews, rename poll_recipients string --- .../amethyst/ui/actions/NewPollView.kt | 13 +++- .../amethyst/ui/components/PollOption.kt | 10 ++- .../ui/components/PollRecipientsField.kt | 4 +- .../ui/components/PollVoteValueRange.kt | 75 +++++++++++++++++++ app/src/main/res/values/strings.xml | 5 +- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.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 7f142094a..06727d56f 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 @@ -29,6 +29,7 @@ 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.note.ReplyInformation import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine import kotlinx.coroutines.delay @@ -114,8 +115,8 @@ fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n PollRecipientsField() PollPrimaryDescription(pollViewModel = pollViewModel) - PollOption(pollViewModel, 0) - PollOption(pollViewModel, 1) + PollOption(0) + PollOption(1) Button( onClick = { /*TODO*/ }, border = BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.32f)), @@ -129,6 +130,8 @@ fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n modifier = Modifier.size(18.dp) ) } + Text(stringResource(R.string.poll_heading_optional)) + PollVoteValueRange() } } @@ -182,3 +185,9 @@ fun PollButton(modifier: Modifier = Modifier, onPost: () -> Unit = {}, isActive: Text(text = stringResource(R.string.post_poll), color = Color.White) } } + +/*@Preview +@Composable +fun NewPollViewPreview() { + NewPollView(onClose = {}, account = Account(loggedIn = Persona())) +}*/ diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollOption.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollOption.kt index 888c23cdf..2a935379d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollOption.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollOption.kt @@ -15,12 +15,12 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.vitorpamplona.amethyst.R -import com.vitorpamplona.amethyst.ui.actions.NewPollViewModel @Composable -fun PollOption(pollViewModel: NewPollViewModel, optionIndex: Int) { +fun PollOption(optionIndex: Int) { var text by rememberSaveable() { mutableStateOf("") } Row() { @@ -59,3 +59,9 @@ fun PollOption(pollViewModel: NewPollViewModel, optionIndex: Int) { } } } + +@Preview +@Composable +fun PollOptionPreview() { + PollOption(0) +} diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollRecipientsField.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollRecipientsField.kt index 0eb3b00c0..ed135f09c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollRecipientsField.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollRecipientsField.kt @@ -20,13 +20,13 @@ fun PollRecipientsField() { onValueChange = { text = it }, label = { Text( - text = stringResource(R.string.poll_recipients), + text = stringResource(R.string.poll_zap_recipients), color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) ) }, placeholder = { Text( - text = stringResource(R.string.poll_recipients), + text = stringResource(R.string.poll_zap_recipients), color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) ) } 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 new file mode 100644 index 000000000..b4064d379 --- /dev/null +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollVoteValueRange.kt @@ -0,0 +1,75 @@ +package com.vitorpamplona.amethyst.ui.components + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +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 PollVoteValueRange() { + var minText by rememberSaveable { mutableStateOf("") } + var maxText by rememberSaveable { mutableStateOf("") } + + Row( + Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center + ) { + OutlinedTextField( + value = minText, + onValueChange = { minText = it }, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), + modifier = Modifier.width(150.dp), + label = { + Text( + text = stringResource(R.string.poll_vote_value_min), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + }, + placeholder = { + Text( + text = stringResource(R.string.poll_vote_value_min), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + } + ) + OutlinedTextField( + value = maxText, + onValueChange = { maxText = it }, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), + modifier = Modifier.width(150.dp), + label = { + Text( + text = stringResource(R.string.poll_vote_value_max), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + }, + placeholder = { + Text( + text = stringResource(R.string.poll_vote_value_max), + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + } + ) + } +} + +@Preview +@Composable +fun PollVoteValueRangePreview() { + PollVoteValueRange() +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17ed0b534..6639bf010 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -224,6 +224,9 @@ Primary poll description… Poll option description Option %s - Poll recipients + Zap recipients + Optional: + Vote minimum + Vote maximum