Skip to content

Instantly share code, notes, and snippets.

@Abhityagi16
Last active October 21, 2018 10:11
Show Gist options
  • Save Abhityagi16/379924ab8babb8ae2cb5d4e742ce1722 to your computer and use it in GitHub Desktop.
Save Abhityagi16/379924ab8babb8ae2cb5d4e742ce1722 to your computer and use it in GitHub Desktop.
class PostListViewModel(
val useCaseHandler: UseCaseHandler,
val getposts: GetPosts,
val savePost: SavePost): ViewModel() {
fun getAllPosts(userId: Int, callback: PostDataSource.LoadPostsCallback) {
val requestValue = GetPosts.RequestValues(userId)
useCaseHandler.execute(getposts, requestValue, object : UseCase.UseCaseCallback<GetPosts.ResponseValue> {
override fun onSuccess(response: GetPosts.ResponseValue) {
callback.onPostsLoaded(response.posts)
}
override fun onError(t: Throwable) {
callback.onError(t)
}
})
}
fun savePost(post: Post, callback: PostDataSource.SaveTaskCallback) {
val requestValues = SavePost.RequestValues(post)
useCaseHandler.execute(savePost, requestValues, object : UseCase.UseCaseCallback<SavePost.ResponseValue> {
override fun onSuccess(response: SavePost.ResponseValue) {
callback.onSaveSuccess()
}
override fun onError(t: Throwable) {
callback.onError(t)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment