Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Unscramble
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
Unscramble
Commits
4ca98441
Commit
4ca98441
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Attach observer to the LiveData object
parent
1bec2397
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/example/android/unscramble/ui/game/GameFragment.kt
+8
-9
8 additions, 9 deletions
...va/com/example/android/unscramble/ui/game/GameFragment.kt
with
8 additions
and
9 deletions
app/src/main/java/com/example/android/unscramble/ui/game/GameFragment.kt
+
8
−
9
View file @
4ca98441
...
@@ -66,10 +66,14 @@ class GameFragment : Fragment() {
...
@@ -66,10 +66,14 @@ class GameFragment : Fragment() {
binding
.
submit
.
setOnClickListener
{
onSubmitWord
()
}
binding
.
submit
.
setOnClickListener
{
onSubmitWord
()
}
binding
.
skip
.
setOnClickListener
{
onSkipWord
()
}
binding
.
skip
.
setOnClickListener
{
onSkipWord
()
}
// Update the UI
// Update the UI
updateNextWordOnScreen
()
binding
.
score
.
text
=
getString
(
R
.
string
.
score
,
0
)
binding
.
score
.
text
=
getString
(
R
.
string
.
score
,
0
)
binding
.
wordCount
.
text
=
getString
(
binding
.
wordCount
.
text
=
getString
(
R
.
string
.
word_count
,
0
,
MAX_NO_OF_WORDS
)
R
.
string
.
word_count
,
0
,
MAX_NO_OF_WORDS
)
// Observe the scrambledCharArray LiveData, passing in the LifecycleOwner and the observer.
viewModel
.
currentScrambledWord
.
observe
(
viewLifecycleOwner
)
{
newWord
->
binding
.
textViewUnscrambledWord
.
text
=
newWord
}
}
}
/*
/*
...
@@ -81,9 +85,7 @@ class GameFragment : Fragment() {
...
@@ -81,9 +85,7 @@ class GameFragment : Fragment() {
if
(
viewModel
.
isUserWordCorrect
(
playerWord
))
{
if
(
viewModel
.
isUserWordCorrect
(
playerWord
))
{
setErrorTextField
(
false
)
setErrorTextField
(
false
)
if
(
viewModel
.
nextWord
())
{
if
(!
viewModel
.
nextWord
())
{
updateNextWordOnScreen
()
}
else
{
showFinalScoreDialog
()
showFinalScoreDialog
()
}
}
}
else
{
}
else
{
...
@@ -98,7 +100,7 @@ class GameFragment : Fragment() {
...
@@ -98,7 +100,7 @@ class GameFragment : Fragment() {
private
fun
onSkipWord
()
{
private
fun
onSkipWord
()
{
if
(
viewModel
.
nextWord
())
{
if
(
viewModel
.
nextWord
())
{
setErrorTextField
(
false
)
setErrorTextField
(
false
)
updateNextWordOnScreen
()
}
else
{
}
else
{
showFinalScoreDialog
()
showFinalScoreDialog
()
}
}
...
@@ -120,7 +122,7 @@ class GameFragment : Fragment() {
...
@@ -120,7 +122,7 @@ class GameFragment : Fragment() {
private
fun
restartGame
()
{
private
fun
restartGame
()
{
viewModel
.
reinitializeData
()
viewModel
.
reinitializeData
()
setErrorTextField
(
false
)
setErrorTextField
(
false
)
updateNextWordOnScreen
()
}
}
/*
/*
...
@@ -160,7 +162,4 @@ class GameFragment : Fragment() {
...
@@ -160,7 +162,4 @@ class GameFragment : Fragment() {
/*
/*
* Displays the next scrambled word on screen.
* Displays the next scrambled word on screen.
*/
*/
private
fun
updateNextWordOnScreen
()
{
binding
.
textViewUnscrambledWord
.
text
=
viewModel
.
currentScrambledWord
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment