Commit d2c04260 authored by rakam's avatar rakam
Browse files

gestion des abandons

parent 1fa8d93c
......@@ -65,6 +65,22 @@ public abstract class MatchActivity extends Activity {
gameTime = (TextView) findViewById(R.id.gameTime);
backButton = (Button) findViewById(R.id.back);
((TextView) findViewById(R.id.categorie)).setText(Util.getCategorieName(match.getCategorie()));
findViewById(R.id.optionsButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
String[] options = {"Abandon"};
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
optionsSelected(i);
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.setCancelable(true);
builder.show();
}
});
boolean resumeMatch = getIntent().getBooleanExtra(RESUME_MATCH, false);
if (resumeMatch) {
......@@ -99,6 +115,76 @@ public abstract class MatchActivity extends Activity {
});
}
private void optionsSelected(int i) {
switch (i) {
case 0: // Abandon
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.abandon);
builder.setMessage(R.string.definitive_action);
builder.setNegativeButton(android.R.string.cancel, null);
builder.setPositiveButton(R.string.continuer, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle(R.string.select_winner);
String[] options = {getPlayerName(0), getPlayerName(1)};
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle(R.string.match_ended);
final int winner = i;
String winnerName = getPlayerName(i);
builder.setMessage("Vainqueur: " + winnerName);
builder.setNegativeButton(android.R.string.cancel, null);
builder.setPositiveButton("Confirmer", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
final ProgressDialog dialog = new ProgressDialog(MatchActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Match terminé, Synchronisation en cours...\nVeuillez patienter. ");
dialog.setCancelable(false);
dialog.show();
syncManager.setOnSyncFinishListener(new OnSyncFinishListener() {
@Override
public void onSyncFinish() {
FileManager.deleteFile(MatchActivity.this); // Suppresion de la sauvegarde du match terminé
dialog.cancel();
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle("Synchronisation terminée :)");
builder.setMessage("Retour à l'accueil");
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();
}
});
syncManager.abandon(winner);
}
});
builder.setCancelable(true);
builder.show();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.setCancelable(true);
builder.show();
}
});
builder.setCancelable(true);
builder.show();
break;
default:
break;
}
}
protected void updateUI(final Score score) {
if (score.isSideLeftA() != isPlayerALeft && score.getVainqueur() == -1) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
......@@ -159,7 +245,7 @@ public abstract class MatchActivity extends Activity {
FileManager.deleteFile(MatchActivity.this); // Suppresion de la sauvegarde du match terminé
dialog.cancel();
AlertDialog.Builder builder = new AlertDialog.Builder(MatchActivity.this);
builder.setTitle("Synchronisation terminé :)");
builder.setTitle("Synchronisation terminée :)");
builder.setMessage("Retour à l'accueil");
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
......
......@@ -78,6 +78,14 @@ public class ScoreSyncManager {
}
}
public void abandon(int winner) {
WinnerToSync winnerToSync = new WinnerToSync(winner == 0 ? "A" : "B");
syncQueue.put(scoreIdMax + 0.9f, winnerToSync);
if (!isSyncing()) {
syncNextElement();
}
}
/**
* Sync back to the id (inclusive)
*
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/grey_button" android:state_selected="true" />
<item android:drawable="@color/grey_button" android:state_checked="true" />
<item android:drawable="@color/grey_button" android:state_pressed="true" />
<item android:drawable="@color/light_grey_button" />
</selector>
\ No newline at end of file
......@@ -195,6 +195,19 @@
android:layout_centerHorizontal="true"
android:background="#999" />
<Button
android:id="@+id/optionsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:layout_centerHorizontal="true"
android:background="@drawable/grey_button"
android:paddingBottom="4dp"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="4dp"
android:text="@string/options" />
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
......
......@@ -158,6 +158,19 @@
android:layout_centerHorizontal="true"
android:background="#999" />
<Button
android:id="@+id/optionsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:layout_centerHorizontal="true"
android:background="@drawable/grey_button"
android:paddingBottom="4dp"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="4dp"
android:text="@string/options" />
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="light_grey">#eeeeee</color>
<color name="light_grey">#dddddd</color>
<color name="light_grey_button">#cccccc</color>
<color name="grey_button">#bbbbbb</color>
<color name="white">#fefefe</color>
<color name="dark_grey">#303030</color>
<color name="darker_grey">#222222</color>
......
......@@ -24,5 +24,11 @@
<string name="select_left_team">Selectionnez l\'équipe sur votre gauche</string>
<string name="refereeing_type">Selectionnez la règle utilisée pour ce double</string>
<string name="first_service">Selectionnez le premier serveur</string>
<string name="options">Options</string>
<string name="continuer">Continuer</string>
<string name="definitive_action">Attention, cette action ne pourra pas être annulée, êtes-vous sûr(e) de vouloir continuer?</string>
<string name="abandon">Abandon</string>
<string name="select_winner">Sélectionnez le vainqueur de ce match</string>
<string name="match_ended">Match terminé</string>
</resources>
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