Merge pull request #113 from lucasnlm/fix-resume-bug
Fix mine count value on resume game
This commit is contained in:
commit
b2b2758d58
7 changed files with 28 additions and 20 deletions
|
@ -9,8 +9,8 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// versionCode and versionName must be hardcoded to support F-droid
|
// versionCode and versionName must be hardcoded to support F-droid
|
||||||
versionCode 702011
|
versionCode 702021
|
||||||
versionName '7.2.1'
|
versionName '7.2.2'
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|
|
@ -139,7 +139,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
||||||
val mines = area.filter { it.hasMine }
|
val mines = area.filter { it.hasMine }
|
||||||
totalArea = area.count()
|
totalArea = area.count()
|
||||||
totalMines = mines.count()
|
totalMines = mines.count()
|
||||||
rightMines = mines.map { if (it.mark.isFlag()) 1 else 0 }.sum()
|
rightMines = mines.count { it.mark.isFlag() }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -166,13 +166,18 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (status == Status.Running) {
|
val willReset = restartIfNeed()
|
||||||
viewModel.refreshUserPreferences()
|
|
||||||
viewModel.resumeGame()
|
|
||||||
analyticsManager.sentEvent(Analytics.Resume())
|
|
||||||
}
|
|
||||||
|
|
||||||
restartIfNeed()
|
if (!willReset) {
|
||||||
|
if (status == Status.Running) {
|
||||||
|
viewModel.run {
|
||||||
|
refreshUserPreferences()
|
||||||
|
resumeGame()
|
||||||
|
}
|
||||||
|
|
||||||
|
analyticsManager.sentEvent(Analytics.Resume())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -536,9 +541,11 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
||||||
* If user change any accessibility preference, the game will restart the activity to
|
* If user change any accessibility preference, the game will restart the activity to
|
||||||
* apply these changes.
|
* apply these changes.
|
||||||
*/
|
*/
|
||||||
private fun restartIfNeed() {
|
private fun restartIfNeed(): Boolean {
|
||||||
if (usingLargeArea != preferencesRepository.useLargeAreas()) {
|
return (usingLargeArea != preferencesRepository.useLargeAreas()).also {
|
||||||
recreate()
|
if (it) {
|
||||||
|
recreate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// versionCode and versionName must be hardcoded to support F-droid
|
// versionCode and versionName must be hardcoded to support F-droid
|
||||||
versionCode 702011
|
versionCode 702021
|
||||||
versionName '7.2.1'
|
versionName '7.2.2'
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||||
|
|
|
@ -94,6 +94,7 @@ class GameViewModel @ViewModelInject constructor(
|
||||||
difficulty.postValue(save.difficulty)
|
difficulty.postValue(save.difficulty)
|
||||||
levelSetup.postValue(setup)
|
levelSetup.postValue(setup)
|
||||||
refreshAll()
|
refreshAll()
|
||||||
|
refreshMineCount()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
gameController.hasAnyMineExploded() -> eventObserver.postValue(Event.GameOver)
|
gameController.hasAnyMineExploded() -> eventObserver.postValue(Event.GameOver)
|
||||||
|
|
|
@ -6,8 +6,8 @@ android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode 702011 // MMmmPPv
|
versionCode 702021 // MMmmPPv
|
||||||
versionName '7.2.1'
|
versionName '7.2.2'
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
resConfigs 'ar', 'en', 'cs', 'de', 'el', 'es', 'fr', 'ja', 'pt', 'ru', 'tr', 'uk', 'vi', 'zh'
|
resConfigs 'ar', 'en', 'cs', 'de', 'el', 'es', 'fr', 'ja', 'pt', 'ru', 'tr', 'uk', 'vi', 'zh'
|
||||||
|
|
|
@ -6,8 +6,8 @@ android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode 702011 // MMmmPPv
|
versionCode 702021 // MMmmPPv
|
||||||
versionName '7.2.1'
|
versionName '7.2.2'
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
resConfigs 'ar', 'en', 'cs', 'de', 'el', 'es', 'fr', 'ja', 'pt', 'ru', 'tr', 'uk', 'vi', 'zh'
|
resConfigs 'ar', 'en', 'cs', 'de', 'el', 'es', 'fr', 'ja', 'pt', 'ru', 'tr', 'uk', 'vi', 'zh'
|
||||||
|
|
|
@ -9,8 +9,8 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// versionCode and versionName must be hardcoded to support F-droid
|
// versionCode and versionName must be hardcoded to support F-droid
|
||||||
versionCode 702011
|
versionCode 702021
|
||||||
versionName '7.2.1'
|
versionName '7.2.2'
|
||||||
applicationId 'dev.lucasnlm.antimine'
|
applicationId 'dev.lucasnlm.antimine'
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
|
|
Loading…
Reference in a new issue