Fix save on rotation

This commit is contained in:
Lucas Lima 2020-08-25 23:27:33 -03:00
parent b61717eeb2
commit cb3335e1a9
No known key found for this signature in database
GPG key ID: C5EEF4C30BFBF8D7
2 changed files with 9 additions and 4 deletions

View file

@ -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,

View file

@ -496,5 +496,11 @@ class GameViewModel(
private fun refreshField() {
field.postValue(gameController.field())
if (gameController.hasMines()) {
viewModelScope.launch {
saveGame()
}
}
}
}