Commit e8a6d28a authored by rakam's avatar rakam

back to the homescreen if a match is finished by an admin

parent 55d2d009
......@@ -365,6 +365,7 @@ public abstract class MatchActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle("Synchronisation terminée");
builder.setMessage("Retour à l'accueil");
builder.setCancelable(false);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
......@@ -528,6 +529,23 @@ public abstract class MatchActivity extends Activity {
// Do nothing when back button is pressed
}
public void onMatchFinishedSyncError() {
FileManager.deleteFile(MatchActivity.this); // Suppresion de la sauvegarde du match terminé
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle("Match terminé");
builder.setMessage("Le match a été terminé par un administrateur");
builder.setCancelable(false);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(MatchActivity.this, HomeActivity.class);
startActivity(intent);
finish();
}
});
builder.show();
}
protected abstract String getPlayerName(int player);
/**
......
package fr.istic.masteru.android.utils;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
......@@ -11,6 +10,7 @@ import com.koushikdutta.ion.Ion;
import java.util.Map;
import java.util.TreeMap;
import fr.istic.masteru.android.activities.MatchActivity;
import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.Point;
import fr.istic.masteru.android.automate.Score;
......@@ -32,7 +32,7 @@ public class ScoreSyncManager {
private static final int RETRY_DELAY = 3 * 1000;
private static final String TAG = "SCORE_SYNC_MANAGER";
private Context context;
private MatchActivity matchActivity;
private Automate automate;
private int idMatch;
private TreeMap<Float, Object> syncQueue = new TreeMap<>();
......@@ -44,8 +44,8 @@ public class ScoreSyncManager {
*/
private OnSyncFinishListener syncFinishListener;
public ScoreSyncManager(Context context, Automate automate) {
this.context = context;
public ScoreSyncManager(MatchActivity matchActivity, Automate automate) {
this.matchActivity = matchActivity;
this.idMatch = automate.getIdMatch();
this.automate = automate;
}
......@@ -161,10 +161,10 @@ public class ScoreSyncManager {
param.addProperty("fsf", point.getStats().isFsf() ? "1" : "0");
param.addProperty("break", point.getStats().isBreakPoint() ? "1" : "0");
Ion.with(context)
Ion.with(matchActivity)
.load("POST", API_URLS.UPDATE_SCORE(idMatch, score.getId()))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(matchActivity))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......@@ -195,6 +195,9 @@ public class ScoreSyncManager {
Log.d(TAG, "SyncScore " + code);
syncQueue.remove(key);
break;
case -5: // Match not in progress
matchActivity.onMatchFinishedSyncError();
return;
}
syncNextElement();
} else {
......@@ -227,10 +230,10 @@ public class ScoreSyncManager {
param.addProperty("gameA", previousSet.getSetA());
param.addProperty("gameB", previousSet.getSetB());
Ion.with(context)
Ion.with(matchActivity)
.load("PUT", API_URLS.UPDATE_SET_SCORE(idMatch, previousSet.getNumSet()))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(matchActivity))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......@@ -272,10 +275,10 @@ public class ScoreSyncManager {
* @param backToSync
*/
private void syncBack(final float key, BackToSync backToSync) {
Ion.with(context)
Ion.with(matchActivity)
.load("DELETE", API_URLS.DELETE_SCORE(idMatch, backToSync.getId()))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(matchActivity))
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
......@@ -325,10 +328,10 @@ public class ScoreSyncManager {
param.addProperty("winner", winnerToSync.getWinner());
param.addProperty("endDate", Utils.getCurrentDateInMySQLFormat());
Ion.with(context)
Ion.with(matchActivity)
.load("PUT", API_URLS.UPDATE_MATCH(idMatch))
.setTimeout(TIMEOUT_MS)
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(context))
.setHeader(API_URLS.AUTH_TOKEN, PrefsUtils.getToken(matchActivity))
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
......
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