diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java index 1a9b69aed..d9190ca03 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java @@ -57,6 +57,7 @@ public class JsonFormConstants { public static final String BEHAVIOUR = "behaviour"; public static final String RESULT = "result"; public static final String VALUE = "value"; + public static final String V_EQUALS = "v_equals"; public static final String KEYS = "keys"; public static final String SECOND_VALUE = "second_value"; public static final String OPENMRS_ENTITY_PARENT = "openmrs_entity_parent"; @@ -148,6 +149,7 @@ public class JsonFormConstants { public static final String EXPANDED = "expanded"; public static final String EXPAND_ON_TEXT_CHANGE = "expand_on_text_change"; public static final String NUMBER = "number"; + public static final String PASSWORD = "password"; public static final String TOP_MARGIN = "top_margin"; public static final String BOTTOM_MARGIN = "bottom_margin"; public static final String LEFT_MARGIN = "left_margin"; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/validators/edittext/ReferenceFieldValidator.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/validators/edittext/ReferenceFieldValidator.java new file mode 100644 index 000000000..b5db28f4b --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/validators/edittext/ReferenceFieldValidator.java @@ -0,0 +1,25 @@ +package com.vijay.jsonwizard.validators.edittext; + +import androidx.annotation.NonNull; + +import com.rengwuxian.materialedittext.MaterialEditText; +import com.rengwuxian.materialedittext.validation.METValidator; + +import org.jetbrains.annotations.NotNull; + +public class ReferenceFieldValidator extends METValidator { + MaterialEditText referenceField; + public ReferenceFieldValidator(@NonNull @NotNull String errorMessage,MaterialEditText referenceField) { + super(errorMessage); + this.referenceField = referenceField; + } + + @Override + public boolean isValid(@NonNull @NotNull CharSequence charSequence, boolean isEmpty) { + if(!isEmpty) { + String referenceText = referenceField.getText().toString(); + return referenceText.equals(charSequence.toString()); + } + return true; + } +} diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java index 6a05a3bbb..45ff0b47b 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java @@ -1,24 +1,12 @@ package com.vijay.jsonwizard.widgets; -import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_CUMULATIVE_VALIDATION_ERR; -import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MAX_VALIDATION_ERR; -import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MIN_VALIDATION_ERR; -import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; -import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATED_FIELDS; -import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATIVE_VALIDATION_EXCEPTION; -import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP1; -import static com.vijay.jsonwizard.constants.JsonFormConstants.V_CUMULATIVE_TOTAL; -import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; -import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MIN; -import static com.vijay.jsonwizard.utils.FormUtils.fields; -import static com.vijay.jsonwizard.utils.FormUtils.getFieldJSONObject; - import android.content.Context; import android.text.Editable; import android.text.InputFilter; import android.text.InputType; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.method.PasswordTransformationMethod; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; @@ -43,6 +31,7 @@ import com.vijay.jsonwizard.validators.edittext.MaxNumericValidator; import com.vijay.jsonwizard.validators.edittext.MinLengthValidator; import com.vijay.jsonwizard.validators.edittext.MinNumericValidator; +import com.vijay.jsonwizard.validators.edittext.ReferenceFieldValidator; import com.vijay.jsonwizard.validators.edittext.ReferenceValidator; import com.vijay.jsonwizard.validators.edittext.RelativeNumericValidator; import com.vijay.jsonwizard.validators.edittext.RequiredValidator; @@ -60,6 +49,19 @@ import timber.log.Timber; +import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_CUMULATIVE_VALIDATION_ERR; +import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MAX_VALIDATION_ERR; +import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MIN_VALIDATION_ERR; +import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; +import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATED_FIELDS; +import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATIVE_VALIDATION_EXCEPTION; +import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP1; +import static com.vijay.jsonwizard.constants.JsonFormConstants.V_CUMULATIVE_TOTAL; +import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; +import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MIN; +import static com.vijay.jsonwizard.utils.FormUtils.fields; +import static com.vijay.jsonwizard.utils.FormUtils.getFieldJSONObject; + public class EditTextFactory implements FormWidgetFactory { public static final int MIN_LENGTH = 0; @@ -117,7 +119,6 @@ protected List attachJson(String stepName, Context context, JsonFormFragme RelativeLayout editTextLayout = rootLayout.findViewById(R.id.edit_text_layout); MaterialEditText editText = editTextLayout.findViewById(R.id.edit_text); ImageView editButton = editTextLayout.findViewById(R.id.material_edit_text_edit_button); - FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener); attachLayout(stepName, context, formFragment, jsonObject, editText, editButton); @@ -179,6 +180,7 @@ public void run() { FormUtils.toggleEditTextVisibility(jsonObject, editText); addRequiredValidator(jsonObject, editText); + addEqualsValidator(formFragment,jsonObject,editText); addLengthValidator(jsonObject, editText); addRegexValidator(jsonObject, editText); addEmailValidator(jsonObject, editText); @@ -190,15 +192,19 @@ public void run() { addCumulativeTotalValidator(jsonObject, formFragment, editText, stepName, (JsonApi) context); // edit type check String editType = jsonObject.optString(JsonFormConstants.EDIT_TYPE); + editText.setSingleLine(false); if (!TextUtils.isEmpty(editType)) { if (JsonFormConstants.NUMBER.equals(editType)) { editText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); } else if (JsonFormConstants.NAME.equals(editType)) { editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); } - } + else if (JsonFormConstants.PASSWORD.equals(editType)) + { + editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); + } - editText.setSingleLine(false); + } editText.addTextChangedListener(new GenericTextWatcher(stepName, formFragment, editText)); attachRefreshLogic(context, jsonObject, editText); } @@ -212,6 +218,15 @@ private void attachInfoIcon(String stepName, JSONObject jsonObject, RelativeLayo } + private void addEqualsValidator(JsonFormFragment formFragment,JSONObject jsonObject, MaterialEditText editText) throws JSONException { + JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_EQUALS); + if (requiredObject != null) { + String referencedValue = requiredObject.optString(JsonFormConstants.VALUE,""); + MaterialEditText referencedEditText = (MaterialEditText) formFragment.getJsonApi().getFormDataView(referencedValue); + editText.addValidator(new ReferenceFieldValidator(requiredObject.getString(JsonFormConstants.ERR),referencedEditText)); + FormUtils.setRequiredOnHint(editText); + } + } private void addRequiredValidator(JSONObject jsonObject, MaterialEditText editText) throws JSONException { JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED); if (requiredObject != null) { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java index 169f5431e..2c0f2fd2a 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java @@ -4,6 +4,7 @@ import android.os.Build; import android.text.InputType; import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; @@ -144,6 +145,10 @@ protected void makeFromJson(String stepName, Context context, JsonFormFragment f } else if ("name".equals(editType)) { editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); } + else if ("password".equals(editType)) + { + editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); + } } editText.addTextChangedListener(new GenericTextWatcher(stepName, formFragment, editText)); diff --git a/gradle.properties b/gradle.properties index 5abb92c86..2c363ec8b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.1.1-SNAPSHOT +VERSION_NAME=3.1.3-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard