Commit baa880a5 authored by rakam's avatar rakam
Browse files

New API (Update Set)

parent d58b93ce
...@@ -5,7 +5,6 @@ public class API_URLS { ...@@ -5,7 +5,6 @@ public class API_URLS {
public static final String BASE_URL = "http://5.196.21.161:9222"; 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 PING_ADD_NUMBER = BASE_URL + "/test/nombres/ajouterNombre";
public static final String SCORE_UPDATE = BASE_URL + "/score/update"; 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 MATCH_WINNER = BASE_URL + "/match/finMatch";
public static final String MATCHS = BASE_URL + "/matches"; public static final String MATCHS = BASE_URL + "/matches";
public static final String INFO_MATCH = BASE_URL + "/match/info/"; // + idMatch public static final String INFO_MATCH = BASE_URL + "/match/info/"; // + idMatch
...@@ -22,6 +21,10 @@ public class API_URLS { ...@@ -22,6 +21,10 @@ public class API_URLS {
return BASE_URL + "/matches/" + matchId + "/score/" + pointId; 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) { public static String DELETE_SCORE(int matchId, int pointId) {
return BASE_URL + "/matches/" + matchId + "/score/" + pointId; return BASE_URL + "/matches/" + matchId + "/score/" + pointId;
} }
......
...@@ -218,44 +218,42 @@ public class ScoreSyncManager { ...@@ -218,44 +218,42 @@ public class ScoreSyncManager {
*/ */
private void synchronizePreviousSet(final float key, PreviousSetToSync previousSet) { private void synchronizePreviousSet(final float key, PreviousSetToSync previousSet) {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("idMatch", idMatch);
param.addProperty("numSet", previousSet.getNumSet());
param.addProperty("setA", previousSet.getSetA()); param.addProperty("setA", previousSet.getSetA());
param.addProperty("setB", previousSet.getSetB()); param.addProperty("setB", previousSet.getSetB());
Ion.with(context) Ion.with(context)
.load("POST", API_URLS.SET_SCORE_UPDATE) .load("PUT", API_URLS.UPDATE_SET_SCORE(idMatch, previousSet.getNumSet()))
.setTimeout(TIMEOUT_MS) .setTimeout(TIMEOUT_MS)
.setJsonObjectBody(param) .setJsonObjectBody(param)
.asJsonObject() .asJsonObject()
.setCallback(new FutureCallback<JsonObject>() { .setCallback(new FutureCallback<JsonObject>() {
@Override @Override
public void onCompleted(Exception e, JsonObject result) { public void onCompleted(Exception e, JsonObject result) {
if (e != null) { // Exception if (result != null && result.has("code")) {
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
int code = result.getAsJsonPrimitive("code").getAsInt(); int code = result.getAsJsonPrimitive("code").getAsInt();
if (code == 0) { // MAJ OK switch (code) {
syncQueue.remove(key); case 0:
// Toast.makeText(context, "PREVIOUS_SET MAJ OK", Toast.LENGTH_SHORT).show(); // Sync OK
syncNextElement(); Log.d(TAG, "SyncPreviousSet " + code);
} else { syncQueue.remove(key);
Log.d(TAG, "PreviousSet:" + result); break;
// Toast.makeText(context, "PREVIOUS_SET Error code:" + code, Toast.LENGTH_SHORT).show(); 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 { ...@@ -285,6 +283,10 @@ public class ScoreSyncManager {
case -2: case -2:
Log.d(TAG, "Back " + code); Log.d(TAG, "Back " + code);
break; break;
case -3:
Log.d(TAG, "Back " + code);
syncQueue.remove(key);
break;
} }
syncNextElement(); syncNextElement();
} else { } 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