Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created April 1, 2019 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/97388f9e38b9731c0d903f9ca10c5047 to your computer and use it in GitHub Desktop.
Save enginebai/97388f9e38b9731c0d903f9ca10c5047 to your computer and use it in GitHub Desktop.
class PostListViewModel : ViewModel() {
private val repo: PostRepository by inject()
fun getNewPostList(): Observable<List<NewPost>> {
return repo.getNewPostList()
}
}
class PostListFragment : Fragment {
private val viewModel by viewModel<PostListViewModel>()
override fun onViewCreated() {
viewModel.getNewPostList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
// update list
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment