Last active
October 21, 2018 10:11
-
-
Save Abhityagi16/379924ab8babb8ae2cb5d4e742ce1722 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 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