Here is the code:
public void onRefresh() {
MyDDPState.getInstance().getItems(null, new DDPListener() {
@Override
public void onResult(Map<String, Object> json) {
Log.d(TAG, "refreshed");
if (json.get("result") == null) {
/*
* Result is null action
*/
Log.d(TAG, "Null");
swipeLayout.setRefreshing(false);
return;
}
List<Map<String, Object>> temp = (ArrayList) json.get("result");
Log.d(TAG, temp.toString());
MyDDPState.getInstance().initItems(temp);
Log.d(TAG, "converted" + MyDDPState.getInstance().getItems().toString());
Log.d(TAG, swipeLayout.toString());
Log.d(TAG, "Finished refreshing");
swipeLayout.setRefreshing(false);
Log.d(TAG, "Refresh closed");
}
});
}
swipeLayout refers to a private variable in the class that holds the SwipeRefreshLayout. On the callback, I try to call setrefreshing(false) to get rid of the progress indicator, but this call hangs the async function. All the other Logs work except for the "Refresh closed" log.
For some reason, I think because of the library I'm using, errors inside DDP Listeners are not logged either, so I can't trace it. swipeLayout.setRefreshing when called outside of the DDP call work fine.
Anyway, I managed to solve the issue.
When I tried to change a ui variable, the function would stop running.
Turns out the issue was that I was changing UI variables on the wrong thread. To fix it, you have to make the UI calls inside a ui thread by calling:
More info here: http://developer.android.com/tools/testing/activity_testing.html