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 ...@@ -28,8 +28,8 @@ import kotlinx.coroutines.launch
* The [ViewModel] that is attached to the [OverviewFragment]. * The [ViewModel] that is attached to the [OverviewFragment].
*/ */
class OverviewViewModel : ViewModel() { class OverviewViewModel : ViewModel() {
private val _photos = MutableLiveData<MarsPhoto>() private val _photos = MutableLiveData<List<MarsPhoto>>()
val photos: LiveData<MarsPhoto> = _photos val photos: LiveData<List<MarsPhoto>> = _photos
// The internal MutableLiveData that stores the status of the most recent request // The internal MutableLiveData that stores the status of the most recent request
private val _status = MutableLiveData<String>() private val _status = MutableLiveData<String>()
...@@ -50,9 +50,8 @@ class OverviewViewModel : ViewModel() { ...@@ -50,9 +50,8 @@ class OverviewViewModel : ViewModel() {
private fun getMarsPhotos() { private fun getMarsPhotos() {
viewModelScope.launch { viewModelScope.launch {
try { try {
_photos.value = MarsApi.retrofitService.getPhotos()[0] _photos.value = MarsApi.retrofitService.getPhotos()
val listResult = MarsApi.retrofitService.getPhotos() _status.value = "Success: Mars properties retrieved"
_status.value = " First Mars image URL : ${_photos.value!!.imgSrcUrl}"
} catch (e: Exception) { } catch (e: Exception) {
_status.value = "Failure: ${e.message}" _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