diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt index ce3c043b..718c1c7b 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt @@ -3,7 +3,6 @@ package dev.lucasnlm.antimine.level.view import android.os.Bundle import android.view.View import androidx.core.view.doOnLayout -import androidx.lifecycle.Observer import androidx.lifecycle.lifecycleScope import dev.lucasnlm.antimine.DeepLink import dev.lucasnlm.antimine.common.R @@ -52,14 +51,14 @@ open class LevelFragment : CommonLevelFragment(R.layout.fragment_level) { gameViewModel.run { field.observe( viewLifecycleOwner, - Observer { + { areaAdapter.bindField(it) } ) levelSetup.observe( viewLifecycleOwner, - Observer { + { getView()?.let { view -> setupRecyclerViewSize(view, it) } @@ -68,7 +67,7 @@ open class LevelFragment : CommonLevelFragment(R.layout.fragment_level) { eventObserver.observe( viewLifecycleOwner, - Observer { + { when (it) { Event.Pause, Event.GameOver, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt index 2c61984f..a3162ad1 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt @@ -496,5 +496,11 @@ class GameViewModel( private fun refreshField() { field.postValue(gameController.field()) + + if (gameController.hasMines()) { + viewModelScope.launch { + saveGame() + } + } } }