diff --git a/app/src/main/java/dev/lucasnlm/antimine/stats/model/StatsModel.kt b/app/src/main/java/dev/lucasnlm/antimine/stats/model/StatsModel.kt index 757edec8..2595170b 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/stats/model/StatsModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/stats/model/StatsModel.kt @@ -6,6 +6,7 @@ data class StatsModel( @StringRes val title: Int, val totalGames: Int, val totalTime: Long, + val victoryTime: Long, val averageTime: Long, val shortestTime: Long, val mines: Int, diff --git a/app/src/main/java/dev/lucasnlm/antimine/stats/viewmodel/StatsViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/stats/viewmodel/StatsViewModel.kt index aa8098e2..0a3eead9 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/stats/viewmodel/StatsViewModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/stats/viewmodel/StatsViewModel.kt @@ -79,6 +79,7 @@ class StatsViewModel( title = 0, totalGames = size, totalTime = 0, + victoryTime = 0, averageTime = 0, shortestTime = 0, mines = 0, @@ -90,7 +91,16 @@ class StatsViewModel( 0, acc.totalGames, acc.totalTime + value.duration, - 0, + victoryTime = if (value.victory != 0){ + if (acc.victoryTime == 0L) { + value.duration + } else { + acc.victoryTime + value.duration + } + } else { + acc.victoryTime + }, + averageTime = 0, shortestTime = if (value.victory != 0) { if (acc.shortestTime == 0L) { value.duration @@ -105,12 +115,13 @@ class StatsViewModel( acc.openArea + value.openArea, ) } - result.copy(averageTime = result.totalTime / result.totalGames) + result.copy(averageTime = result.victoryTime / result.victory) } else { StatsModel( title = 0, totalGames = 0, totalTime = 0, + victoryTime = 0, averageTime = 0, shortestTime = 0, mines = 0,