From 1178de1c1c8cdb14c75ad75ac6946ea46360be6e Mon Sep 17 00:00:00 2001 From: Nathan Meade Date: Mon, 16 Jan 2023 13:08:31 -0500 Subject: [PATCH] Revert "this is replaced with viewLifecycleOwner" --- .../guesstheword/screens/game/GameFragment.kt | 4 ++-- .../screens/game/GameViewModel.kt | 24 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/example/android/guesstheword/screens/game/GameFragment.kt b/app/src/main/java/com/example/android/guesstheword/screens/game/GameFragment.kt index 1fdbda7b3..ad4d0fdcc 100644 --- a/app/src/main/java/com/example/android/guesstheword/screens/game/GameFragment.kt +++ b/app/src/main/java/com/example/android/guesstheword/screens/game/GameFragment.kt @@ -59,11 +59,11 @@ class GameFragment : Fragment() { } /** Setting up LiveData observation relationship **/ - viewModel.word.observe(viewLifecycleOwner, Observer { newWord -> + viewModel.word.observe(this, Observer { newWord -> binding.wordText.text = newWord }) - viewModel.score.observe(viewLifecycleOwner, Observer { newScore -> + viewModel.score.observe(this, Observer { newScore -> binding.scoreText.text = newScore.toString() }) diff --git a/app/src/main/java/com/example/android/guesstheword/screens/game/GameViewModel.kt b/app/src/main/java/com/example/android/guesstheword/screens/game/GameViewModel.kt index 91b38879b..2eb08dcaa 100644 --- a/app/src/main/java/com/example/android/guesstheword/screens/game/GameViewModel.kt +++ b/app/src/main/java/com/example/android/guesstheword/screens/game/GameViewModel.kt @@ -16,7 +16,6 @@ package com.example.android.guesstheword.screens.game -import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -26,32 +25,27 @@ import androidx.lifecycle.ViewModel */ class GameViewModel : ViewModel() { - // DONE (01) Make an internal and external version of the word and score + // TODO (01) Make an internal and external version of the word and score // The internal version should be a MutableLiveData, have an underscore in front of its' name // and be private // The external version should be a LiveData - // DONE (02) Make a backing property for the external version that returns the internal + // TODO (02) Make a backing property for the external version that returns the internal // MutableLiveData as a LiveData // The current word - private val _word = MutableLiveData() - val word: LiveData - get() = _word - + val word = MutableLiveData() // The current score - private val _score = MutableLiveData() - val score: LiveData - get() = _score + val score = MutableLiveData() // The list of words - the front of the list is the next word to guess private lateinit var wordList: MutableList - // DONE (03) Use the internal version (the MutableLiveData) of _score and _word in this class + // TODO (03) Use the internal version (the MutableLiveData) of _score and _word in this class init { resetList() nextWord() - _score.value = 0 + score.value = 0 } /** @@ -92,19 +86,19 @@ class GameViewModel : ViewModel() { if (wordList.isEmpty()) { // gameFinished() should happen here } else { - _word.value = wordList.removeAt(0) + word.value = wordList.removeAt(0) } } /** Methods for buttons presses **/ fun onSkip() { - _score.value = (score.value)?.minus(1) + score.value = (score.value)?.minus(1) nextWord() } fun onCorrect() { - _score.value = (score.value)?.plus(1) + score.value = (score.value)?.plus(1) nextWord() } }