Commit eaa98372 authored by rakam's avatar rakam
Browse files

getToken when starting

parent 60091ca3
......@@ -85,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.0.8" 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="ion-2.0.5" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.0.8" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.0.5" level="project" />
</component>
</module>
......@@ -19,7 +19,7 @@ import fr.istic.masteru.android.automate.AutomateDouble;
import fr.istic.masteru.android.automate.AutomateDoublePro;
import fr.istic.masteru.android.automate.Score;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.Util;
import fr.istic.masteru.android.utils.Utils;
/**
* Activity pour un match double.
......@@ -108,7 +108,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerLeft1Photo.setImageBitmap(result);
}
......@@ -117,7 +117,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerLeft2Photo.setImageBitmap(result);
}
......@@ -126,7 +126,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerRight1Photo.setImageBitmap(result);
}
......@@ -135,7 +135,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerRight2Photo.setImageBitmap(result);
}
......@@ -171,7 +171,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerRight1Photo.setImageBitmap(result);
}
......@@ -180,7 +180,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerRight2Photo.setImageBitmap(result);
}
......@@ -189,7 +189,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerLeft1Photo.setImageBitmap(result);
}
......@@ -198,7 +198,7 @@ public class DoubleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(DoubleMatchActivity.this);
result = Utils.getPersonBitmap(DoubleMatchActivity.this);
}
playerLeft2Photo.setImageBitmap(result);
}
......
package fr.istic.masteru.android.activities;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
......@@ -9,6 +10,8 @@ import android.view.View;
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.utils.OnFinishCallback;
import fr.istic.masteru.android.utils.Utils;
public class HomeActivity extends Activity {
......@@ -25,6 +28,15 @@ public class HomeActivity extends Activity {
});
findViewById(R.id.resumeMatchButton).setEnabled(false);
//checkForSavedAutomate();
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Authentification...");
dialog.show();
Utils.getToken(this, new OnFinishCallback() {
@Override
public void onFinish(Object object) {
dialog.cancel();
}
});
}
private void checkForSavedAutomate() {
......@@ -109,4 +121,5 @@ public class HomeActivity extends Activity {
}.execute(null, null, null);
}
}
}
......@@ -20,7 +20,7 @@ import fr.istic.masteru.android.automate.SimplePoint;
import fr.istic.masteru.android.listeners.OnSyncFinishListener;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.utils.ScoreSyncManager;
import fr.istic.masteru.android.utils.Util;
import fr.istic.masteru.android.utils.Utils;
import fr.istic.masteru.android.views.MatchScoreView;
import fr.istic.masteru.android.views.SecureDelayButton;
......@@ -64,7 +64,7 @@ public abstract class MatchActivity extends Activity {
serviceRight = (ImageView) findViewById(R.id.serviceRight);
gameTime = (TextView) findViewById(R.id.gameTime);
backButton = (Button) findViewById(R.id.back);
((TextView) findViewById(R.id.categorie)).setText(Util.getCategorieName(match.getCategory()));
((TextView) findViewById(R.id.categorie)).setText(Utils.getCategorieName(match.getCategory()));
findViewById(R.id.optionsButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -33,7 +33,8 @@ 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.Util;
import fr.istic.masteru.android.utils.PrefsUtils;
import fr.istic.masteru.android.utils.Utils;
public class MatchSetupActivity extends Activity implements OnMatchSelectedListener,
OnRefereeingTypeChangeListener, OnFirstServiceChangeListener, OnInitialSideChangeListener,
......@@ -124,9 +125,10 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
private void startMatch(final ProgressDialog dialogToClose) {
final JsonObject param = new JsonObject();
param.addProperty("token", PrefsUtils.getToken(this));
param.addProperty("action", "START");
param.addProperty("court", idCourt);
param.addProperty("startDate", Util.getCurrentDateInMySQLFormat());
param.addProperty("startDate", Utils.getCurrentDateInMySQLFormat());
param.addProperty("service", firstServiceCountryCode.equals(match.getTeamA()) ? 0 : 1);
param.addProperty("playerAEq1Id", playerA1.getId());
param.addProperty("playerAEq2Id", playerB1.getId());
......
......@@ -18,7 +18,7 @@ import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.AutomateSimple;
import fr.istic.masteru.android.automate.Score;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.Util;
import fr.istic.masteru.android.utils.Utils;
public class SingleMatchActivity extends MatchActivity {
......@@ -47,10 +47,10 @@ public class SingleMatchActivity extends MatchActivity {
if (match.getCategory().equals("SH")) {
int num = match.getId() % 7;
((TextView) findViewById(R.id.categorie)).setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
((TextView) findViewById(R.id.categorie)).setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
} else if (match.getCategory().equals("SF")) {
int num = (match.getId() - 2) % 7;
((TextView) findViewById(R.id.categorie)).setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
((TextView) findViewById(R.id.categorie)).setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
}
matchScoreView.setPlayersNames(playerInfoA.getName(), playerInfoB.getName());
}
......@@ -83,7 +83,7 @@ public class SingleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(SingleMatchActivity.this);
result = Utils.getPersonBitmap(SingleMatchActivity.this);
}
playerLeftPhoto.setImageBitmap(result);
}
......@@ -92,7 +92,7 @@ public class SingleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(SingleMatchActivity.this);
result = Utils.getPersonBitmap(SingleMatchActivity.this);
}
playerRightPhoto.setImageBitmap(result);
}
......@@ -128,7 +128,7 @@ public class SingleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(SingleMatchActivity.this);
result = Utils.getPersonBitmap(SingleMatchActivity.this);
}
playerRightPhoto.setImageBitmap(result);
}
......@@ -139,7 +139,7 @@ public class SingleMatchActivity extends MatchActivity {
@Override
public void onCompleted(Exception e, Bitmap result) {
if (result == null) {
result = Util.getPersonBitmap(SingleMatchActivity.this);
result = Utils.getPersonBitmap(SingleMatchActivity.this);
}
playerLeftPhoto.setImageBitmap(result);
}
......
......@@ -14,7 +14,7 @@ import java.util.List;
import fr.istic.masteru.android.R;
import fr.istic.masteru.android.listeners.OnMatchSelectedListener;
import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.utils.Util;
import fr.istic.masteru.android.utils.Utils;
public class MatchAdapter extends BaseAdapter {
......@@ -64,20 +64,20 @@ public class MatchAdapter extends BaseAdapter {
}
final Match match = matches.get(position);
ViewHolder viewHolder = (ViewHolder) itemView.getTag();
viewHolder.drapeauA.setImageResource(Util.getCountryFlag(match.getTeamA()));
viewHolder.drapeauB.setImageResource(Util.getCountryFlag(match.getTeamB()));
viewHolder.paysA.setText(Util.getCountryName(match.getTeamA()));
viewHolder.paysB.setText(Util.getCountryName(match.getTeamB()));
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()));
if (match.getCategory().equals("SH")) {
int num = match.getId() % 7;
viewHolder.categorie.setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
viewHolder.categorie.setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
} else if (match.getCategory().equals("SF")) {
int num = (match.getId() - 2) % 7;
viewHolder.categorie.setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
viewHolder.categorie.setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
} else {
viewHolder.categorie.setText(Util.getCategorieName(match.getCategory()));
viewHolder.categorie.setText(Utils.getCategorieName(match.getCategory()));
}
viewHolder.tableau.setText(Util.getTableauName(match.getTableau()));
viewHolder.tableau.setText(Utils.getTableauName(match.getTableau()));
final View finalItemView = itemView;
if (position == selectedItem)
finalItemView.setBackgroundColor(Color.RED);
......
......@@ -12,7 +12,7 @@ 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.Util;
import fr.istic.masteru.android.utils.Utils;
public class FirstServiceFragment extends SetupFragment {
......@@ -50,8 +50,8 @@ public class FirstServiceFragment extends SetupFragment {
});
final Button countryAButton = (Button) root.findViewById(R.id.countryA);
final Button countryBButton = (Button) root.findViewById(R.id.countryB);
countryAButton.setText(Util.getCountryName(match.getTeamA()));
countryBButton.setText(Util.getCountryName(match.getTeamB()));
countryAButton.setText(Utils.getCountryName(match.getTeamA()));
countryBButton.setText(Utils.getCountryName(match.getTeamB()));
countryAButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -13,7 +13,7 @@ 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.Util;
import fr.istic.masteru.android.utils.Utils;
public class InitialSideFragment extends SetupFragment {
......@@ -55,8 +55,8 @@ public class InitialSideFragment extends SetupFragment {
matchSetupActivity.next();
}
});
countryAButton.setText(Util.getCountryName(match.getTeamA()));
countryBButton.setText(Util.getCountryName(match.getTeamB()));
countryAButton.setText(Utils.getCountryName(match.getTeamA()));
countryBButton.setText(Utils.getCountryName(match.getTeamB()));
countryAButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -15,7 +15,7 @@ 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.utils.Constants;
import fr.istic.masteru.android.utils.Util;
import fr.istic.masteru.android.utils.Utils;
public class ResultFragment extends Fragment {
......@@ -72,31 +72,31 @@ public class ResultFragment extends Fragment {
} else {
if (match.getCategory().equals("SH")) {
int num = match.getId() % 7;
categorieTV.setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
categorieTV.setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
} else if (match.getCategory().equals("SF")) {
int num = (match.getId() - 2) % 7;
categorieTV.setText(Util.getCategorieName(match.getCategory()) + " n°" + num);
categorieTV.setText(Utils.getCategorieName(match.getCategory()) + " n°" + num);
} else {
categorieTV.setText(Util.getCategorieName(match.getCategory()));
categorieTV.setText(Utils.getCategorieName(match.getCategory()));
}
categorieTV.setText(Util.getCategorieName(match.getCategory()));
tableauTV.setText(Util.getTableauName(match.getTableau()));
flagA.setImageResource(Util.getCountryFlag(match.getTeamA()));
flagB.setImageResource(Util.getCountryFlag(match.getTeamB()));
countryATV.setText(Util.getCountryName(match.getTeamA()));
countryBTV.setText(Util.getCountryName(match.getTeamB()));
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()));
}
}
public void setCategorie(String categorie) {
categorieTV.setText(Util.getCategorieName(categorie));
categorieTV.setText(Utils.getCategorieName(categorie));
}
public void setRefereeingType(int type) {
if (type == 0) {
refereeingTypeTV.setVisibility(View.GONE);
} else {
refereeingTypeTV.setText(Util.getRefereeingTypeName(type));
refereeingTypeTV.setText(Utils.getRefereeingTypeName(type));
refereeingTypeTV.setVisibility(View.VISIBLE);
}
}
......@@ -133,7 +133,7 @@ public class ResultFragment extends Fragment {
if (country == null) {
firstService.setText(null);
} else {
firstService.setText("First service: " + getString(Util.getCountryName(country)));
firstService.setText("First service: " + getString(Utils.getCountryName(country)));
}
}
......
......@@ -27,7 +27,7 @@ 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.Util;
import fr.istic.masteru.android.utils.Utils;
public class SelectPlayersFragment extends SetupFragment {
......@@ -74,8 +74,8 @@ public class SelectPlayersFragment extends SetupFragment {
}
});
((TextView) root.findViewById(R.id.countryA)).setText(Util.getCountryName(match.getTeamA()));
((TextView) root.findViewById(R.id.countryB)).setText(Util.getCountryName(match.getTeamB()));
((TextView) root.findViewById(R.id.countryA)).setText(Utils.getCountryName(match.getTeamA()));
((TextView) root.findViewById(R.id.countryB)).setText(Utils.getCountryName(match.getTeamB()));
ListView playerAList = (ListView) root.findViewById(R.id.playerAListView);
ListView playerBList = (ListView) root.findViewById(R.id.playerBListView);
......
......@@ -9,6 +9,7 @@ public class API_URLS {
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";
public static String TEAM_PLAYERS(String teamId, String gender) {
return BASE_URL + "/teams/" + teamId + "/players?gender=" + (gender == null ? "X" : gender);
......
......@@ -2,6 +2,8 @@ package fr.istic.masteru.android.utils;
public class Constants {
public static final String TAG = "AceCreamTag";
public static final int SIMPLE = 0;
public static final int DOUBLE_CLASSIC = 1;
public static final int DOUBLE_PRO = 2;
......
package fr.istic.masteru.android.utils;
public interface OnFinishCallback {
public void onFinish(Object object);
}
package fr.istic.masteru.android.utils;
import android.content.Context;
public class PrefsUtils {
private static final String PREFS_NAME = "AceCreamPrefs";
private static final String TOKEN = "TOKEN";
public static void setToken(Context context, String token) {
context.getSharedPreferences(PREFS_NAME, 0).edit().putString(TOKEN, token).commit();
}
public static String getToken(Context context) {
return context.getSharedPreferences(PREFS_NAME, 0).getString(TOKEN, null);
}
}
......@@ -313,7 +313,7 @@ public class ScoreSyncManager {
JsonObject param = new JsonObject();
param.addProperty("action", winnerToSync.isAbandon() ? "ABANDON" : "END");
param.addProperty("winner", winnerToSync.getWinner());
param.addProperty("endDate", Util.getCurrentDateInMySQLFormat());
param.addProperty("endDate", Utils.getCurrentDateInMySQLFormat());
Ion.with(context)
.load("PUT", API_URLS.UPDATE_MATCH(idMatch))
......
......@@ -3,13 +3,19 @@ package fr.istic.masteru.android.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.util.Log;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import java.text.SimpleDateFormat;
import java.util.Date;
import fr.istic.masteru.android.R;
public class Util {
public class Utils {
private static Bitmap person;
......@@ -104,4 +110,55 @@ public class Util {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date());
}
public static void getToken(final Context context, final OnFinishCallback callback) {
JsonObject params = new JsonObject();
params.addProperty("login", "perceval");
params.addProperty("password", "faux");
Ion.with(context)
.load("POST", API_URLS.LOGIN)
.setTimeout(5000)
.setJsonObjectBody(params)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (result != null && result.has("code")) {
int code = result.getAsJsonPrimitive("code").getAsInt();
switch (code) {
case 0:
Log.d(Constants.TAG, "getToken: TOKEN OK");
String token = result.getAsJsonPrimitive("token").getAsString();
PrefsUtils.setToken(context, token);
callback.onFinish(null);
break;
default:
Log.d(Constants.TAG, "getToken: " + code);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
getToken(context, callback);
}
}, 1000);
break;
}
} else {
if (e != null)
Log.d(Constants.TAG, "getToken", e);
else
Log.d(Constants.TAG, "getToken: error");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
getToken(context, callback);
}
}, 1000);
}
}
});
}
}
......@@ -17,17 +17,19 @@
<ImageView
android:id="@+id/playerLeft1Photo"
android:layout_width="71dp"
android:layout_height="78dp"
android:layout_width="82dp"
android:layout_height="90dp"
android:layout_margin="8dp"
android:src="@drawable/person"
android:scaleType="centerCrop"/>
<ImageView
android:id="@+id/playerLeft2Photo"
android:layout_width="71dp"
android:layout_height="78dp"
android:layout_width="82dp"
android:layout_height="90dp"
android:layout_margin="8dp"
android:src="@drawable/person"
android:layout_toRightOf="@id/playerLeft1Photo"
android:scaleType="centerCrop"/>
......@@ -59,26 +61,13 @@
android:layout_toRightOf="@id/playerLeft2Photo"
android:text="(SU)"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/pointLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/playerLeft1Photo"
android:layout_marginTop="10dp"
android:background="@drawable/left_button"
android:paddingBottom="20dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:paddingTop="20dp"
android:text="Point"
android:textColor="#ddd"/>
<ImageView
android:id="@+id/playerRight1Photo"
android:layout_width="82dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:src="@drawable/person"
android:scaleType="centerCrop"/>
<ImageView
......@@ -86,6 +75,7 @@