public HostConfigPresenter(HostConfigView hostConfigView, MediaService mediaService) { this.hostConfigView = hostConfigView; this.mediaService = mediaService; hostConfigView.getServerButtonObservable().subscribe(event -> { if (serverButtonState == START_SERVER) { mediaService.establishConnectionAsHost() .observeOn(JavaFxScheduler.getInstance()) .subscribe(hostConfigView::setServerStatusText); hostConfigView.setServerButtonText("Stop Server"); serverButtonState = STOP_SERVER; } else if (serverButtonState == STOP_SERVER) { mediaService.tearDownNetworkConnection(); hostConfigView.setServerButtonText("Start Server"); serverButtonState = START_SERVER; } }); }
private void tryTheHackerNewsApi() { System.out.println("Calling RapidApi method from Java, snagging top 5 news stories"); hackerNewsApi.getNewStories() .subscribeOn(Schedulers.newThread()) .flatMap(map -> Observable.from((List<Double>) map.get("success"))) .take(5) .map(Double::longValue) .flatMap(id -> hackerNewsApi.getItem(id)) .map(r -> new Story((Map<String, Object>) r.get("success"))) .observeOn(JavaFxScheduler.getInstance()) .subscribe(System.out::println); }