Fix save on rotation
This commit is contained in:
parent
b61717eeb2
commit
cb3335e1a9
2 changed files with 9 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -496,5 +496,11 @@ class GameViewModel(
|
|||
|
||||
private fun refreshField() {
|
||||
field.postValue(gameController.field())
|
||||
|
||||
if (gameController.hasMines()) {
|
||||
viewModelScope.launch {
|
||||
saveGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue