Skip to content

Commit

Permalink
Merge 3035911 into 4994735
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Jun 27, 2022
2 parents 4994735 + 3035911 commit 4a1ff43
Show file tree
Hide file tree
Showing 36 changed files with 1,091 additions and 590 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run unit tests with Gradle
run: ./gradlew :android-json-form-wizard:clean :android-json-form-wizard:jacocoTestReport --stacktrace
run: ./gradlew android-json-form-wizard:clean && ./gradlew android-json-form-wizard:build && ./gradlew android-json-form-wizard:jacocoTestReport --stacktrace -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
- name: Upload coverage to Coveralls with Gradle
run: ./gradlew coveralls --stacktrace
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
- name: Generate Javadoc with Gradle
run: ./gradlew javadoc
run: ./gradlew javadoc
2 changes: 2 additions & 0 deletions android-json-form-wizard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ android {

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

repositories {
Expand Down Expand Up @@ -139,6 +140,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.android.support:multidex:1.0.3'
testImplementation project(path: ':android-json-form-wizard')

// PowerMock
def powerMockVersion = '2.0.4'
Expand Down
2 changes: 2 additions & 0 deletions android-json-form-wizard/src/main/assets/app.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
widget.datepicker.is.numeric=true
widget.value.translated=true
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.vijay.jsonwizard.activities;

import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;
import static com.vijay.jsonwizard.utils.FormUtils.getCheckboxValueJsonArray;
import static com.vijay.jsonwizard.utils.FormUtils.getCurrentCheckboxValues;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
Expand Down Expand Up @@ -68,6 +72,7 @@
import com.vijay.jsonwizard.utils.AppExecutors;
import com.vijay.jsonwizard.utils.ExObjectResult;
import com.vijay.jsonwizard.utils.FormUtils;
import com.vijay.jsonwizard.utils.NativeFormsProperties;
import com.vijay.jsonwizard.utils.PermissionUtils;
import com.vijay.jsonwizard.utils.PropertyManager;
import com.vijay.jsonwizard.utils.Utils;
Expand Down Expand Up @@ -102,38 +107,20 @@

import timber.log.Timber;

import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;
import static com.vijay.jsonwizard.utils.FormUtils.getCheckboxValueJsonArray;
import static com.vijay.jsonwizard.utils.FormUtils.getCurrentCheckboxValues;

public class JsonFormActivity extends JsonFormBaseActivity implements JsonApi {

private FormUtils formUtils = new FormUtils();
private Map<String, View> formDataViews = new ConcurrentHashMap<>();
private Map<String, JSONObject> formFields = new ConcurrentHashMap<>();
private Set<String> popupFormFields = new ConcurrentSkipListSet<>();
private String functionRegex;
private HashMap<String, Comparison> comparisons;
private Map<String, List<String>> ruleKeys = new HashMap<>();
private GenericDialogInterface genericDialogInterface;
private JSONArray extraFieldsWithValues;
private Map<String, String> formValuesCacheMap = new HashMap<>();
private TextView selectedTextView = null;
private Utils utils = new Utils();
private HashMap<String, String[]> addressMap = new HashMap<>();

private Map<String, Set<String>> calculationDependencyMap = new HashMap<>();
private Map<String, Set<String>> skipLogicDependencyMap = new HashMap<>();

private Map<String, Boolean> stepSkipLogicPresenceMap = new ConcurrentHashMap<>();

private boolean isNextStepRelevant;

private String nextStep = "";

private AppExecutors appExecutors = new AppExecutors();

private BroadcastReceiver messageReceiver = new BroadcastReceiver() {
private final FormUtils formUtils = new FormUtils();
private final Map<String, JSONObject> formFields = new ConcurrentHashMap<>();
private final Set<String> popupFormFields = new ConcurrentSkipListSet<>();
private final Map<String, List<String>> ruleKeys = new HashMap<>();
private final Map<String, String> formValuesCacheMap = new HashMap<>();
private final Utils utils = new Utils();
private final HashMap<String, String[]> addressMap = new HashMap<>();
private final Map<String, Set<String>> calculationDependencyMap = new HashMap<>();
private final Map<String, Set<String>> skipLogicDependencyMap = new HashMap<>();
private final Map<String, Boolean> stepSkipLogicPresenceMap = new ConcurrentHashMap<>();
private final AppExecutors appExecutors = new AppExecutors();
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String messageType = intent.getStringExtra(JsonFormConstants.INTENT_KEY.MESSAGE_TYPE);
Expand All @@ -147,6 +134,15 @@ public void onReceive(Context context, Intent intent) {
}
}
};
private Map<String, View> formDataViews = new ConcurrentHashMap<>();
private String functionRegex;
private HashMap<String, Comparison> comparisons;
private GenericDialogInterface genericDialogInterface;
private JSONArray extraFieldsWithValues;
private TextView selectedTextView = null;
private boolean isNextStepRelevant;
private String nextStep = "";


public void performActionOnReceived(String stepName) {
try {
Expand Down Expand Up @@ -342,7 +338,6 @@ public void refreshSkipLogic(String parentKey, String childKey, boolean popup, S
}
}


public Pair<String[], JSONObject> getCalculationAddressAndValue(View view) throws JSONException {
String calculationTag = (String) view.getTag(R.id.calculation);
String widgetKey = (String) view.getTag(R.id.key);
Expand Down Expand Up @@ -719,7 +714,6 @@ protected void initiateFormUpdate(JSONObject json) {
}
}


@Override
public void updateGenericPopupSecondaryValues(JSONArray jsonArray, String stepName) {
if (jsonArray == null || jsonArray.length() == 0) {
Expand Down Expand Up @@ -899,7 +893,11 @@ private void getFieldObject(String stepName, List<String> rulesList, JSONArray r
String value;
if (JsonFormConstants.CHECK_BOX.equals(fieldObject.getString(JsonFormConstants.TYPE))) {
value = String.valueOf(fieldObject.getJSONArray(JsonFormConstants.VALUES));
fieldObject.put(JsonFormConstants.VALUE, value);
if (Utils.enabledProperty(NativeFormsProperties.KEY.WIDGET_VALUE_TRANSLATED)) {
fieldObject.put(value, Utils.generateTranslatableValue(value, fieldObject));
} else {
fieldObject.put(JsonFormConstants.VALUE, value);
}
} else {
value = fieldObject.getJSONArray(JsonFormConstants.VALUES).getString(0);
fieldObject.put(JsonFormConstants.VALUE, value);
Expand Down Expand Up @@ -947,11 +945,41 @@ private void widgetWriteItemValue(String value, JSONObject item, String itemType
if (!TextUtils.isEmpty(value)) {
value = value.trim();
}
item.put(JsonFormConstants.VALUE, itemType.equals(JsonFormConstants.HIDDEN) && TextUtils.isEmpty(value) ?
item.has(JsonFormConstants.VALUE) && !TextUtils.isEmpty(item.getString(JsonFormConstants.VALUE)) ?
item.getString(JsonFormConstants.VALUE) : value : value);
if (itemType.equals(JsonFormConstants.HIDDEN) && TextUtils.isEmpty(value)) {
if (item.has(JsonFormConstants.VALUE) && !TextUtils.isEmpty(item.getString(JsonFormConstants.VALUE)))
item.put(JsonFormConstants.VALUE, item.getString(JsonFormConstants.VALUE));
else item.put(JsonFormConstants.VALUE, value);
} else {
if ((itemType.equals(JsonFormConstants.NATIVE_RADIO_BUTTON) || itemType.equals(JsonFormConstants.SPINNER) || itemType.equals(JsonFormConstants.CHECK_BOX)) && Utils.enabledProperty(NativeFormsProperties.KEY.WIDGET_VALUE_TRANSLATED)) {
if (itemType.equals(JsonFormConstants.SPINNER)) {
if (item.has(JsonFormConstants.KEYS) && item.has(JsonFormConstants.VALUES)) {
item.put(JsonFormConstants.VALUE, value);
} else {
item.put(JsonFormConstants.VALUE, Utils.generateTranslatableValue(value, item));
}
} else {
if (item.optString(JsonFormConstants.KEY).equalsIgnoreCase("reminders")) {
item.put(JsonFormConstants.VALUE, value);
} else {
item.put(JsonFormConstants.VALUE, Utils.generateTranslatableValue(value, item));
}
}
} else {
item.put(JsonFormConstants.VALUE, value);
}
}
}

/**
* Generates a JSONObject Value for the value translatable fields
*
* @param value
* @param item
* @param itemType
* @return
*/


private boolean checkPopUpValidity(String[] curKey, boolean popup) throws JSONException {
boolean validity = false;
if (popup) {
Expand Down Expand Up @@ -1020,9 +1048,19 @@ protected void checkBoxWriteValue(String stepName, String parentKey, String chil
childKey.equals(option.getString(JsonFormConstants.KEY))) {
option.put(JsonFormConstants.VALUE, Boolean.parseBoolean(value));
if (Boolean.parseBoolean(value)) {
currentValues.add(childKey);
if (Utils.enabledProperty(NativeFormsProperties.KEY.WIDGET_VALUE_TRANSLATED)) {
JSONObject object = Utils.generateTranslatableValue(childKey, option);
currentValues.add(object.toString());
} else {
currentValues.add(childKey);
}
} else {
currentValues.remove(childKey);
if (Utils.enabledProperty(NativeFormsProperties.KEY.WIDGET_VALUE_TRANSLATED)) {
JSONObject object = Utils.generateTranslatableValue(childKey, option);
currentValues.remove(object.toString());
} else {
currentValues.remove(childKey);
}
}
}
}
Expand Down Expand Up @@ -1092,7 +1130,8 @@ protected void onResume() {
}


protected Pair<String[], JSONObject> getRelevanceAddress(View view, boolean popup) throws JSONException {
protected Pair<String[], JSONObject> getRelevanceAddress(View view, boolean popup) throws
JSONException {
if (view != null) {
String relevanceTag = (String) view.getTag(R.id.relevance);
String widgetKey = (String) view.getTag(R.id.key);
Expand Down Expand Up @@ -1283,7 +1322,8 @@ private void checkViewConstraints(View curView, boolean popup) {
}
}

private void updateUiByConstraints(View curView, boolean popup, String errorMessage) throws JSONException {
private void updateUiByConstraints(View curView, boolean popup, String errorMessage) throws
JSONException {
String[] address = ((String) curView.getTag(R.id.address)).split(":");
if (errorMessage != null) {
if (curView instanceof MaterialEditText) {
Expand Down Expand Up @@ -1970,7 +2010,8 @@ public void run() {

}

private void updateCalculation(Facts valueMap, View view, String[] address, boolean isForNextStep) {
private void updateCalculation(Facts valueMap, View view, String[] address,
boolean isForNextStep) {
String calculation;
try {
if (address[0].equals(RuleConstant.RULES_DYNAMIC)) {
Expand Down Expand Up @@ -2104,8 +2145,8 @@ protected Object getValue(JSONObject object) throws JSONException {
Object value;

if (object.has(JsonFormConstants.VALUE)) {
value = object.opt(JsonFormConstants.VALUE);

value = Utils.getValueFromTranslatedObject(object);
// value = object.opt(JsonFormConstants.VALUE);
if (isNumberWidget(object)) {
value = TextUtils.isEmpty(object.optString(JsonFormConstants.VALUE)) ? 0 : processNumberValues(object.optString(JsonFormConstants.VALUE));
} else if (value != null && !TextUtils.isEmpty(object.getString(JsonFormConstants.VALUE)) && canHaveNumber(object)) {
Expand Down Expand Up @@ -2467,6 +2508,10 @@ public boolean isNextStepRelevant() {
return isNextStepRelevant;
}

public void setNextStepRelevant(boolean nextStepRelevant) {
isNextStepRelevant = nextStepRelevant;
}

@Override
public String nextStep() {
return nextStep;
Expand All @@ -2477,10 +2522,6 @@ public void setNextStep(String nextStep) {
this.nextStep = nextStep;
}

public void setNextStepRelevant(boolean nextStepRelevant) {
isNextStepRelevant = nextStepRelevant;
}

@Override
public Map<String, JSONObject> getFormFieldsMap() {
return formFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public class JsonFormConstants {
public static final String PROPERTIES_FILE_EXTENSION = ".properties";
public static final String JSON_FILE_EXTENSION = ".json";
public static final String CLIENT_FORM_ASSET_VERSION = "base version";
public static final String TRANSLATION_TEXT = "translation_text";

public interface MultiSelectUtils {
String IS_HEADER = "isHeader";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.vijay.jsonwizard.utils.FormUtils;
import com.vijay.jsonwizard.utils.Utils;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
Expand All @@ -23,6 +24,12 @@
*/
public class RulesEngineDateUtil {

public static int getAgeFromDate(String dateOfBirth) {
Date date = Utils.getDateFromString(dateOfBirth);
Years age = Years.yearsBetween(new DateTime(date).toLocalDate(), LocalDate.now());
return age.getYears();
}

public long getDifferenceDays(String dateString) {
Date date = Utils.getDateFromString(dateString);

Expand Down Expand Up @@ -68,7 +75,7 @@ public String getDateTimeToday() {
* @return String
*/
public String getDuration(String date, String endDate) {
return Utils.getDuration(Utils.getDateFormattedForCalculation(date, Form.getDatePickerDisplayFormat()),
return Utils.getDuration(Utils.getDateFormattedForCalculation(date, Form.getDatePickerDisplayFormat()),
endDate);
}

Expand All @@ -80,7 +87,7 @@ public String getWeeksAndDaysFromDays(Integer days) {
}

public String formatDate(String dateString, String duration) {
LocalDate date = new LocalDate(Utils.reverseDateString(Utils.getDateFormattedForCalculation(dateString, Form.getDatePickerDisplayFormat()), "-"));
LocalDate date = new LocalDate(Utils.reverseDateString(Utils.getDateFormattedForCalculation(dateString, Form.getDatePickerDisplayFormat()), "-"));
int result = 0;
String cleanDuration = duration.trim().toLowerCase();

Expand Down Expand Up @@ -130,7 +137,7 @@ public String addDuration(String durationString) {
* @return String with date
*/
public String addDuration(String dateString, String durationString) {
LocalDate date = new LocalDate(Utils.reverseDateString(Utils.getDateFormattedForCalculation(dateString, Form.getDatePickerDisplayFormat()), "-"));
LocalDate date = new LocalDate(Utils.reverseDateString(Utils.getDateFormattedForCalculation(dateString, Form.getDatePickerDisplayFormat()), "-"));
String[] durationArr = getDurationArray(durationString);

for (String duration : durationArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
*/
public class RulesEngineHelper {

private RulesEngineDateUtil rulesEngineDateUtil = new RulesEngineDateUtil();
private final RulesEngineDateUtil rulesEngineDateUtil = new RulesEngineDateUtil();

public long getDifferenceDays(String dateString) {
return rulesEngineDateUtil.getDifferenceDays(dateString);
}

public int getMothersAge(String dateOfBirth) {
return RulesEngineDateUtil.getAgeFromDate(dateOfBirth);
}

public long getDifferenceDays(String dateString, String dateString2) {
return rulesEngineDateUtil.getDifferenceDays(dateString, dateString2);
}
Expand Down
Loading

0 comments on commit 4a1ff43

Please sign in to comment.