Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MovieHunt blog part4. detail view model
class MovieDetailViewModel : BaseViewModel() {
private val movieRepo: MovieRepo by inject()
private val _movieDetail = MutableLiveData<MovieModel>()
val posterUrl: LiveData<String> = Transformations.map(_movieDetail) { it.getPosterUrl() }
val title: LiveData<String> = Transformations.map(_movieDetail) { it.displayTitle() }
val rating: LiveData<Float> = Transformations.map(_movieDetail) { it.display5StarsRating() }
val voteCount: LiveData<String> = Transformations.map(_movieDetail) { it.displayVoteCount() }
val duration: LiveData<String> = Transformations.map(_movieDetail) { it.displayDuration() }
val releaseDate: LiveData<String> = Transformations.map(_movieDetail) { it.displayReleaseDate() }
fun fetchMovieDetail(id: String) {
movieRepo.fetchMovieDetail(id)
.subscribeOn(Schedulers.io())
.doOnSuccess { _movieDetail.postValue(it) }
.subscribe()
.disposeOnCleared()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.