Created
May 25, 2018 08:46
-
-
Save abbas-oveissi/941bd5f92b3775551bf6dec124ce657f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class MovieDetailViewModel extends BaseViewModel { | |
LiveData<MovieDetailViewState> baz = new MutableLiveData(); | |
MutableLiveData<Void> retryNetworkRequest = new MutableLiveData(); | |
MovieInteractor movieInteractor; | |
@Inject | |
public MovieDetailViewModel(MovieInteractor movieInteractor) { | |
this.movieInteractor = movieInteractor; | |
} | |
LiveData<MovieDetailViewState> getViewState() { | |
baz = Transformations.switchMap(retryNetworkRequest,(v)->{ | |
return LiveDataReactiveStreams.fromPublisher(movieInteractor.getMovieByID("1") | |
.map((it)->(MovieDetailViewState) new MovieDetailViewState.Data(it)) | |
.onErrorReturnItem(new MovieDetailViewState.Error("")) | |
.startWith(new MovieDetailViewState.Loading())); | |
}); | |
return baz; | |
} | |
void retryNetwork() { | |
retryNetworkRequest.setValue(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.