Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 46343bcb authored by 62160052's avatar 62160052
Browse files

Use binding expressions

parent d7e4dec6
No related branches found
No related tags found
No related merge requests found
...@@ -68,21 +68,6 @@ class GameFragment : Fragment() { ...@@ -68,21 +68,6 @@ class GameFragment : Fragment() {
// Setup a click listener for the Submit and Skip buttons. // Setup a click listener for the Submit and Skip buttons.
binding.submit.setOnClickListener { onSubmitWord() } binding.submit.setOnClickListener { onSubmitWord() }
binding.skip.setOnClickListener { onSkipWord() } binding.skip.setOnClickListener { onSkipWord() }
// Update the UI
// Observe the scrambledCharArray LiveData, passing in the LifecycleOwner and the observer.
viewModel.currentScrambledWord.observe(viewLifecycleOwner) {
newWord -> binding.textViewUnscrambledWord.text = newWord
}
viewModel.currentWordCount.observe(viewLifecycleOwner
) { newWordCount ->
binding.wordCount.text =
getString(R.string.word_count, newWordCount, MAX_NO_OF_WORDS)
}
viewModel.score.observe(viewLifecycleOwner
) { newScore ->
binding.score.text = getString(R.string.score, newScore)
}
// Specify the fragment view as the lifecycle owner of the binding. // Specify the fragment view as the lifecycle owner of the binding.
// This is used so that the binding can observe LiveData updates // This is used so that the binding can observe LiveData updates
binding.lifecycleOwner = viewLifecycleOwner binding.lifecycleOwner = viewLifecycleOwner
......
...@@ -81,13 +81,15 @@ ...@@ -81,13 +81,15 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/word_count" app:layout_constraintTop_toBottomOf="@+id/word_count"
android:text="@{gameViewModel.currentScrambledWord}"
tools:text="Scramble word" /> tools:text="Scramble word" />
<TextView <TextView
android:id="@+id/word_count" android:id="@+id/word_count"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/word_count" android:text="@{@string/word_count(gameViewModel.currentWordCount, maxNoOfWords)}"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintBottom_toTopOf="@+id/textView_unscrambled_word" app:layout_constraintBottom_toTopOf="@+id/textView_unscrambled_word"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -98,7 +100,7 @@ ...@@ -98,7 +100,7 @@
android:id="@+id/score" android:id="@+id/score"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/score" android:text="@{@string/score(gameViewModel.score)}"
android:textAllCaps="true" android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment