O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extracting item persistence code

We can use the same approach to extract code that's responsible for the persistence of the StockUpdate items and their retrieval when internet connection isn't available. So, consider the following lines:

.doOnNext(this::saveStockUpdate).onExceptionResumeNext(StorIOFactory.createLocalDbStockUpdateRetrievalObservable(this))

They can be replaced with the given lines:

.compose(addLocalItemPersistenceHandling())

Here, the addLocalItemPersistenceHandling() is set to this:

@NonNullprivate ObservableTransformer<StockUpdate, StockUpdate> addLocalItemPersistenceHandling() {    return upstream -> upstream.doOnNext(this::saveStockUpdate)            .onExceptionResumeNext(StorIOFactory            .createLocalDbStockUpdateRetrievalObservable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required