diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt index ad69a8bec..804e91422 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt @@ -630,17 +630,21 @@ private fun BottomRowActions(postViewModel: NewPostViewModel) { @Composable private fun PollField(postViewModel: NewPostViewModel) { + val optionsList = postViewModel.pollOptions Column( modifier = Modifier.fillMaxWidth(), ) { - postViewModel.pollOptions.values.forEachIndexed { index, _ -> - NewPollOption(postViewModel, index) + optionsList.forEach { value -> + NewPollOption(postViewModel, value.key) } NewPollVoteValueRange(postViewModel) Button( - onClick = { postViewModel.pollOptions[postViewModel.pollOptions.size] = "" }, + onClick = { + // postViewModel.pollOptions[postViewModel.pollOptions.size] = "" + optionsList[optionsList.size] = "" + }, border = BorderStroke( 1.dp, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt index 55dc95a68..eedf5298e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt @@ -1278,10 +1278,26 @@ open class NewPostViewModel : ViewModel() { } fun removePollOption(optionIndex: Int) { - pollOptions.remove(optionIndex) + pollOptions.removeOrdered(optionIndex) saveDraft() } + private fun MutableMap.removeOrdered(index: Int) { + val keyList = keys + val elementList = values.toMutableList() + run stop@{ + for (i in index until elementList.size) { + val nextIndex = i + 1 + if (nextIndex == elementList.size) return@stop + elementList[i] = elementList[nextIndex].also { elementList[nextIndex] = "null" } + } + } + elementList.removeLast() + val newEntries = keyList.zip(elementList) { key, content -> Pair(key, content) } + this.clear() + this.putAll(newEntries) + } + fun updatePollOption( optionIndex: Int, text: String,