JSOModel jso = response.cast();
if (jso.hasKey("error")) {
Window.alert("Get Friend List Error");
return;
}
final JsArray array = jso.getArray("data");
if (array != null) {
for (int i = 0; i < array.length(); i++) {
JSOModel j = array.get(i).cast();
final String name = j.get("name");
final String id = j.get("id");
friendsName.put(id, name);
loginService.getIdInfo(fbUid, id, new AsyncCallback<OtherPlayerInfo>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(OtherPlayerInfo result) {
if (result.getExist() == 0) {
noAgainstList.add(new Contact(name, id, result.getRank(), result.getrd(), result.getGameId()));
}
else{
// User Turn = 1, Opponent Turn = 2
switch (result.getTurn()) {
case 1:
userTurnList.add(new Contact(name, id, result.getRank(), result.getrd(),result.getGameId()));
break;
case 2:
opponentTurnList.add(new Contact(name, id, result.getRank(), result.getrd(),result.getGameId()));
break;
}
}
counter++;
if (counter == array.length()) {
Collections.sort(noAgainstList);
Collections.sort(userTurnList);
Collections.sort(opponentTurnList);
for (int i = 0; i < userTurnList.size(); i++) {