Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MovieHunt blog part4. list view model
class MovieListViewModel : BaseViewModel() {
private val movieRepo: MovieRepo by inject()
private val movieCategoryEvent = BehaviorSubject.create<MovieCategory>()
private val fetchDataSource: Observable<Listing<MovieModel>> = movieCategoryEvent
.map { movieRepo.fetchMovieList(it) }
val movieList: Observable<PagedList<MovieModel>>
get() = fetchDataSource.flatMap { it.pagedList }
val refreshState: Observable<NetworkState>
get() = fetchDataSource.flatMap{ it.refreshState }
val networkState: Observable<NetworkState>
get() = fetchDataSource.flatMap { it.loadMoreState }
fun fetchMovieList(category: MovieCategory) {
fun refresh() {
.map { it.refresh }
.doOnNext { it.invoke() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment