aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java
blob: e9adf15a354db7299a007477ab7b83f0917d39b3 (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
package eu.siacs.conversations.ui.forms;

import android.content.Context;
import android.widget.CheckBox;

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

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

public class FormBooleanFieldWrapper extends FormFieldWrapper {

	protected CheckBox checkBox;

	protected FormBooleanFieldWrapper(Context context, Field field) {
		super(context, field);
		checkBox = (CheckBox) view.findViewById(R.id.field);
	}

	@Override
	protected void setLabel(String label, boolean required) {
		CheckBox checkBox = (CheckBox) view.findViewById(R.id.field);
		checkBox.setText(createSpannableLabelString(label, required));
	}

	@Override
	public List<String> getValues() {
		List<String> values = new ArrayList<>();
		values.add(Boolean.toString(checkBox.isChecked()));
		return values;
	}

	@Override
	public boolean validates() {
		return checkBox.isChecked() || !field.isRequired();
	}

	@Override
	protected int getLayoutResource() {
		return R.layout.form_boolean;
	}
}