fix poll validation (#1459)

This commit is contained in:
Konrad Pozniak 2019-08-27 20:27:38 +02:00 committed by GitHub
parent b703097d17
commit 44163d8720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -30,7 +30,7 @@ import com.keylesspalace.tusky.util.visible
class AddPollOptionsAdapter(
private var options: MutableList<String>,
private val maxOptionLength: Int,
private val onOptionRemoved: () -> Unit,
private val onOptionRemoved: (Boolean) -> Unit,
private val onOptionChanged: (Boolean) -> Unit
): RecyclerView.Adapter<ViewHolder>() {
@ -70,7 +70,7 @@ class AddPollOptionsAdapter(
holder.editText.clearFocus()
options.removeAt(holder.adapterPosition)
notifyItemRemoved(holder.adapterPosition)
onOptionRemoved()
onOptionRemoved(validateInput())
}
}

View file

@ -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