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
| // Use concat and repeat to renew the session repeatedly | |
| Observable<Session> getRenewedSession() { | |
| Observable<Session> sessionObservable = | |
| SessionManager.getCurrentSessionObservable() | |
| .filter(new Func1<Session, Boolean>() { | |
| @Override | |
| public Boolean call(Session session) { | |
| return session.isValid(); | |
| } |
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
| service.startupDetails(request) | |
| .doOnNext(new Action1<StartupDetails>() { | |
| @Override | |
| public void call(StartupDetails startupDetails) { | |
| startupStore.putStartupDetails(startupDetails); | |
| } | |
| }) | |
| .onErrorReturn(new Function<Throwable, StartupDetails>() { | |
| @Override |
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
| //Use concat-Map() to maintain order while performing "Auto-Complete Search" | |
| publishSubject | |
| .debounce(300, TimeUnit.MILLISECONDS) | |
| .concatMap(new Function<String, ObservableSource<List<Book>>>() { | |
| @Override | |
| public ObservableSource<List<Book>> apply(String s) throws Exception { | |
| Log.d(TAG, "getting books for " + s); | |
| return dataSource.getBook(s); | |
| } |
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
| //Order is not maintain if we use flatMap() while performing "Auto-Complete Search" | |
| publishSubject | |
| .debounce(300, TimeUnit.MILLISECONDS) | |
| .flatMap(new Function<String, ObservableSource<List<Book>>>() { | |
| @Override | |
| public ObservableSource<List<Book>> apply(String s) throws Exception { | |
| Log.d(TAG, "getting books for " + s); | |
| return dataSource.getBook(s); | |
| } |
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
| pokeSource.getPokemonAbilityStringObservable("12") | |
| .subscribeOn(provider.io()) | |
| .observeOn(provider.ui()) | |
| .subscribe(new Consumer<Pokemon>() { | |
| @Override | |
| public void accept(@NonNull String pokemonAbility) throws Exception { | |
| if (getView() != null) { | |
| getView().setApiText(pokemonAbility); | |
| } |
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
| if (throwable instanceof HttpException) { | |
| if (((HttpException) throwable).code() == | |
| HttpURLConnection.HTTP_NOT_FOUND) { | |
| if (getView() != null) { | |
| getView().showErrorDialog("Lost!"); | |
| } | |
| } else if (((HttpException) throwable).code() == | |
| HttpURLConnection.HTTP_UNAVAILABLE) { | |
| if (getView() != null) { |
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 LocalResponseDispatcher extends QueueDispatcher { | |
| @Override | |
| public MockResponse dispatch(RecordedRequest request) throws InterruptedException { | |
| MockResponse mockResponse = new MockResponse(); | |
| String scenario = getScenario(request); | |
| if (scenario != null) { | |
| try { | |
| mockResponse.setBody(readFile(scenario)); |
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
| @Test | |
| public void testOnSceneAdded() { | |
| reset(mainSceneMock); | |
| MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService); | |
| presenter.onSceneAdded(mainSceneMock, null); | |
| testScheduler.triggerActions(); |
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
| @Test | |
| public void testDemoResponseErrorSocket() { | |
| reset(mainSceneMock); | |
| MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService); | |
| MockResponse response = new MockResponse(); | |
| response.setBody("\"message\":\"Hello\"").throttleBody(1, 2, TimeUnit.SECONDS); |