Skip to content

Commit

Permalink
Merge 5385710 into b61f254
Browse files Browse the repository at this point in the history
  • Loading branch information
dubdabasoduba committed Mar 24, 2020
2 parents b61f254 + 5385710 commit ae4fa5c
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: step2_date_larvae_collection
description: date_larvae_collection
priority: 1
condition: "step2_larvae_total != ''"
actions:
- "calculation = helper.getDateToday()"
Original file line number Diff line number Diff line change
Expand Up @@ -1735,37 +1735,47 @@ private void updateCalculation(Facts valueMap, View view, String[] address) {

}

private void setRadioButtonCalculation(RadioGroup view, String calculation) {
private void setRadioButtonCalculation(final RadioGroup view, final String calculation) {
int count = view.getChildCount();
for (int i = 0; i < count; i++) {
if (!TextUtils.isEmpty(calculation)) {
RelativeLayout radioButtonLayout = (RelativeLayout) view.getChildAt(i);
int radioButtonViewId = (int) radioButtonLayout.getTag(R.id.native_radio_button_view_id);
RadioButton radioButton = radioButtonLayout.findViewById(radioButtonViewId);
boolean showExtraInfo = (boolean) radioButton.getTag(R.id.native_radio_button_extra_info);
String radioButtonKey = (String) radioButton.getTag(R.id.childKey);

if (!TextUtils.isEmpty(radioButtonKey) && calculation.equals(radioButtonKey)) {
radioButton.setChecked(true);
radioButton.performClick();
final int childPosition = i;
runOnUiThread(new Runnable() {
@Override
public void run() {
addRadioButtonCalculation(calculation, view, childPosition);
}
});
}
}

if (showExtraInfo) {
CustomTextView renderView = view.getChildAt(i).findViewById(R.id.extraInfoTextView);
private void addRadioButtonCalculation(String calculation, RadioGroup view, int childPosition) {
if (!TextUtils.isEmpty(calculation)) {
RelativeLayout radioButtonLayout = (RelativeLayout) view.getChildAt(childPosition);
int radioButtonViewId = (int) radioButtonLayout.getTag(R.id.native_radio_button_view_id);
RadioButton radioButton = radioButtonLayout.findViewById(radioButtonViewId);
boolean showExtraInfo = (boolean) radioButton.getTag(R.id.native_radio_button_extra_info);
String radioButtonKey = (String) radioButton.getTag(R.id.childKey);

if (renderView.getTag(R.id.original_text) == null) {
renderView.setTag(R.id.original_text, renderView.getText());
}
if (!TextUtils.isEmpty(calculation)) {
renderView.setText(calculation.charAt(0) == '{' ? getRenderText(calculation, renderView.getTag(R.id.original_text).toString(), false) : calculation);
}
if (!TextUtils.isEmpty(radioButtonKey) && calculation.equals(radioButtonKey)) {
radioButton.setChecked(true);
radioButton.performClick();
}

if (showExtraInfo) {
CustomTextView renderView = view.getChildAt(childPosition).findViewById(R.id.extraInfoTextView);

renderView.setVisibility(renderView.getText().toString().contains("{") ||
renderView.getText().toString().equals("0") ? View.GONE : View.VISIBLE);
if (renderView.getTag(R.id.original_text) == null) {
renderView.setTag(R.id.original_text, renderView.getText());
}
}


if (!TextUtils.isEmpty(calculation)) {
renderView.setText(calculation.charAt(0) == '{' ? getRenderText(calculation, renderView.getTag(R.id.original_text).toString(), false) : calculation);
}

renderView.setVisibility(renderView.getText().toString().contains("{") ||
renderView.getText().toString().equals("0") ? View.GONE : View.VISIBLE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vijay.jsonwizard.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
Expand Down Expand Up @@ -57,6 +58,7 @@ abstract class JsonFormBaseActivity extends MultiLanguageActivity implements OnF
private Toolbar mToolbar;
private Map<String, ValidationStatus> invalidFields = new HashMap<>();
private boolean isPreviousPressed = false;
private ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -204,4 +206,12 @@ public RulesEngineFactory getRulesEngineFactory() {
public void setRulesEngineFactory(RulesEngineFactory rulesEngineFactory) {
this.rulesEngineFactory = rulesEngineFactory;
}

public ProgressDialog getProgressDialog() {
return progressDialog;
}

public void setProgressDialog(ProgressDialog progressDialog) {
this.progressDialog = progressDialog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Set;

public class FormErrorView extends LinearLayoutCompat {

private Map<String, ValidationStatus> invalidFields;
private HashMap<String, ArrayList<ValidationStatus>> errorsPerStep;

Expand Down Expand Up @@ -64,13 +63,13 @@ private void addCustomViews() {
View view = LayoutInflater.from(this.getContext()).inflate(R.layout.native_form_error_item, null, false);
FormErrorViewHolder formErrorViewHolder = new FormErrorViewHolder(view);
String errors;
StringBuilder sb = new StringBuilder();
StringBuilder stringBuilder = new StringBuilder();
String spacing = values.size() > 1 ? "\n\n" : "";
for (int i = 0; i < values.size(); i++) {
ValidationStatus validationStatus = values.get(i);
sb.append(i + 1).append(". ").append(validationStatus.getErrorMessage()).append(spacing);
stringBuilder.append(i + 1).append(". ").append(validationStatus.getErrorMessage()).append(spacing);
}
errors = sb.toString();
errors = stringBuilder.toString();
String stepName = key.toUpperCase();
formErrorViewHolder.bindViews(stepName, errors);
this.addView(formErrorViewHolder.getItemView());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,23 @@ public void onFormFinish() {

@Override
public void scrollToView(final View view) {
view.requestFocus();
if (!(view instanceof MaterialEditText)) {
mScrollView.post(new Runnable() {
if (getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
int y = view.getBottom() - view.getHeight();
if (y < 0) {
y = 0;
view.requestFocus();
if (!(view instanceof MaterialEditText)) {
mScrollView.post(new Runnable() {
@Override
public void run() {
int viewLength = view.getBottom() - view.getHeight();
if (viewLength < 0) {
viewLength = 0;
}
mScrollView.scrollTo(0, viewLength);
}
});
}
mScrollView.scrollTo(0, y);
}
});
}
Expand Down Expand Up @@ -619,16 +626,18 @@ public boolean onMenuItemClick(MenuItem item) {

protected class BottomNavigationListener implements View.OnClickListener {
@Override
public void onClick(View v) {
if (v.getId() == R.id.next_button) {
Object isSubmit = v.getTag(R.id.submit);
if (isSubmit != null && Boolean.valueOf(isSubmit.toString())) {
save(false);
} else {
next();
public void onClick(View view) {
if (view != null) {
if (view.getId() == R.id.next_button) {
Object isSubmit = view.getTag(R.id.submit);
if (isSubmit != null && Boolean.valueOf(isSubmit.toString())) {
save(false);
} else {
next();
}
} else if (view.getId() == R.id.previous_button) {
getFragmentManager().popBackStack();
}
} else if (v.getId() == R.id.previous_button) {
getFragmentManager().popBackStack();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.vijay.jsonwizard.interactors.JsonFormInteractor;
import com.vijay.jsonwizard.presenters.JsonFormFragmentPresenter;
import com.vijay.jsonwizard.presenters.JsonWizardFormFragmentPresenter;
import com.vijay.jsonwizard.task.NextProgressDialogTask;
import com.vijay.jsonwizard.viewstates.JsonFormFragmentViewState;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -37,7 +38,6 @@
* Created by keyman on 04/12/2018.
*/
public class JsonWizardFormFragment extends JsonFormFragment {

public static final String TAG = JsonWizardFormFragment.class.getName();
private static final int MENU_NAVIGATION = 100001;
private BottomNavigationListener navigationListener = new BottomNavigationListener();
Expand All @@ -48,6 +48,7 @@ public class JsonWizardFormFragment extends JsonFormFragment {
private TextView stepName;
private Toolbar navigationToolbar;
private View bottomNavLayout;
private JsonWizardFormFragment jsonFormFragment;

public static JsonWizardFormFragment getFormFragment(String stepName) {
JsonWizardFormFragment jsonFormFragment = new JsonWizardFormFragment();
Expand Down Expand Up @@ -148,6 +149,7 @@ private Form getForm() {
@Override
public void onResume() {
super.onResume();
setJsonFormFragment(this);
if (!getJsonApi().isPreviousPressed()) {
skipStepsOnNextPressed();
} else {
Expand Down Expand Up @@ -264,7 +266,7 @@ public void updateVisibilityOfNextAndSave(boolean next, boolean save) {
/**
* Skips blank by relevance steps when next is clicked on the json wizard forms.
*/
private void skipStepsOnNextPressed() {
public void skipStepsOnNextPressed() {
if (skipBlankSteps()) {
JSONObject formStep = getStep(getArguments().getString(JsonFormConstants.STEPNAME));
String next = formStep.optString(JsonFormConstants.NEXT, "");
Expand All @@ -280,7 +282,7 @@ private void skipStepsOnNextPressed() {
/**
* Skips blank by relevance steps when previous is clicked on the json wizard forms.
*/
private void skipStepOnPreviousPressed() {
public void skipStepOnPreviousPressed() {
if (skipBlankSteps()) {
JSONObject currentFormStep = getStep(getArguments().getString(JsonFormConstants.STEPNAME));
String next = currentFormStep.optString(JsonFormConstants.NEXT, "");
Expand Down Expand Up @@ -360,32 +362,43 @@ public TextView getStepName() {
return stepName;
}

public JsonWizardFormFragment getJsonFormFragment() {
return jsonFormFragment;
}

public void setJsonFormFragment(JsonWizardFormFragment jsonFormFragment) {
this.jsonFormFragment = jsonFormFragment;
}


////////////////////////////////////////////////////////////////
// Inner classes
////////////////////////////////////////////////////////////////

protected class BottomNavigationListener implements View.OnClickListener {
@Override
public void onClick(View view) {
if (view.getId() == R.id.next || view.getId() == R.id.next_icon) {
getJsonApi().setPreviousPressed(false);
Object tag = view.getTag(R.id.NEXT_STATE);
if (tag == null) {
next();
} else {
boolean next = (boolean) tag;
if (next) {
next();
if (view != null) {
if (view.getId() == R.id.next || view.getId() == R.id.next_icon) {
getJsonApi().setPreviousPressed(false);
Object nextStateTag = view.getTag(R.id.NEXT_STATE);
if (nextStateTag == null) {
new NextProgressDialogTask(getJsonFormFragment()).execute();
} else {
save();
boolean next = (boolean) nextStateTag;
if (next) {
new NextProgressDialogTask(getJsonFormFragment()).execute();
} else {
save();
}
}
}

} else if (view.getId() == R.id.previous || view.getId() == R.id.previous_icon) {
assert getFragmentManager() != null;
presenter.checkAndStopCountdownAlarm();
getJsonApi().setPreviousPressed(true);
getFragmentManager().popBackStack();
} else if (view.getId() == R.id.previous || view.getId() == R.id.previous_icon) {
assert getFragmentManager() != null;
presenter.checkAndStopCountdownAlarm();
getJsonApi().setPreviousPressed(true);
getFragmentManager().popBackStack();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ public boolean onNextClick(LinearLayout mainView) {
}

public void validateAndWriteValues() {
for (View childAt : formFragment.getJsonApi().getFormDataViews()) {
ValidationStatus validationStatus = validateView(childAt);
String key = (String) childAt.getTag(R.id.key);
String openMrsEntityParent = (String) childAt.getTag(R.id.openmrs_entity_parent);
String openMrsEntity = (String) childAt.getTag(R.id.openmrs_entity);
String openMrsEntityId = (String) childAt.getTag(R.id.openmrs_entity_id);
Boolean popup = (Boolean) childAt.getTag(R.id.extraPopup);
for (View childView : formFragment.getJsonApi().getFormDataViews()) {
ValidationStatus validationStatus = validateView(childView);
String key = (String) childView.getTag(R.id.key);
String openMrsEntityParent = (String) childView.getTag(R.id.openmrs_entity_parent);
String openMrsEntity = (String) childView.getTag(R.id.openmrs_entity);
String openMrsEntityId = (String) childView.getTag(R.id.openmrs_entity_id);
Boolean popup = (Boolean) childView.getTag(R.id.extraPopup);
String fieldKey = mStepName + "#" + getStepTitle() + ":" + key;

if (childAt instanceof MaterialEditText) {
MaterialEditText editText = (MaterialEditText) childAt;
if (childView instanceof MaterialEditText) {
MaterialEditText editText = (MaterialEditText) childView;

String rawValue = (String) editText.getTag(R.id.raw_value);
if (rawValue == null) {
Expand All @@ -201,15 +201,13 @@ public void validateAndWriteValues() {

handleWrongFormatInputs(validationStatus, fieldKey, rawValue);

String type = (String) childAt.getTag(R.id.type);
rawValue = JsonFormConstants.DATE_PICKER.equals(type) || JsonFormConstants.TIME_PICKER.
equals(type) ? childAt.getTag(R.id.locale_independent_value).toString() : rawValue;
String type = (String) childView.getTag(R.id.type);
rawValue = JsonFormConstants.DATE_PICKER.equals(type) || JsonFormConstants.TIME_PICKER.equals(type) ? childView.getTag(R.id.locale_independent_value).toString() : rawValue;
Log.d("Writing values ..", key + " " + rawValue);

getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity,
openMrsEntityId, popup);
} else if (childAt instanceof NativeEditText) {
NativeEditText editText = (NativeEditText) childAt;
getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
} else if (childView instanceof NativeEditText) {
NativeEditText editText = (NativeEditText) childView;

String rawValue = (String) editText.getTag(R.id.raw_value);
if (rawValue == null) {
Expand All @@ -218,34 +216,26 @@ public void validateAndWriteValues() {

handleWrongFormatInputs(validationStatus, fieldKey, rawValue);

getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity,
openMrsEntityId, popup);
} else if (childAt instanceof ImageView) {
Object path = childAt.getTag(R.id.imagePath);
getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
} else if (childView instanceof ImageView) {
Object path = childView.getTag(R.id.imagePath);
if (path instanceof String) {
getView().writeValue(mStepName, key, (String) path, openMrsEntityParent, openMrsEntity,
openMrsEntityId,
popup);
getView().writeValue(mStepName, key, (String) path, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
}
} else if (childAt instanceof CheckBox) {
String parentKey = (String) childAt.getTag(R.id.key);
String childKey = (String) childAt.getTag(R.id.childKey);
getView().writeValue(mStepName, parentKey, JsonFormConstants.OPTIONS_FIELD_NAME, childKey,
String.valueOf(((CheckBox) childAt).isChecked()), openMrsEntityParent, openMrsEntity,
openMrsEntityId, popup);
} else if (childAt instanceof RadioButton) {
String parentKey = (String) childAt.getTag(R.id.key);
String childKey = (String) childAt.getTag(R.id.childKey);
if (((RadioButton) childAt).isChecked()) {
getView().writeValue(mStepName, parentKey, childKey, openMrsEntityParent, openMrsEntity,
openMrsEntityId,
popup);
} else if (childView instanceof CheckBox) {
String parentKey = (String) childView.getTag(R.id.key);
String childKey = (String) childView.getTag(R.id.childKey);
getView().writeValue(mStepName, parentKey, JsonFormConstants.OPTIONS_FIELD_NAME, childKey, String.valueOf(((CheckBox) childView).isChecked()), openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
} else if (childView instanceof RadioButton) {
String parentKey = (String) childView.getTag(R.id.key);
String childKey = (String) childView.getTag(R.id.childKey);
if (((RadioButton) childView).isChecked()) {
getView().writeValue(mStepName, parentKey, childKey, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
}
} else if (childAt instanceof Button) {
Button button = (Button) childAt;
} else if (childView instanceof Button) {
Button button = (Button) childView;
String rawValue = (String) button.getTag(R.id.raw_value);
getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity,
openMrsEntityId, popup);
getView().writeValue(mStepName, key, rawValue, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);
}

if (!validationStatus.isValid()) {
Expand Down

0 comments on commit ae4fa5c

Please sign in to comment.