Add reset stats functionality to stats screen with confirmation dialog

This commit is contained in:
cmclark00 2025-03-27 18:37:22 -04:00
parent 0f1404d969
commit ee2bb0883a
4 changed files with 49 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package com.mintris
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.mintris.databinding.ActivityStatsBinding
import com.mintris.model.StatsManager
@ -25,9 +26,26 @@ class StatsActivity : AppCompatActivity() {
finish()
}
// Set up reset stats button
binding.resetStatsButton.setOnClickListener {
showResetConfirmationDialog()
}
updateStats()
}
private fun showResetConfirmationDialog() {
AlertDialog.Builder(this)
.setTitle("Reset Stats")
.setMessage("Are you sure you want to reset all your stats? This cannot be undone.")
.setPositiveButton("Reset") { _, _ ->
statsManager.resetStats()
updateStats()
}
.setNegativeButton("Cancel", null)
.show()
}
private fun updateStats() {
// Format time duration
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())

View file

@ -157,6 +157,27 @@ class StatsManager(context: Context) {
fun getSessionTriples(): Int = sessionTriples
fun getSessionTetrises(): Int = sessionTetrises
fun resetStats() {
// Reset all lifetime stats
totalGames = 0
totalScore = 0
totalLines = 0
totalPieces = 0
totalTime = 0
maxLevel = 0
maxScore = 0
maxLines = 0
// Reset line clear stats
totalSingles = 0
totalDoubles = 0
totalTriples = 0
totalTetrises = 0
// Save the reset stats
saveStats()
}
companion object {
private const val PREFS_NAME = "mintris_stats"
private const val KEY_TOTAL_GAMES = "total_games"