aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java
blob: 274936e86b68c031feebefd464a41d4b2905ed15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package eu.siacs.conversations.ui.forms;

import android.content.Context;
import android.text.InputType;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import eu.siacs.conversations.R;
import eu.siacs.conversations.xmpp.forms.Field;

public class FormTextFieldWrapper extends FormFieldWrapper {

	protected EditText editText;

	protected FormTextFieldWrapper(Context context, Field field) {
		super(context, field);
		editText = (EditText) view.findViewById(R.id.field);
		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
	protected void setLabel(String label, boolean required) {
		TextView textView = (TextView) view.findViewById(R.id.label);
		textView.setText(createSpannableLabelString(label, required));
	}

	protected String getValue() {
		return editText.getText().toString();
	}

	@Override
	public List<String> getValues() {
		List<String> values = new ArrayList<>();
		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;
	}
}