1. Open Sourcing the Store
What we open sourced and how you can too!
Mike Nakhimovich - New York Times
2. Agenda For Today
Walkthrough of New York Times’ first Android
Open Source Library
How you can make open source a library
yourself
3. Problem Set
Modern Android Apps need their data representations to be fluid and always
available.
Users expect their UI experience to never be compromised (blocked) by new
data loads
International users expect minimal data downloads
4. Android === Open Source
Libraries fill gaps left by framework
Network Client? OKHTTP/Retrofit
Threading/Functional Programming? RxJava
Dependency Injection? Dagger
View Bindings? Butterknife
5. Android === Open Source
Libraries fill gaps left by framework
Network Client? OKHTTP/Retrofit
Threading/Functional Programming? RxJava
Dependency Injection? Dagger
View Bindings? Butterknife
Store? Data Flow & Caching
12. Add a fetcher
public interface Fetcher<T> {
Observable<T> fetch(BarCode barCode);
}
Store<Article> articleStore = StoreBuilder.<Article>builder()
.fetcher(barCode -> api.getArticle(barCode.getKey()))
.open();
13. Or NonObservable Fetcher
Use nonObservbleFetcher when connecting to a synchronous & non observable
API
Store<Article> articleStore = StoreBuilder.<Article>builder()
.nonObservableFetcher(barCode -> api.getArticle(barCode.getKey()))
.open();
14. Call your Store with a Barcode
...
BarCode barcode = new BarCode("Article", "42");
articleStore.fetch(barcode)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Article>() {
public void onCompleted() {}
public void onError(Throwable throwable) {//handle error}
public void onNext(Article article) {//bind Article to UI}});
First part of the talk will be a quick primer in a new library that we released at NY Times
Second part will be how to open source a library yourself.
If we ever fetched data when online, we should be able
Android Framework give us components like Activities, Services, Adapters and Widgets
Open Source Libraries try to fill the gap
Retrofit - Defacto standard for networking
RxJava - Threading and functional programming
Dagger - Dependecy Injection and Code Organization
Butterknife - Boilerplate reduction
Android Framework give us components like Activities, Services, Adapters and Widgets
Open Source Libraries try to fill the gap
Retrofit - Defacto standard for networking
RxJava - Threading and functional programming
Dagger - Dependecy Injection and Code Organization
Butterknife - Boilerplate reduction
Github link so that you all can check it out
Store’s follow the repository pattern and try to abstract working with data into a few public methods. You ask a store for data and it gets it from either local storage or network. If data needs to be parsed, the store takes care of that as well.
Store’s follow the repository pattern and try to abstract working with data into a few public methods. You ask a store for data and it gets it from either local storage or network. If data needs to be parsed, the store takes care of that as well.
Store’s follow the repository pattern and try to abstract working with data into a few public methods. You ask a store for data and it gets it from either local storage or network. If data needs to be parsed, the store takes care of that as well.
Each store is a representation of a single data call
Each store is a representation of a single data call
A fetcher will tell your Store how to load data. Think of a store as a wrapper for a particular endpoint you want to superpower. The nice part of using Stores is that it will work with both observable and non observable data sources
A fetcher will tell your Store how to load data. Think of a store as a wrapper for a particular endpoint you want to superpower. The nice part of using Stores is that it will work with both observable and non observable data sources
Stores use barcode to identify data, we will first create a barcode and then pass it to the store. When we subscribe to the store, it will call the fetcher and return to use an observable of the data
Uni Direct
Besides fetch you can also call get method on store. Calling get will return cached data if it is available rather than hitting your fetcher
Walk user through new data flow
Data usually comes in a format different from what UI expects. Stores have the ability to have a parser as well. Talk about the different builder & extra generic
The parsing step looks generic maybe we can do something about it? We created some parsers that are shared between different stores. Here you see an example of a GsonSourceParser which takes an input of a buffered source and outputs a POJO. We also included GsonStringParser and GsonStreamParser
The parsing step looks generic maybe we can do something about it? We created some parsers that are shared between different stores. Here you see an example of a GsonSourceParser which takes an input of a buffered source and outputs a POJO. We also included GsonStringParser and GsonStreamParser
Just like a Fetcher and Persister, You can implement a Perisister.
Don’t want to implement a persister? You don’t have to as long as you start with a BufferedSource.