From 1cfba81a741eb9f4878aa6d0daa7aaa103474a3d Mon Sep 17 00:00:00 2001
From: 62160052 <62160052@go.buu.ac.th>
Date: Sat, 24 Sep 2022 20:03:23 +0700
Subject: [PATCH] Update the view model

---
 .../android/marsphotos/overview/OverviewViewModel.kt     | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/app/src/main/java/com/example/android/marsphotos/overview/OverviewViewModel.kt b/app/src/main/java/com/example/android/marsphotos/overview/OverviewViewModel.kt
index 6050dd5..2449cdf 100644
--- a/app/src/main/java/com/example/android/marsphotos/overview/OverviewViewModel.kt
+++ b/app/src/main/java/com/example/android/marsphotos/overview/OverviewViewModel.kt
@@ -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}"
             }
-- 
GitLab