Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Get Data from Internet
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
Get Data from Internet
Commits
1cfba81a
Commit
1cfba81a
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Update the view model
parent
b2cb5f9f
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/marsphotos/overview/OverviewViewModel.kt
+4
-5
4 additions, 5 deletions
.../example/android/marsphotos/overview/OverviewViewModel.kt
with
4 additions
and
5 deletions
app/src/main/java/com/example/android/marsphotos/overview/OverviewViewModel.kt
+
4
−
5
View file @
1cfba81a
...
...
@@ -28,8 +28,8 @@ import kotlinx.coroutines.launch
* The [ViewModel] that is attached to the [OverviewFragment].
*/
class
OverviewViewModel
:
ViewModel
()
{
private
val
_photos
=
MutableLiveData
<
MarsPhoto
>()
val
photos
:
LiveData
<
MarsPhoto
>
=
_photos
private
val
_photos
=
MutableLiveData
<
List
<
MarsPhoto
>
>
()
val
photos
:
LiveData
<
List
<
MarsPhoto
>
>
=
_photos
// The internal MutableLiveData that stores the status of the most recent request
private
val
_status
=
MutableLiveData
<
String
>()
...
...
@@ -50,9 +50,8 @@ class OverviewViewModel : ViewModel() {
private
fun
getMarsPhotos
()
{
viewModelScope
.
launch
{
try
{
_photos
.
value
=
MarsApi
.
retrofitService
.
getPhotos
()[
0
]
val
listResult
=
MarsApi
.
retrofitService
.
getPhotos
()
_status
.
value
=
" First Mars image URL : ${_photos.value!!.imgSrcUrl}"
_photos
.
value
=
MarsApi
.
retrofitService
.
getPhotos
()
_status
.
value
=
"Success: Mars properties retrieved"
}
catch
(
e
:
Exception
)
{
_status
.
value
=
"Failure: ${e.message}"
}
...
...
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