diff options
Diffstat (limited to 'src/main')
6 files changed, 58 insertions, 7 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 eba0f12d..6cb357a9 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java @@ -40,6 +40,15 @@ 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() { if (checkBox.isChecked() || !field.isRequired()) { return true; @@ -63,4 +72,9 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { protected int getLayoutResource() { return R.layout.form_boolean; } + + @Override + void setReadOnly(boolean readOnly) { + checkBox.setEnabled(!readOnly); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index 8ba62bdd..3a21ade3 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -45,10 +45,14 @@ public abstract class FormFieldWrapper { abstract List<String> getValues(); + protected abstract void setValues(List<String> values); + abstract boolean validates(); abstract protected int getLayoutResource(); + abstract void setReadOnly(boolean readOnly); + protected SpannableString createSpannableLabelString(String label, boolean required) { SpannableString spannableString = new SpannableString(label + (required ? " *" : "")); if (required) { @@ -61,11 +65,8 @@ public abstract class FormFieldWrapper { } protected void invokeOnFormFieldValuesEdited() { - Log.d(Config.LOGTAG, "invoke on form field values edited"); if (this.onFormFieldValuesEditedListener != null) { this.onFormFieldValuesEditedListener.onFormFieldValuesEdited(); - } else { - Log.d(Config.LOGTAG,"listener is null"); } } @@ -79,7 +80,9 @@ public abstract class FormFieldWrapper { protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) { try { - return c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); + F fieldWrapper = c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); + fieldWrapper.setValues(field.getValues()); + return fieldWrapper; } catch (Exception e) { e.printStackTrace(); return null; diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java index 3890a1a7..553e8f21 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java @@ -3,6 +3,8 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; import android.text.InputType; +import java.util.List; + import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -30,4 +32,13 @@ public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { } return super.validates(); } + + @Override + protected void setValues(List<String> values) { + StringBuilder builder = new StringBuilder(""); + for(String value : values) { + builder.append(value); + } + editText.setText(builder.toString()); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java index 47b8d86c..b7dac951 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -63,6 +63,18 @@ public class FormTextFieldWrapper extends FormFieldWrapper { } @Override + protected void setValues(List<String> values) { + StringBuilder builder = new StringBuilder(""); + for(int i = 0; i < values.size(); ++i) { + builder.append(values.get(i)); + if (i < values.size() - 1 && "text-multi".equals(field.getType())) { + builder.append("\n"); + } + } + editText.setText(builder.toString()); + } + + @Override public boolean validates() { if (getValue().trim().length() > 0 || !field.isRequired()) { return true; @@ -77,4 +89,9 @@ public class FormTextFieldWrapper extends FormFieldWrapper { protected int getLayoutResource() { return R.layout.form_text; } + + @Override + void setReadOnly(boolean readOnly) { + editText.setEnabled(!readOnly); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java index 51d15f0c..eafe95cc 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java @@ -52,6 +52,12 @@ public class FormWrapper { } } + public void setReadOnly(boolean b) { + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + fieldWrapper.setReadOnly(b); + } + } + public boolean edited() { boolean edited = false; for(FormFieldWrapper fieldWrapper : fieldWrappers) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java index d05c9abb..0053a399 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java +++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java @@ -53,16 +53,16 @@ public class Data extends Element { public void submit() { this.setAttribute("type","submit"); - removeNonFieldChildren(); + removeUnnecessaryChildren(); for(Field field : getFields()) { field.removeNonValueChildren(); } } - private void removeNonFieldChildren() { + private void removeUnnecessaryChildren() { for(Iterator<Element> iterator = this.children.iterator(); iterator.hasNext();) { Element element = iterator.next(); - if (!element.getName().equals("field")) { + if (!element.getName().equals("field") && !element.getName().equals("title")) { iterator.remove(); } } |