diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java index e9adf15a..6cb357a9 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; import android.widget.CheckBox; +import android.widget.CompoundButton; import java.util.ArrayList; import java.util.List; @@ -16,6 +17,13 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { protected FormBooleanFieldWrapper(Context context, Field field) { super(context, field); checkBox = (CheckBox) view.findViewById(R.id.field); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + checkBox.setError(null); + invokeOnFormFieldValuesEdited(); + } + }); } @Override @@ -32,12 +40,41 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { } @Override + protected void setValues(List<String> values) { + if (values.size() == 0) { + checkBox.setChecked(false); + } else { + checkBox.setChecked(Boolean.parseBoolean(values.get(0))); + } + } + + @Override public boolean validates() { - return checkBox.isChecked() || !field.isRequired(); + if (checkBox.isChecked() || !field.isRequired()) { + return true; + } else { + checkBox.setError(context.getString(R.string.this_field_is_required)); + checkBox.requestFocus(); + return false; + } + } + + @Override + public boolean edited() { + if (field.getValues().size() == 0) { + return checkBox.isChecked(); + } else { + return super.edited(); + } } @Override protected int getLayoutResource() { return R.layout.form_boolean; } + + @Override + void setReadOnly(boolean readOnly) { + checkBox.setEnabled(!readOnly); + } } |