Commit baa880a5 authored by rakam's avatar rakam
Browse files

New API (Update Set)

parent d58b93ce
......@@ -5,7 +5,6 @@ public class API_URLS {
public static final String BASE_URL = "http://5.196.21.161:9222";
public static final String PING_ADD_NUMBER = BASE_URL + "/test/nombres/ajouterNombre";
public static final String SCORE_UPDATE = BASE_URL + "/score/update";
public static final String SET_SCORE_UPDATE = BASE_URL + "/score/majSet";
public static final String MATCH_WINNER = BASE_URL + "/match/finMatch";
public static final String MATCHS = BASE_URL + "/matches";
public static final String INFO_MATCH = BASE_URL + "/match/info/"; // + idMatch
......@@ -22,6 +21,10 @@ public class API_URLS {
return BASE_URL + "/matches/" + matchId + "/score/" + pointId;
}
public static String UPDATE_SET_SCORE(int matchId, int setId) {
return BASE_URL + "/matches/" + matchId + "/set/" + setId;
}
public static String DELETE_SCORE(int matchId, int pointId) {
return BASE_URL + "/matches/" + matchId + "/score/" + pointId;
}
......
......@@ -218,44 +218,42 @@ public class ScoreSyncManager {
*/
private void synchronizePreviousSet(final float key, PreviousSetToSync previousSet) {
JsonObject param = new JsonObject();
param.addProperty("idMatch", idMatch);
param.addProperty("numSet", previousSet.getNumSet());
param.addProperty("setA", previousSet.getSetA());
param.addProperty("setB", previousSet.getSetB());
Ion.with(context)
.load("POST", API_URLS.SET_SCORE_UPDATE)
.load("PUT", API_URLS.UPDATE_SET_SCORE(idMatch, previousSet.getNumSet()))
.setTimeout(TIMEOUT_MS)
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e != null) { // Exception
if (e instanceof CancellationException || e instanceof TimeoutException) {
// Toast.makeText(context, "PreviousSet Cancelled", Toast.LENGTH_SHORT).show();
// After a timeout, retry in 5 seconds
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
syncNextElement();
}
}, RETRY_DELAY);
} else {
// Toast.makeText(context, "PreviousSet Exception:" + e, Toast.LENGTH_SHORT).show();
Log.d(TAG, "PreviousSetException:" + e);
}
} else { // JSON
if (result != null && result.has("code")) {
int code = result.getAsJsonPrimitive("code").getAsInt();
if (code == 0) { // MAJ OK
syncQueue.remove(key);
// Toast.makeText(context, "PREVIOUS_SET MAJ OK", Toast.LENGTH_SHORT).show();
syncNextElement();
} else {
Log.d(TAG, "PreviousSet:" + result);
// Toast.makeText(context, "PREVIOUS_SET Error code:" + code, Toast.LENGTH_SHORT).show();
switch (code) {
case 0:
// Sync OK
Log.d(TAG, "SyncPreviousSet " + code);
syncQueue.remove(key);
break;
case -2:
Log.d(TAG, "SyncPreviousSet " + code);
break;
}
syncNextElement();
} else {
if (e != null)
Log.d(TAG, "SyncPreviousSet ", e);
else
Log.d(TAG, "SyncPreviousSet error");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
syncNextElement();
}
}, RETRY_DELAY);
}
}
});
......@@ -285,6 +283,10 @@ public class ScoreSyncManager {
case -2:
Log.d(TAG, "Back " + code);
break;
case -3:
Log.d(TAG, "Back " + code);
syncQueue.remove(key);
break;
}
syncNextElement();
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment