Commit da9df19f authored by rakam's avatar rakam

Reprise de l'automate

parent 0f8fd2a2
......@@ -2,7 +2,6 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/MasterU.iml" filepath="$PROJECT_DIR$/MasterU.iml" />
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
......
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
......@@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
......@@ -84,11 +85,11 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="ion-2.1.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.0" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.1.2" level="project" />
<orderEntry type="library" exported="" name="ion-2.1.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
</component>
</module>
......@@ -7,9 +7,16 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.FileManager;
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.OnFinishCallback;
import fr.istic.masteru.android.utils.Utils;
......@@ -51,72 +58,72 @@ public class HomeActivity extends Activity {
@Override
protected void onPostExecute(final Automate automate) {
super.onPostExecute(automate);
//todo New API
// Ion.with(HomeActivity.this)
// .load("GET", API_URLS.INFO_MATCH + automate.getIdMatch())
// .asJsonObject()
// .setCallback(new FutureCallback<JsonObject>() {
// @Override
// public void onCompleted(Exception e, JsonObject result) {
// if (e != null || result == null) {
// checkForSavedAutomate();
// return;
// }
// String countryA = result.getAsJsonPrimitive("Nation_A").getAsString();
// String countryB = result.getAsJsonPrimitive("Nation_B").getAsString();
// final String categorie = result.getAsJsonPrimitive("Categorie").getAsString();
// String tableau = result.getAsJsonPrimitive("Tableau").getAsString();
//
// final PlayerInfo playerA1, playerA2, playerB1, playerB2;
// String nameA = result.getAsJsonPrimitive("Nom_CompletA").getAsString();
// String nameB = result.getAsJsonPrimitive("Nom_CompletB").getAsString();
// if (categorie.contains("D")) {
// int idPlayerA1 = result.getAsJsonPrimitive("IdJoueurA_1").getAsInt();
// int idPlayerA2 = result.getAsJsonPrimitive("IdJoueurA_2").getAsInt();
// int idPlayerB1 = result.getAsJsonPrimitive("IdJoueurB_1").getAsInt();
// int idPlayerB2 = result.getAsJsonPrimitive("IdJoueurB_2").getAsInt();
// String nameA1 = nameA.split("/")[0];
// String nameA2 = nameA.split("/")[1];
// String nameB1 = nameB.split("/")[0];
// String nameB2 = nameB.split("/")[1];
// playerA1 = new PlayerInfo(idPlayerA1, PlayerInfo.MAN, nameA1, countryA);
// playerA2 = new PlayerInfo(idPlayerA2, PlayerInfo.MAN, nameA2, countryA);
// playerB1 = new PlayerInfo(idPlayerB1, PlayerInfo.MAN, nameB1, countryB);
// playerB2 = new PlayerInfo(idPlayerB2, PlayerInfo.MAN, nameB2, countryB);
// } else {
// int idPlayerA = result.getAsJsonPrimitive("IdJoueurA").getAsInt();
// int idPlayerB = result.getAsJsonPrimitive("IdJoueurB").getAsInt();
// playerA1 = new PlayerInfo(idPlayerA, PlayerInfo.MAN, nameA, countryA);
// playerB1 = new PlayerInfo(idPlayerB, PlayerInfo.MAN, nameB, countryB);
// playerA2 = null;
// playerB2 = null;
// }
// final Match match = new Match(automate.getIdMatch(), countryA, countryB, categorie, tableau);
// findViewById(R.id.resumeMatchButton).setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// if (categorie.contains("D")) {
// Intent intent = new Intent(HomeActivity.this, DoubleMatchActivity.class);
// intent.putExtra(MatchActivity.RESUME_MATCH, true);
// intent.putExtra(MatchActivity.MATCH, match);
// intent.putExtra(MatchActivity.PLAYER_A1, playerA1);
// intent.putExtra(MatchActivity.PLAYER_A2, playerA2);
// intent.putExtra(MatchActivity.PLAYER_B1, playerB1);
// intent.putExtra(MatchActivity.PLAYER_B2, playerB2);
// startActivity(intent);
// } else {
// Intent intent = new Intent(HomeActivity.this, SingleMatchActivity.class);
// intent.putExtra(MatchActivity.RESUME_MATCH, true);
// intent.putExtra(MatchActivity.MATCH, match);
// intent.putExtra(MatchActivity.PLAYER_A1, playerA1);
// intent.putExtra(MatchActivity.PLAYER_B1, playerB1);
// startActivity(intent);
// }
// }
// });
// findViewById(R.id.resumeMatchButton).setEnabled(true);
// }
// });
Ion.with(HomeActivity.this)
.load("GET", API_URLS.INFO_MATCH(automate.getIdMatch()))
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e != null || result == null) {
checkForSavedAutomate();
return;
}
JsonObject jsonMatch = result.getAsJsonObject("match");
String teamA = jsonMatch.getAsJsonPrimitive("Team_A").getAsString();
String teamB = jsonMatch.getAsJsonPrimitive("Team_B").getAsString();
final String category = jsonMatch.getAsJsonPrimitive("Category").getAsString();
String tableau = jsonMatch.getAsJsonPrimitive("Tableau").getAsString();
final PlayerInfo playerA1, playerA2, playerB1, playerB2;
String nameA = jsonMatch.getAsJsonPrimitive("Name_CompletA").getAsString();
String nameB = jsonMatch.getAsJsonPrimitive("Name_CompletB").getAsString();
if (category.contains("D")) {
int idPlayerA1 = jsonMatch.getAsJsonPrimitive("IdPlayerA_1").getAsInt();
int idPlayerA2 = jsonMatch.getAsJsonPrimitive("IdPlayerA_2").getAsInt();
int idPlayerB1 = jsonMatch.getAsJsonPrimitive("IdPlayerB_1").getAsInt();
int idPlayerB2 = jsonMatch.getAsJsonPrimitive("IdPlayerB_2").getAsInt();
String nameA1 = nameA.split("/")[0];
String nameA2 = nameA.split("/")[1];
String nameB1 = nameB.split("/")[0];
String nameB2 = nameB.split("/")[1];
playerA1 = new PlayerInfo(idPlayerA1, PlayerInfo.MAN, nameA1, teamA);
playerA2 = new PlayerInfo(idPlayerA2, PlayerInfo.MAN, nameA2, teamA);
playerB1 = new PlayerInfo(idPlayerB1, PlayerInfo.MAN, nameB1, teamB);
playerB2 = new PlayerInfo(idPlayerB2, PlayerInfo.MAN, nameB2, teamB);
} else {
int idPlayerA = jsonMatch.getAsJsonPrimitive("IdPlayerA").getAsInt();
int idPlayerB = jsonMatch.getAsJsonPrimitive("IdPlayerB").getAsInt();
playerA1 = new PlayerInfo(idPlayerA, PlayerInfo.MAN, nameA, teamA);
playerB1 = new PlayerInfo(idPlayerB, PlayerInfo.MAN, nameB, teamB);
playerA2 = null;
playerB2 = null;
}
final Match match = new Match(automate.getIdMatch(), teamA, teamB, category, tableau);
findViewById(R.id.resumeMatchButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (category.contains("D")) {
Intent intent = new Intent(HomeActivity.this, DoubleMatchActivity.class);
intent.putExtra(MatchActivity.RESUME_MATCH, true);
intent.putExtra(MatchActivity.MATCH, match);
intent.putExtra(MatchActivity.PLAYER_A1, playerA1);
intent.putExtra(MatchActivity.PLAYER_A2, playerA2);
intent.putExtra(MatchActivity.PLAYER_B1, playerB1);
intent.putExtra(MatchActivity.PLAYER_B2, playerB2);
startActivity(intent);
} else {
Intent intent = new Intent(HomeActivity.this, SingleMatchActivity.class);
intent.putExtra(MatchActivity.RESUME_MATCH, true);
intent.putExtra(MatchActivity.MATCH, match);
intent.putExtra(MatchActivity.PLAYER_A1, playerA1);
intent.putExtra(MatchActivity.PLAYER_B1, playerB1);
startActivity(intent);
}
}
});
findViewById(R.id.resumeMatchButton).setEnabled(true);
}
});
}
}.execute(null, null, null);
}
......
......@@ -83,20 +83,20 @@ public class AutomateDouble implements Automate {
relanceur = (score.getService() + 1) % 2;
// Relanceur est joueur A
if (relanceur == 0){
if (relanceur == 0) {
// On cherche la différence de score
if((scoreA > scoreB) && (scoreA == 40)){
if ((scoreA > scoreB) && (scoreA == 40)) {
return true;
}else{
} else {
return false;
}
}
// Relanceur est joueur B
else{
else {
// On cherche la différence de score
if((scoreB > scoreA) && (scoreB == 40)){
if ((scoreB > scoreA) && (scoreB == 40)) {
return true;
}else{
} else {
return false;
}
}
......
......@@ -78,20 +78,20 @@ public class AutomateDoublePro implements Automate {
relanceur = (score.getService() + 1) % 2;
// Relanceur est joueur A
if (relanceur == 0){
if (relanceur == 0) {
// On cherche la différence de score
if((scoreA > scoreB) && (scoreA == 40)){
if ((scoreA > scoreB) && (scoreA == 40)) {
return true;
}else{
} else {
return false;
}
}
// Relanceur est joueur B
else{
else {
// On cherche la différence de score
if((scoreB > scoreA) && (scoreB == 40)){
if ((scoreB > scoreA) && (scoreB == 40)) {
return true;
}else{
} else {
return false;
}
}
......
......@@ -78,20 +78,20 @@ public class AutomateSimple implements Automate {
relanceur = (score.getService() + 1) % 2;
// Relanceur est joueur A
if (relanceur == 0){
if (relanceur == 0) {
// On cherche la différence de score
if((scoreA > scoreB) && (scoreA == 40 || scoreA == 4444)){
if ((scoreA > scoreB) && (scoreA == 40 || scoreA == 4444)) {
return true;
}else{
} else {
return false;
}
}
// Relanceur est joueur B
else{
else {
// On cherche la différence de score
if((scoreB > scoreA) && (scoreB == 40 || scoreB == 4444)){
if ((scoreB > scoreA) && (scoreB == 40 || scoreB == 4444)) {
return true;
}else{
} else {
return false;
}
}
......
......@@ -156,7 +156,7 @@ public class SelectPlayersFragment extends SetupFragment {
String name = o.get("Name").getAsString();
String firstName = o.get("FirstName").getAsString();
int gender = o.get("Sex").getAsString().equals("M") ? PlayerInfo.MAN : PlayerInfo.WOMAN;
PlayerInfo playerInfo = new PlayerInfo(playerId, gender, name, firstName, countryCode);
PlayerInfo playerInfo = new PlayerInfo(playerId, gender, firstName + name, countryCode);
if (team == TEAM_A)
playersA.add(playerInfo);
else
......
......@@ -12,14 +12,12 @@ public class PlayerInfo implements Serializable {
private int id;
private int gender;
private String name;
private String firstName;
private String nationality;
public PlayerInfo(int id, int gender, String name, String firstName, String nationality) {
public PlayerInfo(int id, int gender, String name, String nationality) {
this.id = id;
this.gender = gender;
this.name = name;
this.firstName = firstName;
this.nationality = nationality;
}
......
......@@ -7,7 +7,6 @@ public class API_URLS {
public static final String SCORE_UPDATE = BASE_URL + "/score/update";
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
public static final String AVAILABLE_COURTS = BASE_URL + "/courts/available";
public static final String LOGIN = BASE_URL + "/login";
......@@ -15,6 +14,10 @@ public class API_URLS {
return BASE_URL + "/teams/" + teamId + "/players?gender=" + (gender == null ? "X" : gender);
}
public static String INFO_MATCH(int matchId) {
return BASE_URL + "/matches/" + matchId;
}
public static String UPDATE_MATCH(int matchId) {
return BASE_URL + "/matches/" + matchId;
}
......
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