-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ws api to retrieve img of day - connect drawable to view
- Loading branch information
1 parent
5d0fa71
commit c94ab6c
Showing
8 changed files
with
66 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
starter/app/src/main/java/com/udacity/asteroidradar/main/MainRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
package com.udacity.asteroidradar.main | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.udacity.asteroidradar.PictureOfDay | ||
import com.udacity.asteroidradar.api.NeoWsService | ||
|
||
class MainRepository { | ||
|
||
val neoWsService = NeoWsService() | ||
private val _neoWsService = NeoWsService() | ||
private val _pictureOfDay = MutableLiveData<PictureOfDay>() | ||
|
||
suspend fun fetchLatest() { | ||
println("*** fetchLatest") | ||
try { | ||
val list = neoWsService.fetchLast() | ||
println("*** list $list") | ||
} | ||
catch (e : Exception) { | ||
e.printStackTrace() | ||
} | ||
val pictureOfDay : LiveData<PictureOfDay> = _pictureOfDay | ||
|
||
suspend fun updateImageOfDay() { | ||
_pictureOfDay.value = _neoWsService.fetchPictureOfDay() | ||
} | ||
} |
13 changes: 8 additions & 5 deletions
13
starter/app/src/main/java/com/udacity/asteroidradar/main/MainViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
package com.udacity.asteroidradar.main | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.udacity.asteroidradar.PictureOfDay | ||
import kotlinx.coroutines.launch | ||
|
||
class MainViewModel : ViewModel() { | ||
|
||
val repo = MainRepository() | ||
private val repo = MainRepository() | ||
|
||
init { | ||
getLatest() | ||
refreshPictureOfDay() | ||
} | ||
|
||
fun getLatest() { | ||
val pictureOfDay : LiveData<PictureOfDay> = repo.pictureOfDay | ||
|
||
fun refreshPictureOfDay() { | ||
viewModelScope.launch { | ||
try { | ||
repo.fetchLatest() | ||
repo.updateImageOfDay() | ||
} | ||
catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters