diff --git a/stream-chat-android-compose/api/stream-chat-android-compose.api b/stream-chat-android-compose/api/stream-chat-android-compose.api index b18ea6e23e9..a57bc90308c 100644 --- a/stream-chat-android-compose/api/stream-chat-android-compose.api +++ b/stream-chat-android-compose/api/stream-chat-android-compose.api @@ -1254,14 +1254,12 @@ public final class io/getstream/chat/android/compose/ui/components/poll/Composab public static field lambda-1 Lkotlin/jvm/functions/Function3; public static field lambda-2 Lkotlin/jvm/functions/Function3; public static field lambda-3 Lkotlin/jvm/functions/Function3; - public static field lambda-4 Lkotlin/jvm/functions/Function2; - public static field lambda-5 Lkotlin/jvm/functions/Function3; + public static field lambda-4 Lkotlin/jvm/functions/Function3; public fun ()V public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3; public final fun getLambda-2$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3; public final fun getLambda-3$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3; - public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2; - public final fun getLambda-5$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3; + public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3; } public final class io/getstream/chat/android/compose/ui/components/poll/ComposableSingletons$PollDialogHeaderKt { diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.kt index b8c6ecc4552..261ece6b61c 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/PollMessageContent.kt @@ -199,6 +199,7 @@ private fun PollMessageContent( if (showAddAnswerDialog.value) { AddAnswerDialog( + initMessage = "", onDismiss = { showAddAnswerDialog.value = false }, onNewAnswer = { newAnswer -> onAddAnswer.invoke(newAnswer) }, ) diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollAnswers.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollAnswers.kt index 5e08348c569..8ee0fcfa62d 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollAnswers.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollAnswers.kt @@ -43,6 +43,8 @@ import androidx.compose.material.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -73,6 +75,8 @@ public fun PollAnswersDialog( onDismissRequest: () -> Unit, onBackPressed: () -> Unit, ) { + val user by listViewModel.user.collectAsState() + val currentUserAnswer = selectedPoll.poll.answers.firstOrNull { it.user?.id == user?.id } val state = remember { MutableTransitionState(false).apply { // Start the animation immediately. @@ -82,6 +86,7 @@ public fun PollAnswersDialog( val showAddAnswerDialog = remember { mutableStateOf(false) } if (showAddAnswerDialog.value) { AddAnswerDialog( + initMessage = currentUserAnswer?.text ?: "", onDismiss = { showAddAnswerDialog.value = false }, onNewAnswer = { newAnswer -> listViewModel.castAnswer(selectedPoll.message, selectedPoll.poll, newAnswer) @@ -127,6 +132,7 @@ public fun PollAnswersDialog( answer = answer, showAvatar = (poll.votingVisibility == VotingVisibility.PUBLIC) || showAnonymousAvatar, ) + Spacer(modifier = Modifier.height(8.dp)) } item { Spacer(modifier = Modifier.height(16.dp)) } @@ -153,7 +159,12 @@ public fun PollAnswersDialog( modifier = Modifier .fillMaxWidth() .padding(vertical = 11.dp), - text = stringResource(id = R.string.stream_compose_add_answer), + text = stringResource( + id = when (currentUserAnswer == null) { + true -> R.string.stream_compose_add_answer + false -> R.string.stream_compose_edit_answer + }, + ), textAlign = TextAlign.Center, color = ChatTheme.colors.primaryAccent, fontSize = 16.sp, @@ -231,13 +242,23 @@ internal fun PollAnswersItem( @Composable internal fun AddAnswerDialog( + initMessage: String, onDismiss: () -> Unit, onNewAnswer: (newOption: String) -> Unit, ) { - val newOption = remember { mutableStateOf("") } + val newOption = remember { mutableStateOf(initMessage) } val focusRequester = remember { FocusRequester() } AlertDialog( - title = { Text(text = stringResource(R.string.stream_compose_add_answer)) }, + title = { + Text( + text = stringResource( + when (initMessage.isBlank()) { + true -> R.string.stream_compose_add_answer + false -> R.string.stream_compose_edit_answer + }, + ), + ) + }, text = { InputField( value = newOption.value, diff --git a/stream-chat-android-compose/src/main/res/values/strings.xml b/stream-chat-android-compose/src/main/res/values/strings.xml index b92e945cb7b..b6f5b3640d4 100644 --- a/stream-chat-android-compose/src/main/res/values/strings.xml +++ b/stream-chat-android-compose/src/main/res/values/strings.xml @@ -218,6 +218,7 @@ Poll Results Poll Comments Add a Comment + Update Comment %d votes 📊 Poll created: %s 📊 Poll closed: %s