mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 17:45:21 +01:00
Add reset stats functionality to stats screen with confirmation dialog
This commit is contained in:
parent
0f1404d969
commit
ee2bb0883a
4 changed files with 49 additions and 0 deletions
|
@ -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())
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue