diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-01-23 12:44:08 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-01-23 12:44:08 +0100 |
commit | 39fdf4a333378affcca360886701851d84dd9e0b (patch) | |
tree | c2071acd108caee7a0a497f846dee3e9332e1821 /src/main/java/eu/siacs/conversations/ui/forms | |
parent | 61408611437785ebe685aadfbca924cbc86340c1 (diff) |
added support for field types jid-single and text-private
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/forms')
4 files changed, 59 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java index 9e54678a..2e7c17dc 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java @@ -15,10 +15,15 @@ public class FormFieldFactory { static { typeTable.put("text-single", FormTextFieldWrapper.class); typeTable.put("text-multi", FormTextFieldWrapper.class); + typeTable.put("text-private", FormTextFieldWrapper.class); + typeTable.put("jid-single", FormJidSingleFieldWrapper.class); } public static FormFieldWrapper createFromField(Context context, Field field) { Class clazz = typeTable.get(field.getType()); + if (clazz == null) { + clazz = FormTextFieldWrapper.class; + } return FormFieldWrapper.createFromField(clazz, context, field); } } 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 3af37536..a0ed371a 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -19,7 +19,11 @@ public abstract class FormFieldWrapper { this.field = field; LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.view = inflater.inflate(getLayoutResource(), null); - setLabel(field.getLabel(), field.isRequired()); + String label = field.getLabel(); + if (label == null) { + label = field.getFieldName(); + } + setLabel(label, field.isRequired()); } public void submit() { @@ -34,6 +38,8 @@ public abstract class FormFieldWrapper { abstract List<String> getValues(); + abstract boolean validates(); + abstract protected int getLayoutResource(); protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) { diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java new file mode 100644 index 00000000..b54940f6 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java @@ -0,0 +1,31 @@ +package eu.siacs.conversations.ui.forms; + +import android.content.Context; +import android.text.InputType; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.xmpp.forms.Field; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + +public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { + + protected FormJidSingleFieldWrapper(Context context, Field field) { + super(context, field); + editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + editText.setHint(R.string.account_settings_example_jabber_id); + } + + @Override + public boolean validates() { + String value = getValue(); + if (!value.isEmpty()) { + try { + Jid.fromString(value); + } catch (InvalidJidException e) { + return false; + } + } + return super.validates(); + } +} 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 8f70dd37..71ed6e4a 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; +import android.text.InputType; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; @@ -20,7 +21,10 @@ public class FormTextFieldWrapper extends FormFieldWrapper { protected FormTextFieldWrapper(Context context, Field field) { super(context, field); editText = (EditText) view.findViewById(R.id.field); - editText.setSingleLine("text-single".equals(field.getType())); + editText.setSingleLine(!"text-multi".equals(field.getType())); + if ("text-private".equals(field.getType())) { + editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + } } @Override @@ -36,16 +40,25 @@ public class FormTextFieldWrapper extends FormFieldWrapper { textView.setText(spannableString); } + protected String getValue() { + return editText.getText().toString(); + } + @Override - List<String> getValues() { + public List<String> getValues() { List<String> values = new ArrayList<>(); - for (String line : editText.getText().toString().split("\\n")) { + for (String line : getValue().split("\\n")) { values.add(line); } return values; } @Override + public boolean validates() { + return getValue().trim().length() > 0 || !field.isRequired(); + } + + @Override protected int getLayoutResource() { return R.layout.form_text; } |