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
compositeDisposable.add(RxRecyclerView.scrollEvents(nowPlayingBinding.recyclerView) | |
.subscribe(recyclerViewScrollEvent -> { | |
//Send Information To View Model | |
if (scrollEventCalculator.isAtScrollEnd()) { | |
nowPlayingViewModel.loadMoreNowPlayingInfo(); | |
} | |
} | |
})); |
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
nowPlayingViewModel.getAdapterDataPublishSubject() | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(adapterUiCommand -> { | |
//Update UI (Adapter Only)... | |
}; |
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
compositeDisposable.add(loadMorePublishSubject | |
.debounce(LoadMoreCommand -> { | |
//Do Work... | |
}) | |
.doOnNext(loadMoreCommand -> { | |
//Update UI... | |
loadMoreEnabledBehaviorSubject.onNext(false); | |
}) | |
.observeOn(Schedulers.computation()) | |
.flatMap(loadMoreCommand -> { |
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
compositeDisposable.add(RxRecyclerView.scrollEvents(nowPlayingBinding.recyclerView) | |
.flatMap(recyclerViewScrollEvent -> { | |
if (scrollEventCalculator.isAtScrollEnd()) { | |
return Observable.just(new ScrollEvent(pageNumber + 1)); | |
} else { | |
return Observable.empty(); | |
} | |
}) | |
.debounce(scrollEvent -> Observable.<ScrollEvent>empty().delay(250, TimeUnit.MILLISECONDS)) | |
.subscribe(scrollEvent -> nowPlayingViewModel.processUiEvent(scrollEvent), throwable -> { |
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
uiModelObservable = publishRelayUiEvents | |
.observeOn(Schedulers.computation()) | |
//Translate UiEvents into Actions | |
.compose(transformEventsIntoActions) | |
//Asynchronous Actions To Interactor | |
.publish(actionObservable -> nowPlayingInteractor.processAction(actionObservable)) | |
//Scan Results to Update UiModel | |
.scan(initialUiModel, (uiModel, result) -> { | |
if (result instanceof ScrollResult) { | |
return processScrollResult(uiModel, (ScrollResult) result); |
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
public Observable<Result> processAction(Observable<Action> actions) { | |
return actions.compose(transformActionIntoResults); | |
} | |
transformActionIntoResults = upstream -> upstream.publish(new Function<Observable<Action>, ObservableSource<Result>>() { | |
@Override | |
public ObservableSource<Result> apply(Observable<Action> actionObservable) throws Exception { | |
return Observable.merge( | |
actionObservable.ofType(ScrollAction.class).compose(transformScrollActionToScrollResult), | |
actionObservable.ofType(***Action.class).compose(transform***ActionToRestoreResult) |
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
compositeDisposable.add(nowPlayingViewModel.getUiModels() | |
.subscribe(this::processUiModel, | |
throwable -> { throw new UnsupportedOperationException("Errors from Model Unsupported: ");} | |
) | |
); | |
private void processUiModel(UiModel uiModel) { | |
this.latestUiModel = uiModel; | |
//Update progressBar... |
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
@Test | |
public void initState() { | |
//Arrange | |
TestObserver<UiModel> testObserver; | |
TestNowPlayingViewModel nowPlayingViewModel = new TestNowPlayingViewModel(***); | |
nowPlayingViewModel.init(null); | |
when(mockTestTransformer.transform(any(Action.class))).thenReturn(Observable.<Result>empty()); | |
//Act | |
testObserver = nowPlayingViewModel.getUiModels().test(); |
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
//Save | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.putParcelable(LAST_UIMODEL, latestUiModel); | |
} | |
//Init ViewModel with saved state | |
public void init(@Nullable UiModel restoredUiModel) { | |
if (initialUiModel == null) { |