added support for field types jid-single and text-private
This commit is contained in:
parent
6140861143
commit
39fdf4a333
|
@ -15,10 +15,15 @@ public class FormFieldFactory {
|
||||||
static {
|
static {
|
||||||
typeTable.put("text-single", FormTextFieldWrapper.class);
|
typeTable.put("text-single", FormTextFieldWrapper.class);
|
||||||
typeTable.put("text-multi", 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) {
|
public static FormFieldWrapper createFromField(Context context, Field field) {
|
||||||
Class clazz = typeTable.get(field.getType());
|
Class clazz = typeTable.get(field.getType());
|
||||||
|
if (clazz == null) {
|
||||||
|
clazz = FormTextFieldWrapper.class;
|
||||||
|
}
|
||||||
return FormFieldWrapper.createFromField(clazz, context, field);
|
return FormFieldWrapper.createFromField(clazz, context, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,11 @@ public abstract class FormFieldWrapper {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
this.view = inflater.inflate(getLayoutResource(), null);
|
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() {
|
public void submit() {
|
||||||
|
@ -34,6 +38,8 @@ public abstract class FormFieldWrapper {
|
||||||
|
|
||||||
abstract List<String> getValues();
|
abstract List<String> getValues();
|
||||||
|
|
||||||
|
abstract boolean validates();
|
||||||
|
|
||||||
abstract protected int getLayoutResource();
|
abstract protected int getLayoutResource();
|
||||||
|
|
||||||
protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) {
|
protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) {
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.ui.forms;
|
package eu.siacs.conversations.ui.forms;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.InputType;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
|
@ -20,7 +21,10 @@ public class FormTextFieldWrapper extends FormFieldWrapper {
|
||||||
protected FormTextFieldWrapper(Context context, Field field) {
|
protected FormTextFieldWrapper(Context context, Field field) {
|
||||||
super(context, field);
|
super(context, field);
|
||||||
editText = (EditText) view.findViewById(R.id.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
|
@Override
|
||||||
|
@ -36,15 +40,24 @@ public class FormTextFieldWrapper extends FormFieldWrapper {
|
||||||
textView.setText(spannableString);
|
textView.setText(spannableString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getValue() {
|
||||||
|
return editText.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
List<String> getValues() {
|
public List<String> getValues() {
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
for (String line : editText.getText().toString().split("\\n")) {
|
for (String line : getValue().split("\\n")) {
|
||||||
values.add(line);
|
values.add(line);
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validates() {
|
||||||
|
return getValue().trim().length() > 0 || !field.isRequired();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutResource() {
|
protected int getLayoutResource() {
|
||||||
return R.layout.form_text;
|
return R.layout.form_text;
|
||||||
|
|
Loading…
Reference in New Issue