As we now have the data prepared, it will be super easy to plug it in to our existing RecyclerView population code.
Recall our initial RecyclerView population code that contained mock data:
Observable.just(
new StockUpdate("GOOGLE", 12.43, new Date()),
new StockUpdate("APPL", 645.1, new Date()),
new StockUpdate("TWTR", 1.43, new Date())
)
.subscribe(stockUpdate -> {
Log.d("APP", "New update " + stockUpdate.getStockSymbol());
stockDataAdapter.add(stockUpdate);
});
Here, the last part (.subscribe()) can be taken and plugged in to the existing flow we have just created:
yahooService.yqlQuery(query, env)
.subscribeOn(Schedulers.io())
.toObservable()
.map(r -> r.getQuery().getResults().getQuote())
.flatMap(r -> Observable.fromIterable(r))
.map(r -> StockUpdate.create(r))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(stockUpdate -> {
Log.d("APP", "New update " + stockUpdate.getStockSymbol());
stockDataAdapter.add(stockUpdate);
});
That's it! It's a strong argument that all the trouble for the anti-corruption layer was worth it as we don't need to change anything else, and we will finally be able to see real financial stock quotes from Yahoo service.