Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unnecessary multi-threading #665

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,41 +372,37 @@ public Pair<String[], JSONObject> getCalculationAddressAndValue(View view) throw

@Override
public void refreshCalculationLogic(String parentKey, String childKey, boolean popup, String stepName, boolean isForNextStep) {
appExecutors.diskIO().execute(() ->{
Set<String> viewsIds = calculationDependencyMap.get(stepName + "_" + parentKey);
if (parentKey == null || viewsIds == null)
viewsIds = calculationLogicViews.keySet();
for (String viewId : viewsIds) {
try {
View curView = calculationLogicViews.get(viewId);
if (curView == null) {
Timber.w("calculationLogicViews Missing %s", viewId);
continue;
Set<String> viewsIds = calculationDependencyMap.get(stepName + "_" + parentKey);
if (parentKey == null || viewsIds == null)
viewsIds = calculationLogicViews.keySet();
for (String viewId : viewsIds) {
try {
View curView = calculationLogicViews.get(viewId);
if (curView == null) {
Timber.w("calculationLogicViews Missing %s", viewId);
continue;
}
Pair<String[], JSONObject> addressAndValue = getCalculationAddressAndValue(curView);
if (addressAndValue != null && addressAndValue.first != null) {
String[] address = addressAndValue.first;
JSONObject valueSource = addressAndValue.second;
Facts curValueMap;
if (valueSource.length() > 0) {
curValueMap = getValueFromAddress(address, popup, valueSource);
} else {
curValueMap = getValueFromAddress(address, popup);
}
Pair<String[], JSONObject> addressAndValue = getCalculationAddressAndValue(curView);
if (addressAndValue != null && addressAndValue.first != null) {
String[] address = addressAndValue.first;
JSONObject valueSource = addressAndValue.second;
Facts curValueMap;
if (valueSource.length() > 0) {
curValueMap = getValueFromAddress(address, popup, valueSource);
} else {
curValueMap = getValueFromAddress(address, popup);
}
//update ui
appExecutors.mainThread().execute(() -> {
updateCalculation(curValueMap, curView, address, isForNextStep);
});
//update ui
updateCalculation(curValueMap, curView, address, isForNextStep);

}
}

} catch (Exception e) {
Timber.e(e, "%s refreshCalculationLogic()", this.getClass().getCanonicalName());
} catch (Exception e) {
Timber.e(e, "%s refreshCalculationLogic()", this.getClass().getCanonicalName());

}
}
}

});

}

Expand Down Expand Up @@ -629,26 +625,24 @@ public JSONObject getObjectUsingAddress(String[] address, boolean popup, JSONObj
*/
@Override
public void refreshConstraints(String parentKey, String childKey, boolean popup) {
appExecutors.diskIO().execute(()->{
initComparisons();
initComparisons();

// Priorities constraints on the view that has just been changed
String changedViewKey = parentKey;
if (changedViewKey != null && childKey != null) {
changedViewKey = changedViewKey + ":" + childKey;
}
// Priorities constraints on the view that has just been changed
String changedViewKey = parentKey;
if (changedViewKey != null && childKey != null) {
changedViewKey = changedViewKey + ":" + childKey;
}

if (changedViewKey != null && (constrainedViews != null && constrainedViews.containsKey(changedViewKey))) {
checkViewConstraints(constrainedViews.get(changedViewKey), popup);
}
if (changedViewKey != null && (constrainedViews != null && constrainedViews.containsKey(changedViewKey))) {
checkViewConstraints(constrainedViews.get(changedViewKey), popup);
}

for (View curView : constrainedViews.values()) {
String viewKey = getViewKey(curView);
if (changedViewKey == null || (!TextUtils.isEmpty(viewKey) && !viewKey.equals(changedViewKey))) {
checkViewConstraints(curView, popup);
}
for (View curView : constrainedViews.values()) {
String viewKey = getViewKey(curView);
if (changedViewKey == null || (!TextUtils.isEmpty(viewKey) && !viewKey.equals(changedViewKey))) {
checkViewConstraints(curView, popup);
}
});
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,9 @@ public void testGetViewKey() throws Exception {
assertEquals(key + ":" + childKey, returnKey);

}
}

@Test
public void testGetCOuntSHouldReturnTheCorrectCount() {
assertEquals("1", activity.getCount());
}
}
Loading