Commit bb9f2326 authored by rakam's avatar rakam

Updates Automate to work with Stats

parent 72f951a4
......@@ -27,7 +27,7 @@ public class HomeActivity extends Activity {
}
});
findViewById(R.id.resumeMatchButton).setEnabled(false);
//checkForSavedAutomate();
checkForSavedAutomate();
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Authentification...");
dialog.show();
......@@ -51,6 +51,8 @@ public class HomeActivity extends Activity {
@Override
protected void onPostExecute(final Automate automate) {
super.onPostExecute(automate);
int a = 98;
int b = 98;
//todo New API
// Ion.with(HomeActivity.this)
// .load("GET", API_URLS.INFO_MATCH + automate.getIdMatch())
......
......@@ -156,7 +156,7 @@ public abstract class MatchActivity extends Activity {
automate = getAutomateInstance(service, sideLeftA);
}
syncManager = new ScoreSyncManager(this, automate);
Score initScore = automate.last();
Score initScore = automate.last().getScore();
if (initScore.isSideLeftA())
setPlayerALeft();
else
......@@ -167,9 +167,7 @@ public abstract class MatchActivity extends Activity {
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Score previousScore = automate.back();
Point previousPoint = new Point(previousScore, null);
updateUI(previousPoint);
updateUI(automate.back());
}
});
}
......@@ -265,7 +263,7 @@ public abstract class MatchActivity extends Activity {
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
updateScore(new Point(automate.back(), null));
updateScore(automate.back());
}
});
builder.setPositiveButton("Confirmer", new DialogInterface.OnClickListener() {
......@@ -393,26 +391,26 @@ public abstract class MatchActivity extends Activity {
leftPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(leftPlayer), new Stats(Stats.Type.NONE, fsfButton.isSelected(), leftPlayer)));
updateUI(automate.point(new Stats(Stats.Type.NONE, fsfButton.isSelected(), leftPlayer)));
}
});
leftAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(leftPlayer), new Stats(Stats.Type.ACE, fsfButton.isSelected(), leftPlayer)));
updateUI(automate.point(new Stats(Stats.Type.ACE, fsfButton.isSelected(), leftPlayer)));
}
});
rightPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(rightPlayer), new Stats(Stats.Type.NONE, fsfButton.isSelected(), rightPlayer)));
updateUI(automate.point(new Stats(Stats.Type.NONE, fsfButton.isSelected(), rightPlayer)));
}
});
rightAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(rightPlayer), new Stats(Stats.Type.ACE, fsfButton.isSelected(), rightPlayer)));
updateUI(automate.point(new Stats(Stats.Type.ACE, fsfButton.isSelected(), rightPlayer)));
}
});
}
......
......@@ -9,8 +9,6 @@ import android.os.Bundle;
import android.view.WindowManager;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import java.util.ArrayList;
import java.util.List;
......@@ -31,7 +29,6 @@ import fr.istic.masteru.android.listeners.OnRefereeingTypeChangeListener;
import fr.istic.masteru.android.listeners.OnSelectedCourtChangeListener;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.API_URLS;
import fr.istic.masteru.android.utils.Constants;
import fr.istic.masteru.android.utils.PrefsUtils;
import fr.istic.masteru.android.utils.Utils;
......@@ -140,43 +137,64 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
param.addProperty("playerBEq2Id", playerB2.getId());
}
Ion.with(this)
.load("PUT", API_URLS.UPDATE_MATCH(match.getId()))
.setTimeout(1000 * 6)
.setJsonObjectBody(param)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e != null || result != null && result.get("code").getAsInt() != 0) {
startMatch(dialogToClose);
} else {
dialogToClose.cancel();
if (refereeingType == Constants.SIMPLE) {
Intent matchActivityIntent = new Intent(MatchSetupActivity.this, SingleMatchActivity.class);
matchActivityIntent.putExtra(MatchActivity.MATCH, match);
matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
startActivity(matchActivityIntent);
} else {
Intent matchActivityIntent = new Intent(MatchSetupActivity.this, DoubleMatchActivity.class);
matchActivityIntent.putExtra(MatchActivity.MATCH, match);
matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
matchActivityIntent.putExtra(DoubleMatchActivity.REFEREEING_TYPE, refereeingType);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A2, playerA2);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B2, playerB2);
startActivity(matchActivityIntent);
}
finish();
}
}
});
// Ion.with(this)
// .load("PUT", API_URLS.UPDATE_MATCH(match.getId()))
// .setTimeout(1000 * 6)
// .setJsonObjectBody(param)
// .asJsonObject()
// .setCallback(new FutureCallback<JsonObject>() {
// @Override
// public void onCompleted(Exception e, JsonObject result) {
// if (e != null || result != null && result.get("code").getAsInt() != 0) {
// startMatch(dialogToClose);
// } else {
// dialogToClose.cancel();
// if (refereeingType == Constants.SIMPLE) {
// Intent matchActivityIntent = new Intent(MatchSetupActivity.this, SingleMatchActivity.class);
// matchActivityIntent.putExtra(MatchActivity.MATCH, match);
// matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
// matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
// startActivity(matchActivityIntent);
// } else {
// Intent matchActivityIntent = new Intent(MatchSetupActivity.this, DoubleMatchActivity.class);
// matchActivityIntent.putExtra(MatchActivity.MATCH, match);
// matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
// matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
// matchActivityIntent.putExtra(DoubleMatchActivity.REFEREEING_TYPE, refereeingType);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_A2, playerA2);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
// matchActivityIntent.putExtra(MatchActivity.PLAYER_B2, playerB2);
// startActivity(matchActivityIntent);
// }
// finish();
// }
// }
// });
dialogToClose.cancel();
if (refereeingType == Constants.SIMPLE) {
Intent matchActivityIntent = new Intent(MatchSetupActivity.this, SingleMatchActivity.class);
matchActivityIntent.putExtra(MatchActivity.MATCH, match);
matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
startActivity(matchActivityIntent);
} else {
Intent matchActivityIntent = new Intent(MatchSetupActivity.this, DoubleMatchActivity.class);
matchActivityIntent.putExtra(MatchActivity.MATCH, match);
matchActivityIntent.putExtra(MatchActivity.SIDE_LEFT_A, side == Constants.A_IS_LEFT);
matchActivityIntent.putExtra(MatchActivity.SERVICE, firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
matchActivityIntent.putExtra(DoubleMatchActivity.REFEREEING_TYPE, refereeingType);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A2, playerA2);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B2, playerB2);
startActivity(matchActivityIntent);
}
finish();
}
@Override
......
......@@ -5,15 +5,15 @@ package fr.istic.masteru.android.automate;
*/
public interface Automate {
public Score point(int code);
public Point point(Stats stats);
public Score point2(int code);
public Point pointWithoutSaving(Stats stats);
public Score getPoint(int index);
public Point getPoint(int index);
public Score back();
public Point back();
public Score last();
public Point last();
public int getIdMatch();
......
......@@ -10,8 +10,8 @@ import java.util.Vector;
*/
public class AutomateDouble implements Automate {
public Vector<InfoScore> pile = new Vector<InfoScore>();
public Stack<Integer> pileEtat = new Stack<Integer>();
public Vector<Step> pile = new Vector<>();
public Stack<Integer> pileEtat = new Stack<>();
protected int etat;
protected int numact;
protected InfoScore score;
......@@ -28,38 +28,22 @@ public class AutomateDouble implements Automate {
this.idMatch = idMatch;
int myInt = (sideLeftA) ? 1 : 0;
myInt = myInt * 10;
pile.add(DoublePoint.executer(-(service) - myInt).copy());
pile.add(new Step(DoublePoint.executer(-(service) - myInt).copy(), null));
etat = 0;
pileEtat.add(etat);
}
@Override
public Score point(int code) {
/** Vérification TieBreak */
if (!DoublePoint.getScore().isTieBreak()) {
/** Vérification SuperTieBreak */
if (!DoublePoint.getScore().isSuperTieBreak()) {
numact = DoublePoint.action[etat][code];
etat = DoublePoint.transit[etat][code];
score = DoublePoint.executer(numact).copy();
} else {
score = DoublePoint.executer(20 + code).copy();
}
} else {
score = DoublePoint.executer(10 + code).copy();
}
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
/* Ajout de score dans un vecteur de score */
pile.add(score.copy());
FileManager.point(context, code);
return score.getScore();
public Point point(Stats stats) {
Point point = pointWithoutSaving(stats);
FileManager.point(context, point);
return point;
}
@Override
public Score point2(int code) {
public Point pointWithoutSaving(Stats stats) {
int code = stats.getWinner();
/** Vérification TieBreak */
if (!DoublePoint.getScore().isTieBreak()) {
/** Vérification SuperTieBreak */
......@@ -73,21 +57,26 @@ public class AutomateDouble implements Automate {
} else {
score = DoublePoint.executer(10 + code).copy();
}
// todo modifier stats pour mettre breakPoint à true/false
Point point = new Point(score.getScore(), stats);
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
/* Ajout de score dans un vecteur de score */
pile.add(score.copy());
return score.getScore();
pile.add(new Step(score, stats));
return point;
}
@Override
public Score getPoint(int index) {
return pile.elementAt(index).getScore();
public Point getPoint(int index) {
return pile.elementAt(index).getPoint();
}
@Override
public Score back() {
public Point back() {
/* Delete si pile non "vide" */
if (pile.size() > 1 && pile.size() > 1) {
......@@ -101,7 +90,7 @@ public class AutomateDouble implements Automate {
etat = pileEtat.lastElement();
/* Mise à jour score */
DoublePoint.setScore(pile.lastElement());
DoublePoint.setScore(pile.lastElement().getInfoScore());
/* OLD : Vérification TieBreak & SuperTieBreak
if (DoublePoint.getScore().getGamesA() == 6 && DoublePoint.getScore().getGamesB() == 6) {
......@@ -117,7 +106,7 @@ public class AutomateDouble implements Automate {
*/
}
FileManager.deleteLast(context);
return pile.lastElement().getScore();
return pile.lastElement().getPoint();
}
public int getIdMatch() {
......@@ -125,7 +114,7 @@ public class AutomateDouble implements Automate {
}
@Override
public Score last() {
return pile.lastElement().getScore();
public Point last() {
return pile.lastElement().getPoint();
}
}
......@@ -10,7 +10,7 @@ import java.util.Vector;
*/
public class AutomateDoublePro implements Automate {
public Vector<InfoScore> pile = new Vector<InfoScore>();
public Vector<Step> pile = new Vector<>();
public Stack<Integer> pileEtat = new Stack<Integer>();
protected int etat;
protected int numact;
......@@ -28,33 +28,21 @@ public class AutomateDoublePro implements Automate {
this.idMatch = idMatch;
int myInt = (sideLeftA) ? 1 : 0;
myInt = myInt * 10;
pile.add(DoubleProPoint.executer(-(service) - myInt).copy());
pile.add(new Step(DoubleProPoint.executer(-(service) - myInt).copy(), null));
etat = 0;
pileEtat.add(etat);
}
@Override
public Score point(int code) {
/** Vérification TieBreak */
if (!DoubleProPoint.getScore().isTieBreak()) {
numact = DoubleProPoint.action[etat][code];
etat = DoubleProPoint.transit[etat][code];
score = DoubleProPoint.executer(numact).copy();
} else {
score = DoubleProPoint.executer(10 + code).copy();
}
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
/* Ajout de score dans un vecteur de score */
pile.add(score);
FileManager.point(context, code);
return score.getScore();
public Point point(Stats stats) {
Point point = pointWithoutSaving(stats);
FileManager.point(context, point);
return point;
}
@Override
public Score point2(int code) {
public Point pointWithoutSaving(Stats stats) {
int code = stats.getWinner();
/** Vérification TieBreak */
if (!DoubleProPoint.getScore().isTieBreak()) {
numact = DoubleProPoint.action[etat][code];
......@@ -64,21 +52,25 @@ public class AutomateDoublePro implements Automate {
score = DoubleProPoint.executer(10 + code).copy();
}
// todo modifier stats pour mettre breakPoint à true/false
Point point = new Point(score.getScore(), stats);
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
/* Ajout de score dans un vecteur de score */
pile.add(score);
return score.getScore();
pile.add(new Step(score, stats));
return point;
}
@Override
public Score getPoint(int index) {
return pile.elementAt(index).getScore();
public Point getPoint(int index) {
return pile.elementAt(index).getPoint();
}
@Override
public Score back() {
public Point back() {
/* Delete si pile non "vide" */
if (pile.size() > 0 && pile.size() > 1) {
/* Suppression de l'élément dans la pile */
......@@ -91,7 +83,7 @@ public class AutomateDoublePro implements Automate {
etat = pileEtat.lastElement();
/* Mise à jour score */
DoubleProPoint.setScore(pile.lastElement());
DoubleProPoint.setScore(pile.lastElement().getInfoScore());
/* OLD : Vérification tie-break
if (DoubleProPoint.getScore().getGamesA() == 7 && DoubleProPoint.getScore().getGamesB() == 7) {
......@@ -102,7 +94,7 @@ public class AutomateDoublePro implements Automate {
*/
}
FileManager.deleteLast(context);
return pile.lastElement().getScore();
return pile.lastElement().getPoint();
}
......@@ -111,7 +103,7 @@ public class AutomateDoublePro implements Automate {
}
@Override
public Score last() {
return pile.lastElement().getScore();
public Point last() {
return pile.lastElement().getPoint();
}
}
......@@ -10,7 +10,7 @@ import java.util.Vector;
*/
public class AutomateSimple implements Automate {
public Vector<InfoScore> pile = new Vector<InfoScore>();
public Vector<Step> pile = new Vector<>();
public Stack<Integer> pileEtat = new Stack<Integer>();
protected int etat;
protected int numact;
......@@ -28,59 +28,49 @@ public class AutomateSimple implements Automate {
this.idMatch = idMatch;
int myInt = (sideLeftA) ? 1 : 0;
myInt = myInt * 10;
pile.add(SimplePoint.executer(-(service) - myInt).copy());
pile.add(new Step(SimplePoint.executer(-(service) - myInt).copy(), null));
etat = 0;
pileEtat.add(etat);
}
@Override
public Score point(int code) {
/** Vérification TieBreak */
if (!SimplePoint.getScore().isTieBreak()) {
numact = SimplePoint.action[etat][code];
etat = SimplePoint.transit[etat][code];
score = SimplePoint.executer(numact).copy();
} else {
score = SimplePoint.executer(10 + code).copy();
}
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
/* Ajout de score dans un vecteur de score */
pile.add(score);
FileManager.point(context, code);
return score.getScore();
public Point point(Stats stats) {
Point point = pointWithoutSaving(stats);
FileManager.point(context, point);
return point;
}
public Score point2(int code) {
public Point pointWithoutSaving(Stats stats) {
int pointWinner = stats.getWinner();
/** Vérification TieBreak */
if (!SimplePoint.getScore().isTieBreak()) {
numact = SimplePoint.action[etat][code];
etat = SimplePoint.transit[etat][code];
numact = SimplePoint.action[etat][pointWinner];
etat = SimplePoint.transit[etat][pointWinner];
score = SimplePoint.executer(numact).copy();
} else {
score = SimplePoint.executer(10 + code).copy();
score = SimplePoint.executer(10 + pointWinner).copy();
}
// todo modifier stats pour mettre breakPoint à true/false
Point point = new Point(score.getScore(), stats);
/* Ajout de l'état dans une pile d'état */
pileEtat.add(etat);
pileEtat.add(etat); //todo - Il y a peut être du changement a faire ici
/* Ajout de score dans un vecteur de score */
pile.add(score);
pile.add(new Step(score, stats)); // todo - Et ici aussi
return score.getScore();
return point;
}
@Override
public Score getPoint(int index) {
return pile.elementAt(index).getScore();
public Point getPoint(int index) {
return pile.elementAt(index).getPoint();
}
@Override
public Score back() {
public Point back() {
/* Delete si pile non "vide" */
if (pile.size() > 0 && pile.size() > 1) {
/* Suppression de l'élément dans la pile */
......@@ -93,7 +83,7 @@ public class AutomateSimple implements Automate {
etat = pileEtat.lastElement();
/* Mise à jour score */
SimplePoint.setScore(pile.lastElement());
SimplePoint.setScore(pile.lastElement().getInfoScore());
/* OLD :Verification tie-break
if (SimplePoint.getScore().getGamesA() == 6 && SimplePoint.getScore().getGamesB() == 6) {
......@@ -104,7 +94,8 @@ public class AutomateSimple implements Automate {
*/
}
FileManager.deleteLast(context);
return pile.lastElement().getScore();
return pile.lastElement().getPoint();
}
public int getIdMatch() {
......@@ -113,7 +104,7 @@ public class AutomateSimple implements Automate {
@Override
public Score last() {
return pile.lastElement().getScore();
public Point last() {
return pile.lastElement().getPoint();
}
}
\ No newline at end of file
......@@ -25,4 +25,8 @@ public class Point {
public void setStats(Stats stats) {
this.stats = stats;
}
public String getBackupString() {
return stats.getBackupString();
}
}
......@@ -6,6 +6,7 @@ public class Stats {
private Type type;
private boolean fsf;
private boolean breakPoint;
private int winner;