Skip to content

Commit

Permalink
Refactoring RadioButton,Native Button threads
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Jun 30, 2022
1 parent 0d8b26d commit 9ab982e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,11 @@ public void run() {
try {
if (finalCheckBoxValues != null) {
for (String checkBoxVal : Objects.requireNonNull(getCurrentCheckboxValues(finalCheckBoxValues))) {
if (checkBoxVal!=null &&checkBoxVal.charAt(0) == '{') {
if (new JSONObject(checkBoxVal).optString(JsonFormConstants.VALUE).equalsIgnoreCase(item.getString(JsonFormConstants.KEY))) {
if (checkBoxVal != null && checkBoxVal.startsWith("{")) {
JSONObject jsonObject = new JSONObject(checkBoxVal);
if (jsonObject.optString(JsonFormConstants.VALUE).equalsIgnoreCase(item.getString(JsonFormConstants.KEY)) || getCurrentCheckboxValues(finalCheckBoxValues).contains(item.getString(JsonFormConstants.KEY))) {
checkBox.setChecked(true);
}
} else if (getCurrentCheckboxValues(finalCheckBoxValues).contains(item.getString(JsonFormConstants.KEY))) {
checkBox.setChecked(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,25 +621,18 @@ public void run() {

private void checkSelectedRadioButton(final CommonListener listener, final RadioButton radioButton, String value, JSONObject item) throws JSONException {
if (StringUtils.isNotBlank(value)) {
if (value.equals(item.getString(JsonFormConstants.KEY))) {
JSONObject jsonObject = null;
if (value.startsWith("{")) {
jsonObject = new JSONObject(value);
}
if (value.equals(item.getString(JsonFormConstants.KEY)) || (jsonObject != null && jsonObject.has(JsonFormConstants.VALUE) && jsonObject.optString(JsonFormConstants.VALUE).equals(item.getString(JsonFormConstants.KEY)))) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
radioButton.setChecked(true);
radioButton.setOnCheckedChangeListener(listener);
}
});
} else if (value.charAt(0) == '{') {
JSONObject object = new JSONObject(value);
if (object.has(JsonFormConstants.VALUE) && object.optString(JsonFormConstants.VALUE).equals(item.getString(JsonFormConstants.KEY))) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
radioButton.setChecked(true);
radioButton.setOnCheckedChangeListener(listener);
}
});
}
}
} else {
radioButton.setOnCheckedChangeListener(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ public List<View> getViewsFromJson(String stepName, Context context, JsonFormFra
// radioButton.setTextSize(context.getResources().getDimension(R.dimen.default_text_size));
radioButton.setOnCheckedChangeListener(listener);
if (!TextUtils.isEmpty(jsonObject.optString(JsonFormConstants.VALUE))) {
if (jsonObject.optString(JsonFormConstants.VALUE).equals(item.getString(JsonFormConstants.KEY))) {
radioButton.setChecked(true);
JSONObject translatedObject = null;
if (jsonObject.optString(JsonFormConstants.VALUE).startsWith("{")) {
translatedObject = new JSONObject(jsonObject.optString(JsonFormConstants.VALUE));
}
if (jsonObject.optString(JsonFormConstants.VALUE).charAt(0) == '{') {
JSONObject object = new JSONObject(jsonObject.optString(JsonFormConstants.VALUE));
if (object.optString(JsonFormConstants.VALUE).equals(item.optString(JsonFormConstants.KEY))) {
radioButton.setChecked(true);
}
if (jsonObject.optString(JsonFormConstants.VALUE).equals(item.getString(JsonFormConstants.KEY)) || (translatedObject != null && translatedObject.optString(JsonFormConstants.VALUE).equals(item.optString(JsonFormConstants.KEY)))) {
radioButton.setChecked(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
} else if (keysJson != null && valueToSelect.equals(keysJson.optString(i))) {
indexToSelect = i;
}
else if (keysJson != null && StringUtils.isNotBlank(valueToSelect) && valueToSelect.charAt(0) == '{' && new JSONObject(valueToSelect).has(JsonFormConstants.VALUE)
else if (keysJson != null && StringUtils.isNotBlank(valueToSelect) && valueToSelect.startsWith("{") && new JSONObject(valueToSelect).has(JsonFormConstants.VALUE)
&& new JSONObject(valueToSelect).optString(JsonFormConstants.VALUE).equals(keysJson.optString(i))) {
indexToSelect = i;
}
Expand Down

0 comments on commit 9ab982e

Please sign in to comment.