mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 09:25: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"
|
||||
|
|
|
@ -143,5 +143,14 @@
|
|||
android:background="@color/transparent"
|
||||
android:layout_marginTop="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/resetStatsButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/reset_stats"
|
||||
android:textColor="@color/white"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginTop="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -44,4 +44,5 @@
|
|||
<string name="doubles">Doubles: %d</string>
|
||||
<string name="triples">Triples: %d</string>
|
||||
<string name="tetrises">Tetrises: %d</string>
|
||||
<string name="reset_stats">Reset Stats</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue