Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 44d0a07e authored by 62160052's avatar 62160052
Browse files

Test Unscramble app with Talkback enabled and Delete unused code

parent 46343bcb
Branches
No related tags found
No related merge requests found
......@@ -55,11 +55,6 @@ class GameFragment : Fragment() {
return binding.root
}
override fun onDetach() {
super.onDetach()
Log.d("GameFragment", "GameFragment destroyed!")
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.gameViewModel = viewModel
......@@ -106,11 +101,6 @@ class GameFragment : Fragment() {
/*
* Gets a random word for the list of words and shuffles the letters in it.
*/
private fun getNextScrambledWord(): String {
val tempWord = allWordsList.random().toCharArray()
tempWord.shuffle()
return String(tempWord)
}
/*
* Re-initializes the data in the ViewModel and updates the views with the new data, to
......
package com.example.android.unscramble.ui.game
import android.text.Spannable
import android.text.SpannableString
import android.text.style.TtsSpan
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
class GameViewModel: ViewModel() {
......@@ -15,8 +19,21 @@ class GameViewModel: ViewModel() {
get() = _currentWordCount
private val _currentScrambledWord = MutableLiveData<String>()
val currentScrambledWord: LiveData<String>
get() = _currentScrambledWord
val currentScrambledWord: LiveData<Spannable> = Transformations.map(_currentScrambledWord) {
if (it == null) {
SpannableString("")
} else {
val scrambledWord = it.toString()
val spannable: Spannable = SpannableString(scrambledWord)
spannable.setSpan(
TtsSpan.VerbatimBuilder(scrambledWord).build(),
0,
scrambledWord.length,
Spannable.SPAN_INCLUSIVE_INCLUSIVE
)
spannable
}
}
private var wordsList: MutableList<String> = mutableListOf()
private lateinit var currentWord: String
......@@ -25,10 +42,6 @@ class GameViewModel: ViewModel() {
getNextWord()
}
override fun onCleared() {
super.onCleared()
Log.d("GameFragment", "GameViewModel destroyed!")
}
private fun getNextWord() {
currentWord = allWordsList.random()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment