Created
January 23, 2019 23:04
-
-
Save weverb2/d883db61112be78364da97cdd53e0a61 to your computer and use it in GitHub Desktop.
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
class MainViewModel : ViewModel() { | |
val api = NetworkConfiguration.getPlaceholderApi() | |
private val mutablePostData = MutableLiveData<List<Post>>() | |
val postData: LiveData<List<Post>> | |
get() = mutablePostData | |
fun fetchPosts() { | |
api.getPosts().enqueue(object : Callback<List<Post>> { | |
override fun onResponse(call: Call<List<Post>>, response: Response<List<Post>>) { | |
if (response.isSuccessful) { | |
mutablePostData.postValue(response.body()) | |
} else { | |
// Handle Unsuccessful response | |
} | |
} | |
override fun onFailure(call: Call<List<Post>>, t: Throwable) { | |
// Handle error | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment