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 9b3f18bec..1db3668ea 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
@@ -1,30 +1,20 @@
package com.vitorpamplona.amethyst.ui.actions
import android.widget.Toast
-import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
-import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
-import androidx.compose.ui.focus.FocusRequester
-import androidx.compose.ui.focus.focusRequester
-import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
-import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.text.input.KeyboardCapitalization
-import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
@@ -33,28 +23,23 @@ 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.*
+import com.vitorpamplona.amethyst.ui.components.PollOption
+import com.vitorpamplona.amethyst.ui.components.PollPrimaryDescription
import com.vitorpamplona.amethyst.ui.note.ReplyInformation
import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine
import kotlinx.coroutines.delay
-@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = null, account: Account) {
val pollViewModel: NewPollViewModel = viewModel()
val context = LocalContext.current
- // initialize focus reference to be able to request focus programmatically
- val focusRequester = remember { FocusRequester() }
- val keyboardController = LocalSoftwareKeyboardController.current
-
val scrollState = rememberScrollState()
LaunchedEffect(Unit) {
pollViewModel.load(account, baseReplyTo, quote)
delay(100)
- focusRequester.requestFocus()
pollViewModel.imageUploadingError.collect { error ->
Toast.makeText(context, error, Toast.LENGTH_SHORT).show()
@@ -121,41 +106,10 @@ fun NewPollView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
}
}
- OutlinedTextField(
- value = pollViewModel.message,
- onValueChange = {
- pollViewModel.updateMessage(it)
- },
- keyboardOptions = KeyboardOptions.Default.copy(
- capitalization = KeyboardCapitalization.Sentences
- ),
- modifier = Modifier
- .fillMaxWidth()
- .border(
- width = 1.dp,
- color = MaterialTheme.colors.surface,
- shape = RoundedCornerShape(8.dp)
- )
- .focusRequester(focusRequester)
- .onFocusChanged {
- if (it.isFocused) {
- keyboardController?.show()
- }
- },
- placeholder = {
- Text(
- text = stringResource(R.string.primary_poll_description),
- color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
- )
- },
- colors = TextFieldDefaults
- .outlinedTextFieldColors(
- unfocusedBorderColor = Color.Transparent,
- focusedBorderColor = Color.Transparent
- ),
- visualTransformation = UrlUserTagTransformation(MaterialTheme.colors.primary),
- textStyle = LocalTextStyle.current.copy(textDirection = TextDirection.Content)
- )
+ PollPrimaryDescription(pollViewModel = pollViewModel)
+
+ PollOption(pollViewModel, 0)
+ PollOption(pollViewModel, 1)
}
}
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
new file mode 100644
index 000000000..ca335ecbb
--- /dev/null
+++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollOption.kt
@@ -0,0 +1,36 @@
+package com.vitorpamplona.amethyst.ui.components
+
+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.res.stringResource
+import com.vitorpamplona.amethyst.R
+import com.vitorpamplona.amethyst.ui.actions.NewPollViewModel
+
+@Composable
+fun PollOption(pollViewModel: NewPollViewModel, optionIndex: Int) {
+ var text by rememberSaveable() { mutableStateOf("") }
+
+ OutlinedTextField(
+ value = text,
+ onValueChange = { text = it },
+ label = {
+ Text(
+ text = stringResource(R.string.poll_option_index).format(optionIndex),
+ color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
+ )
+ },
+ placeholder = {
+ Text(
+ text = stringResource(R.string.what_s_on_your_mind),
+ color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
+ )
+ }
+
+ )
+}
diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollPrimaryDescription.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollPrimaryDescription.kt
new file mode 100644
index 000000000..8870b42ec
--- /dev/null
+++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/PollPrimaryDescription.kt
@@ -0,0 +1,67 @@
+package com.vitorpamplona.amethyst.ui.components
+
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material.*
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.ExperimentalComposeUiApi
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalSoftwareKeyboardController
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.input.KeyboardCapitalization
+import androidx.compose.ui.text.style.TextDirection
+import androidx.compose.ui.unit.dp
+import com.vitorpamplona.amethyst.R
+import com.vitorpamplona.amethyst.ui.actions.NewPollViewModel
+import com.vitorpamplona.amethyst.ui.actions.UrlUserTagTransformation
+
+@OptIn(ExperimentalComposeUiApi::class)
+@Composable
+fun PollPrimaryDescription(pollViewModel: NewPollViewModel) {
+ // initialize focus reference to be able to request focus programmatically
+ val focusRequester = remember { FocusRequester() }
+ val keyboardController = LocalSoftwareKeyboardController.current
+
+ OutlinedTextField(
+ value = pollViewModel.message,
+ onValueChange = {
+ pollViewModel.updateMessage(it)
+ },
+ keyboardOptions = KeyboardOptions.Default.copy(
+ capitalization = KeyboardCapitalization.Sentences
+ ),
+ modifier = Modifier
+ .fillMaxWidth()
+ .border(
+ width = 1.dp,
+ color = MaterialTheme.colors.surface,
+ shape = RoundedCornerShape(8.dp)
+ )
+ .focusRequester(focusRequester)
+ .onFocusChanged {
+ if (it.isFocused) {
+ keyboardController?.show()
+ }
+ },
+ placeholder = {
+ Text(
+ text = stringResource(R.string.primary_poll_description),
+ color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
+ )
+ },
+ colors = TextFieldDefaults
+ .outlinedTextFieldColors(
+ unfocusedBorderColor = Color.Transparent,
+ focusedBorderColor = Color.Transparent
+ ),
+ visualTransformation = UrlUserTagTransformation(MaterialTheme.colors.primary),
+ textStyle = LocalTextStyle.current.copy(textDirection = TextDirection.Content)
+ )
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5a4a6a4e8..db4332bdc 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -222,5 +222,7 @@
"<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