From 44163d872011ca4fd2136d64d51c206ce6cb8f02 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Tue, 27 Aug 2019 20:27:38 +0200 Subject: [PATCH] fix poll validation (#1459) --- .../com/keylesspalace/tusky/adapter/AddPollOptionsAdapter.kt | 4 ++-- .../main/java/com/keylesspalace/tusky/view/AddPollDialog.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AddPollOptionsAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/AddPollOptionsAdapter.kt index 17828874..60241992 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AddPollOptionsAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AddPollOptionsAdapter.kt @@ -30,7 +30,7 @@ import com.keylesspalace.tusky.util.visible class AddPollOptionsAdapter( private var options: MutableList, private val maxOptionLength: Int, - private val onOptionRemoved: () -> Unit, + private val onOptionRemoved: (Boolean) -> Unit, private val onOptionChanged: (Boolean) -> Unit ): RecyclerView.Adapter() { @@ -70,7 +70,7 @@ class AddPollOptionsAdapter( holder.editText.clearFocus() options.removeAt(holder.adapterPosition) notifyItemRemoved(holder.adapterPosition) - onOptionRemoved() + onOptionRemoved(validateInput()) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/view/AddPollDialog.kt b/app/src/main/java/com/keylesspalace/tusky/view/AddPollDialog.kt index f6116f9e..3ed211b2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/AddPollDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/AddPollDialog.kt @@ -48,8 +48,9 @@ fun showAddPollDialog( val adapter = AddPollOptionsAdapter( options = poll?.options?.toMutableList() ?: mutableListOf("", ""), maxOptionLength = maxOptionLength ?: DEFAULT_MAX_OPTION_LENGTH, - onOptionRemoved = { + onOptionRemoved = { valid -> view.addChoiceButton.isEnabled = true + dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = valid }, onOptionChanged = { valid -> dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = valid