Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 1cfba81a authored by 62160052's avatar 62160052
Browse files

Update the view model

parent b2cb5f9f
No related branches found
No related tags found
No related merge requests found
......@@ -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}"
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment