Feat: Implémentation écran Paramètres (dialogue)
- Création du layout personnalisé 'dialog_settings.xml'. - Ajout des options dans le dialogue : - Son (placeholder désactivé). - Notifications (placeholder désactivé). - Bouton 'Gérer les Permissions' ouvrant les paramètres système de l'app. - Bouton 'Partager mes Statistiques' utilisant l'Intent de partage Android. - Bouton 'Réinitialiser les Statistiques' avec dialogue de confirmation. - Bouton 'Quitter l'Application'. - Bouton 'Fermer'. - Ajout des strings correspondantes. - Implémentation de showSettingsDialog(), shareStats(), showResetStatsConfirmationDialog(), resetStatistics() dans MainActivity. - Ajout de la méthode resetStats() dans GameStats.
This commit is contained in:
parent
b7655a825a
commit
a61f110992
@ -217,6 +217,35 @@ public class GameStats {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise toutes les statistiques (solo, multijoueur, high score global)
|
||||
* à leurs valeurs par défaut.
|
||||
*/
|
||||
public void resetStats() {
|
||||
// Réinitialise toutes les variables membres à 0 ou valeur initiale
|
||||
overallHighScore = 0;
|
||||
totalGamesPlayed = 0;
|
||||
totalGamesStarted = 0;
|
||||
totalMoves = 0;
|
||||
totalPlayTimeMs = 0;
|
||||
totalMerges = 0;
|
||||
highestTile = 0;
|
||||
numberOfTimesObjectiveReached = 0;
|
||||
perfectGames = 0;
|
||||
bestWinningTimeMs = Long.MAX_VALUE;
|
||||
worstWinningTimeMs = 0;
|
||||
|
||||
multiplayerGamesWon = 0;
|
||||
multiplayerGamesPlayed = 0;
|
||||
multiplayerBestWinningStreak = 0;
|
||||
multiplayerTotalScore = 0;
|
||||
multiplayerTotalTimeMs = 0;
|
||||
totalMultiplayerLosses = 0;
|
||||
multiplayerHighestScore = 0;
|
||||
|
||||
saveStats();
|
||||
}
|
||||
|
||||
// --- Getters pour l'affichage ---
|
||||
public int getTotalGamesPlayed() { return totalGamesPlayed; }
|
||||
public int getTotalGamesStarted() { return totalGamesStarted; }
|
||||
|
@ -10,7 +10,8 @@ package legion.muyue.best2048;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface; // Assurez-vous que cet import est présent
|
||||
import android.provider.Settings;
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
@ -475,16 +476,146 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une boîte de dialogue placeholder pour les paramètres.
|
||||
* Affiche la boîte de dialogue des paramètres en utilisant un layout personnalisé.
|
||||
* Gère les interactions avec les différentes options.
|
||||
*/
|
||||
private void showSettingsDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.dialog_settings, null);
|
||||
builder.setView(dialogView);
|
||||
builder.setCancelable(true); // Permet de fermer en cliquant à côté
|
||||
|
||||
// Récupération des vues
|
||||
SwitchMaterial switchSound = dialogView.findViewById(R.id.switchSound);
|
||||
SwitchMaterial switchNotifications = dialogView.findViewById(R.id.switchNotifications);
|
||||
Button permissionsButton = dialogView.findViewById(R.id.buttonManagePermissions);
|
||||
Button shareStatsButton = dialogView.findViewById(R.id.buttonShareStats);
|
||||
Button resetStatsButton = dialogView.findViewById(R.id.buttonResetStats);
|
||||
Button quitAppButton = dialogView.findViewById(R.id.buttonQuitApp);
|
||||
Button closeButton = dialogView.findViewById(R.id.buttonCloseSettings);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
|
||||
// Configuration initiale des switches (désactivés pour l'instant)
|
||||
switchSound.setEnabled(false);
|
||||
switchSound.setChecked(false); // Mettre à jour avec la vraie valeur si implémenté
|
||||
switchSound.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
// TODO: Implémenter la logique Son ON/OFF
|
||||
Toast.makeText(this, "Gestion du son à venir.", Toast.LENGTH_SHORT).show();
|
||||
// switchSound.setChecked(!isChecked); // Revenir en arrière car pas implémenté
|
||||
});
|
||||
|
||||
switchNotifications.setEnabled(false);
|
||||
switchNotifications.setChecked(false); // Mettre à jour avec la vraie valeur si implémenté
|
||||
switchNotifications.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
// TODO: Implémenter la logique Notifications ON/OFF
|
||||
Toast.makeText(this, "Gestion des notifications à venir.", Toast.LENGTH_SHORT).show();
|
||||
// switchNotifications.setChecked(!isChecked);
|
||||
});
|
||||
|
||||
// Listener bouton Permissions
|
||||
permissionsButton.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, "Impossible d'ouvrir les paramètres de l'application.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
dialog.dismiss(); // Ferme les paramètres après clic
|
||||
});
|
||||
|
||||
// Listener bouton Partager Stats
|
||||
shareStatsButton.setOnClickListener(v -> {
|
||||
shareStats();
|
||||
dialog.dismiss(); // Ferme après partage (ou tentative)
|
||||
});
|
||||
|
||||
// Listener bouton Réinitialiser Stats
|
||||
resetStatsButton.setOnClickListener(v -> {
|
||||
dialog.dismiss(); // Ferme d'abord la dialogue des paramètres
|
||||
showResetStatsConfirmationDialog(); // Ouvre la confirmation
|
||||
});
|
||||
|
||||
// Listener bouton Quitter
|
||||
quitAppButton.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
finishAffinity(); // Ferme toutes les activités de l'application
|
||||
});
|
||||
|
||||
// Listener bouton Fermer
|
||||
closeButton.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée et lance une Intent pour partager les statistiques du joueur.
|
||||
*/
|
||||
private void shareStats() {
|
||||
if (gameStats == null) return;
|
||||
|
||||
// Construit le message à partager
|
||||
String shareBody = getString(R.string.share_stats_body,
|
||||
gameStats.getOverallHighScore(),
|
||||
gameStats.getHighestTile(),
|
||||
gameStats.getNumberOfTimesObjectiveReached(),
|
||||
gameStats.getTotalGamesStarted(), // Ou totalGamesPlayed ?
|
||||
GameStats.formatTime(gameStats.getTotalPlayTimeMs()),
|
||||
gameStats.getTotalMoves()
|
||||
);
|
||||
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_stats_subject));
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
|
||||
|
||||
try {
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_stats_title)));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, "Aucune application de partage disponible.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une boîte de dialogue pour confirmer la réinitialisation des statistiques.
|
||||
*/
|
||||
private void showResetStatsConfirmationDialog() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.settings_title)
|
||||
.setMessage(R.string.settings_message) // Message placeholder
|
||||
.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
|
||||
.setTitle(R.string.reset_stats_confirm_title)
|
||||
.setMessage(R.string.reset_stats_confirm_message)
|
||||
.setPositiveButton(R.string.confirm, (dialog, which) -> {
|
||||
resetStatistics(); // Appelle la méthode de réinitialisation
|
||||
dialog.dismiss();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
|
||||
.setIcon(android.R.drawable.ic_dialog_alert) // Icône d'avertissement
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise toutes les statistiques via GameStats et sauvegarde les changements.
|
||||
* Affiche une confirmation à l'utilisateur.
|
||||
*/
|
||||
private void resetStatistics() {
|
||||
if (gameStats != null) {
|
||||
gameStats.resetStats(); // Réinitialise les stats dans l'objet
|
||||
gameStats.saveStats(); // Sauvegarde les stats réinitialisées
|
||||
// Met aussi à jour le highScore de l'objet Game courant (si une partie est en cours)
|
||||
if(game != null){
|
||||
game.setHighestScore(gameStats.getOverallHighScore()); // Le HS est aussi reset dans GameStats
|
||||
updateScores(); // Rafraichit l'affichage du HS si visible
|
||||
}
|
||||
Toast.makeText(this, R.string.stats_reset_confirmation, Toast.LENGTH_SHORT).show();
|
||||
// Si les stats étaient visibles, on pourrait vouloir les rafraîchir
|
||||
if (statisticsVisible && inflatedStatsView != null) {
|
||||
updateStatisticsTextViews();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche la boîte de dialogue "À Propos" en utilisant un layout personnalisé,
|
||||
* incluant des informations sur l'application et un lien cliquable vers le site web.
|
||||
|
89
app/src/main/res/layout/dialog_settings.xml
Normal file
89
app/src/main/res/layout/dialog_settings.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:background="@drawable/dialog_background">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialogTitleSettings"
|
||||
style="@style/SectionTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_title"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switchSound"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_sound_label"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="@font/nunito_family"
|
||||
android:textColor="@color/text_tile_low"
|
||||
android:enabled="false" /> <com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switchNotifications"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/settings_notifications_label"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="@font/nunito_family"
|
||||
android:textColor="@color/text_tile_low"
|
||||
android:enabled="false" /> </LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonManagePermissions"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
|
||||
android:layout_marginTop="4dp" android:layout_marginBottom="4dp"
|
||||
android:text="@string/settings_permissions_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonShareStats"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
|
||||
android:layout_marginTop="4dp" android:layout_marginBottom="4dp"
|
||||
android:text="@string/settings_share_stats_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonResetStats"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
|
||||
android:layout_marginTop="4dp" android:layout_marginBottom="4dp"
|
||||
android:backgroundTint="@android:color/holo_red_dark" android:text="@string/settings_reset_stats_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonQuitApp"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
|
||||
android:layout_marginTop="4dp" android:layout_marginBottom="16dp"
|
||||
android:text="@string/settings_quit_app_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonCloseSettings"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
|
||||
android:layout_marginTop="8dp" android:layout_marginBottom="0dp"
|
||||
android:text="@string/settings_close_button" />
|
||||
|
||||
</LinearLayout>
|
@ -63,5 +63,18 @@
|
||||
<string name="about_website_text">Website : legion-muyue.fr</string> <string name="about_website_url">https://legion-muyue.fr</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="settings_title">Settings</string>
|
||||
<string name="settings_message">Settings screen to be implemented.</string>
|
||||
<string name="settings_sound_label">Sound (coming soon)</string>
|
||||
<string name="settings_notifications_label">Notifications (coming soon)</string>
|
||||
<string name="settings_permissions_button">Manage Permissions</string>
|
||||
<string name="settings_share_stats_button">Share my Statistics</string>
|
||||
<string name="settings_reset_stats_button">Reset Statistics</string>
|
||||
<string name="settings_quit_app_button">Quit Application</string>
|
||||
<string name="settings_close_button">Close</string>
|
||||
<string name="reset_stats_confirm_title">Reset Stats?</string>
|
||||
<string name="reset_stats_confirm_message">Are you sure you want to erase all your saved statistics? This action is irreversible.</string>
|
||||
<string name="share_stats_title">Share my stats via…</string>
|
||||
<string name="share_stats_subject">My 2048 Statistics</string>
|
||||
<string name="share_stats_body">Here are my stats on Best 2048:\n- Best Score: %d\n- Highest Tile: %d\n- Games Won: %d / %d\n- Total Time: %s\n- Total Moves: %d</string>
|
||||
<string name="stats_reset_confirmation">Statistics reset.</string>
|
||||
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user