Commit ba4def1e authored by rakam's avatar rakam
Browse files

New API (Sync Winner)

parent baa880a5
......@@ -10,8 +10,6 @@ import com.koushikdutta.ion.Ion;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeoutException;
import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.Score;
......@@ -218,8 +216,8 @@ public class ScoreSyncManager {
*/
private void synchronizePreviousSet(final float key, PreviousSetToSync previousSet) {
JsonObject param = new JsonObject();
param.addProperty("setA", previousSet.getSetA());
param.addProperty("setB", previousSet.getSetB());
param.addProperty("gameA", previousSet.getSetA());
param.addProperty("gameB", previousSet.getSetB());
Ion.with(context)
.load("PUT", API_URLS.UPDATE_SET_SCORE(idMatch, previousSet.getNumSet()))
......@@ -325,46 +323,30 @@ public class ScoreSyncManager {
.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, "Winner 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, "Winner Exception:" + e, Toast.LENGTH_SHORT).show();
Log.d(TAG, "WinnerException:" + e);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
syncNextElement();
}
}, RETRY_DELAY);
}
} 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, "Winner OK!", Toast.LENGTH_SHORT).show();
if (syncFinishListener != null)
syncFinishListener.onSyncFinish();
} else {
Log.d(TAG, "Winner:" + result);
// Toast.makeText(context, "Winner Error code:" + code, Toast.LENGTH_SHORT).show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
syncNextElement();
}
}, RETRY_DELAY);
switch (code) {
case 0:
// Sync OK
Log.d(TAG, "SyncWinner " + code);
syncQueue.remove(key);
if (syncFinishListener != null)
syncFinishListener.onSyncFinish();
break;
}
syncNextElement();
} else {
if (e != null)
Log.d(TAG, "SyncWinner ", e);
else
Log.d(TAG, "SyncWinner error");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
syncNextElement();
}
}, RETRY_DELAY);
}
}
});
......
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