I have a cursor which is an id to get the next set of results from server, and i tried adding a do while loop until cursor value reaches 0 (end of results), i realised onResponse and onFailure callback methods are not called once i added the do while loop so the cursor is stuck at initial value without reaching 0 (fetchResults from the api are not called). The loadTwitterFriends keeps getting called and it resulted in an infinite do while loop. Can i know why the callback methods aren't triggered even though i set a listener to wait for the response? The cursor value is successfully retrieved if the do while loop is removed (callback onResponse works) but i can't iterate through the results without the loop. Any form of help is appreciated!
do {
loadTwitterFriends(new cursorListener() {
@Override
public void onFollowReceived(long cursor) {
adapter.notifyDataSetChanged();
}
});
}
while(getCursor() != 0);
loadTwitterFriends() with callback methods
private void loadTwitterFriends(final cursorListener listener) {
MyTwitterApiClient myTwitterApiClient = new MyTwitterApiClient(twitterSession);
myTwitterApiClient.getCustomTwitterService().list(loggedUserTwitterId,getCursor()).enqueue(new retrofit2.Callback<FriendsResponseModel>() {
@Override
public void onResponse(Call<FriendsResponseModel> call, Response<FriendsResponseModel> response) {
Log.e("onResponselol", "Is response success" + response.isSuccessful());
twitterFriends = fetchResults(response);
getActivity().setTitle(String.valueOf(twitterFriends.size()) + " Following");
setCursor(fetchResults3(response));
Log.e("onResponseFlwing", "Cursor:" + getCursor());
Log.e("onResponse", "twitterfriends:" + twitterFriends.size());
listener.onFollowReceived(getCursor());
}
@Override
public void onFailure(Call<FriendsResponseModel> call, Throwable t) {
Log.e("onFailure", t.toString());
listener.onFollowReceived(1);
}
});
}
fetchResults
private List<TwitterFriends> fetchResults(Response<FriendsResponseModel> response) {
FriendsResponseModel responseModel = response.body();
if (responseModel != null) {
Log.e("lol","asd");
return responseModel.getResults();
}
else{
Log.e("lol","dsa");
return Collections.emptyList();
}
}