Commit 60ae01e9 authored by rakam's avatar rakam

Add TeamInfo

parent bb8e8478
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
</value>
</option>
<option name="RIGHT_MARGIN" value="100" />
<AndroidXmlCodeStyleSettings>
<option name="USE_CUSTOM_SETTINGS" value="true" />
</AndroidXmlCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*:layout_width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>.*:layout_height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<NAME>.*:layout_.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*:width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*:height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</rules>
</arrangement>
</codeStyleSettings>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>
......@@ -16,6 +16,7 @@ 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.model.TeamInfo;
import fr.istic.masteru.android.utils.API_URLS;
import fr.istic.masteru.android.utils.OnFinishCallback;
import fr.istic.masteru.android.utils.Utils;
......@@ -69,8 +70,12 @@ public class HomeActivity extends Activity {
return;
}
JsonObject jsonMatch = result.getAsJsonObject("match");
String teamA = jsonMatch.getAsJsonPrimitive("Team_A").getAsString();
String teamB = jsonMatch.getAsJsonPrimitive("Team_B").getAsString();
String isoA = jsonMatch.get("Team_A").getAsString();
String isoB = jsonMatch.get("Team_B").getAsString();
// todo get flag and full team names
TeamInfo teamA = new TeamInfo(isoA, isoA, null);
TeamInfo teamB = new TeamInfo(isoB, isoB, null);
final String category = jsonMatch.getAsJsonPrimitive("Category").getAsString();
String tableau = jsonMatch.getAsJsonPrimitive("Tableau").getAsString();
......@@ -86,15 +91,15 @@ public class HomeActivity extends Activity {
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);
playerA1 = new PlayerInfo(idPlayerA1, PlayerInfo.MAN, nameA1, teamA.getISO());
playerA2 = new PlayerInfo(idPlayerA2, PlayerInfo.MAN, nameA2, teamA.getISO());
playerB1 = new PlayerInfo(idPlayerB1, PlayerInfo.MAN, nameB1, teamB.getISO());
playerB2 = new PlayerInfo(idPlayerB2, PlayerInfo.MAN, nameB2, teamB.getISO());
} 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);
playerA1 = new PlayerInfo(idPlayerA, PlayerInfo.MAN, nameA, teamA.getISO());
playerB1 = new PlayerInfo(idPlayerB, PlayerInfo.MAN, nameB, teamB.getISO());
playerA2 = null;
playerB2 = null;
}
......
......@@ -16,13 +16,13 @@ import java.util.ArrayList;
import java.util.List;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.fragments.RefereeingTypeFragment;
import fr.istic.masteru.android.fragments.ResultFragment;
import fr.istic.masteru.android.fragments.SelectCourtFragment;
import fr.istic.masteru.android.fragments.SelectFirstServiceFragment;
import fr.istic.masteru.android.fragments.SelectInitialSideFragment;
import fr.istic.masteru.android.fragments.SelectMatchFragment;
import fr.istic.masteru.android.fragments.SelectPlayersFragment;
import fr.istic.masteru.android.fragments.SelectRefereeingTypeFragment;
import fr.istic.masteru.android.fragments.SetupFragment;
import fr.istic.masteru.android.listeners.OnFirstServiceChangeListener;
import fr.istic.masteru.android.listeners.OnInitialSideChangeListener;
......@@ -31,6 +31,7 @@ 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.model.TeamInfo;
import fr.istic.masteru.android.utils.API_URLS;
import fr.istic.masteru.android.utils.Constants;
import fr.istic.masteru.android.utils.PrefsUtils;
......@@ -48,7 +49,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
private Match match;
private int refereeingType;
private PlayerInfo playerA1, playerA2, playerB1, playerB2;
private String firstServiceCountryCode;
private TeamInfo firstServerTeam;
private int side = Constants.UNDEFINED;
private int idCourt;
......@@ -129,7 +130,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
param.addProperty("action", "START");
param.addProperty("court", idCourt);
param.addProperty("startDate", Utils.getCurrentDateInMySQLFormat());
param.addProperty("service", firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
param.addProperty("service", firstServerTeam.equals(match.getTeamA()) ? 0 : 1);
param.addProperty("playerAEq1Id", playerA1.getId());
param.addProperty("playerAEq2Id", playerB1.getId());
if (refereeingType == Constants.SIMPLE) {
......@@ -156,7 +157,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
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.SERVICE, firstServerTeam.getISO().equals(match.getTeamA().getISO()) ? 0 : 1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_B1, playerB1);
startActivity(matchActivityIntent);
......@@ -164,7 +165,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
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(MatchActivity.SERVICE, firstServerTeam.getISO().equals(match.getTeamA().getISO()) ? 0 : 1);
matchActivityIntent.putExtra(DoubleMatchActivity.REFEREEING_TYPE, refereeingType);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A1, playerA1);
matchActivityIntent.putExtra(MatchActivity.PLAYER_A2, playerA2);
......@@ -183,10 +184,10 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
this.match = match;
resultFragment.setMatchInfos(match);
if (match != null && match.getCategory().contains("D")
&& !flow.get(1).equals(RefereeingTypeFragment.class.getName())) {
flow.add(1, RefereeingTypeFragment.class.getName());
&& !flow.get(1).equals(SelectRefereeingTypeFragment.class.getName())) {
flow.add(1, SelectRefereeingTypeFragment.class.getName());
} else if (match != null && !match.getCategory().contains("D") &&
flow.get(1).equals(RefereeingTypeFragment.class.getName())) {
flow.get(1).equals(SelectRefereeingTypeFragment.class.getName())) {
flow.remove(1);
}
}
......@@ -228,9 +229,9 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
}
@Override
public void onFirstServiceChange(String country) {
resultFragment.setFirstService(country);
firstServiceCountryCode = country;
public void onFirstServiceChange(TeamInfo teamInfo) {
resultFragment.setFirstService(teamInfo);
firstServerTeam = teamInfo;
}
@Override
......
......@@ -9,6 +9,8 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.koushikdutta.ion.Ion;
import java.util.List;
import fr.istic.masteru.android.R;
......@@ -64,10 +66,12 @@ public class MatchAdapter extends BaseAdapter {
}
final Match match = matches.get(position);
ViewHolder viewHolder = (ViewHolder) itemView.getTag();
viewHolder.drapeauA.setImageResource(Utils.getCountryFlag(match.getTeamA()));
viewHolder.drapeauB.setImageResource(Utils.getCountryFlag(match.getTeamB()));
viewHolder.paysA.setText(Utils.getCountryName(match.getTeamA()));
viewHolder.paysB.setText(Utils.getCountryName(match.getTeamB()));
Ion.with(viewHolder.drapeauA)
.load(match.getTeamA().getFlagUrl());
Ion.with(viewHolder.drapeauB)
.load(match.getTeamB().getFlagUrl());
viewHolder.paysA.setText(match.getTeamA().getName());
viewHolder.paysB.setText(match.getTeamB().getName());
if (match.getCategory().equals("SH")) {
int num = match.getId() % 7;
viewHolder.categorie.setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
......
......@@ -153,7 +153,7 @@ public class AutomateDouble implements Automate {
@Override
public Point switchSide() {
Stats stat=null;
Stats stat = null;
Score score1 = null;
InfoScore infoScore;
Point point = null;
......@@ -163,18 +163,18 @@ public class AutomateDouble implements Automate {
DoublePoint.score.setSideLeftA(!DoublePoint.score.isSideLeftA());
/* Modifier l'état dans le fichier et la pile */
step = pile.get(pile.size() -1);
step = pile.get(pile.size() - 1);
infoScore = step.getInfoScore().copy();
if(step.getStats()!=null) {
if (step.getStats() != null) {
stat = step.getStats().copy();
}
infoScore.setSideLeftA(!infoScore.isSideLeftA());
step = new Step(infoScore,stat);
step = new Step(infoScore, stat);
pile.setElementAt(step, pile.size()-1);
pile.setElementAt(step, pile.size() - 1);
point = new Point(infoScore.getScore(),stat);
point = new Point(infoScore.getScore(), stat);
FileManager.deleteLast(context);
FileManager.point(context, point);
......@@ -184,7 +184,7 @@ public class AutomateDouble implements Automate {
@Override
public Point switchService() {
Stats stat=null;
Stats stat = null;
Score score1 = null;
InfoScore infoScore;
Point point = null;
......@@ -194,19 +194,19 @@ public class AutomateDouble implements Automate {
DoublePoint.score.setService((DoublePoint.score.getService() + 1) % 2);
/* Modifier l'état dans le fichier et la pile */
step = pile.get(pile.size() -1);
step = pile.get(pile.size() - 1);
infoScore = step.getInfoScore().copy();
if(step.getStats()!=null) {
if (step.getStats() != null) {
stat = step.getStats().copy();
}
infoScore.setService((infoScore.getService() + 1) % 2);
step = new Step(infoScore,stat);
step = new Step(infoScore, stat);
pile.setElementAt(step, pile.size()-1);
pile.setElementAt(step, pile.size() - 1);
point = new Point(infoScore.getScore(),stat);
point = new Point(infoScore.getScore(), stat);
FileManager.deleteLast(context);
FileManager.point(context, point);
......
......@@ -61,8 +61,8 @@ public class Stats {
this.breakPoint = breakPoint;
}
public Stats copy(){
return new Stats(this.type,this.fsf,this.winner);
public Stats copy() {
return new Stats(this.type, this.fsf, this.winner);
}
public String getBackupString() {
......
......@@ -10,10 +10,13 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.koushikdutta.ion.Ion;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.model.TeamInfo;
import fr.istic.masteru.android.utils.Constants;
import fr.istic.masteru.android.utils.Utils;
......@@ -81,10 +84,12 @@ public class ResultFragment extends Fragment {
}
categorieTV.setText(Utils.getCategorieName(match.getCategory()));
tableauTV.setText(Utils.getTableauName(match.getTableau()));
flagA.setImageResource(Utils.getCountryFlag(match.getTeamA()));
flagB.setImageResource(Utils.getCountryFlag(match.getTeamB()));
countryATV.setText(Utils.getCountryName(match.getTeamA()));
countryBTV.setText(Utils.getCountryName(match.getTeamB()));
Ion.with(flagA)
.load(match.getTeamA().getFlagUrl());
Ion.with(flagB)
.load(match.getTeamB().getFlagUrl());
countryATV.setText(match.getTeamA().getName());
countryBTV.setText(match.getTeamB().getName());
}
}
......@@ -129,11 +134,11 @@ public class ResultFragment extends Fragment {
playerB2TV.setText(playerB2.getName());
}
public void setFirstService(String country) {
if (country == null) {
public void setFirstService(TeamInfo teamInfo) {
if (teamInfo == null) {
firstService.setText(null);
} else {
firstService.setText("First service: " + getString(Utils.getCountryName(country)));
firstService.setText("First service: " + teamInfo.getName());
}
}
......
......@@ -12,7 +12,6 @@ import android.widget.Button;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.utils.Utils;
public class SelectFirstServiceFragment extends SetupFragment {
......@@ -50,8 +49,8 @@ public class SelectFirstServiceFragment extends SetupFragment {
});
final Button countryAButton = (Button) root.findViewById(R.id.countryA);
final Button countryBButton = (Button) root.findViewById(R.id.countryB);
countryAButton.setText(Utils.getCountryName(match.getTeamA()));
countryBButton.setText(Utils.getCountryName(match.getTeamB()));
countryAButton.setText(match.getTeamA().getName());
countryBButton.setText(match.getTeamB().getName());
countryAButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -13,7 +13,6 @@ import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.utils.Constants;
import fr.istic.masteru.android.utils.Utils;
public class SelectInitialSideFragment extends SetupFragment {
......@@ -55,8 +54,8 @@ public class SelectInitialSideFragment extends SetupFragment {
matchSetupActivity.next();
}
});
countryAButton.setText(Utils.getCountryName(match.getTeamA()));
countryBButton.setText(Utils.getCountryName(match.getTeamB()));
countryAButton.setText(match.getTeamA().getName());
countryBButton.setText(match.getTeamB().getName());
countryAButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -16,17 +16,15 @@ import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.adapters.MatchAdapter;
import fr.istic.masteru.android.listeners.OnMatchSelectedListener;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.model.TeamInfo;
import fr.istic.masteru.android.utils.API_URLS;
public class SelectMatchFragment extends SetupFragment implements OnMatchSelectedListener {
......@@ -70,10 +68,6 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
}
private void loadMatches() {
SimpleDateFormat sdf = new SimpleDateFormat("EEEE", Locale.ENGLISH);
Date d = new Date();
String dayOfTheWeek = sdf.format(d);
Ion.with(matchSetupActivity)
.load("GET", API_URLS.MATCHS + "?round=CURRENT")
.setTimeout(1000 * 10)
......@@ -96,8 +90,11 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
if (!status.equals("SOON")) // Display only the matches which can be played
continue;
int idMatch = o.get("IdMatch").getAsInt();
String teamA = o.get("Team_A").getAsString();
String teamB = o.get("Team_B").getAsString();
String isoA = o.get("Team_A").getAsString();
String isoB = o.get("Team_B").getAsString();
// todo get flag and full team names
TeamInfo teamA = new TeamInfo(isoA, isoA, null);
TeamInfo teamB = new TeamInfo(isoB, isoB, null);
JsonElement playerAElement = o.get("Name_Complet_A");
String playerA = playerAElement.isJsonNull() ? null : playerAElement.getAsString();
JsonElement playerBElement = o.get("Name_Complet_B");
......
......@@ -27,7 +27,6 @@ import fr.istic.masteru.android.listeners.OnPlayerSelectedListener;
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.Utils;
public class SelectPlayersFragment extends SetupFragment {
......@@ -74,8 +73,8 @@ public class SelectPlayersFragment extends SetupFragment {
}
});
((TextView) root.findViewById(R.id.countryA)).setText(Utils.getCountryName(match.getTeamA()));
((TextView) root.findViewById(R.id.countryB)).setText(Utils.getCountryName(match.getTeamB()));
((TextView) root.findViewById(R.id.countryA)).setText(match.getTeamA().getName());
((TextView) root.findViewById(R.id.countryB)).setText(match.getTeamB().getName());
ListView playerAList = (ListView) root.findViewById(R.id.playerAListView);
ListView playerBList = (ListView) root.findViewById(R.id.playerBListView);
......@@ -132,7 +131,7 @@ public class SelectPlayersFragment extends SetupFragment {
}
private void loadPlayers(final int team) {
final String countryCode = team == TEAM_A ? match.getTeamA() : match.getTeamB();
final String countryCode = team == TEAM_A ? match.getTeamA().getISO() : match.getTeamB().getISO();
String gender = match.getCategory().contains("M") ? "M" : match.getCategory().contains("W") ? "W" : "X";
String url = API_URLS.TEAM_PLAYERS(countryCode, gender);
......
......@@ -12,7 +12,7 @@ import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.utils.Constants;
public class RefereeingTypeFragment extends SetupFragment {
public class SelectRefereeingTypeFragment extends SetupFragment {
MatchSetupActivity matchSetupActivity;
private int lightGrey;
......
package fr.istic.masteru.android.listeners;
import fr.istic.masteru.android.model.TeamInfo;