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
| package com.laimiux.dayahead.ui.util; | |
| import android.content.Context; | |
| import android.os.Bundle; | |
| import android.os.Parcelable; | |
| import android.support.v4.view.PagerAdapter; | |
| import android.util.Log; | |
| import android.util.SparseArray; | |
| import android.view.LayoutInflater; | |
| import android.view.View; |
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 void onAttach(View view) { | |
| view.showLoading(true) | |
| repository.getData().subscribe({ data -> | |
| view.showLoading(false) | |
| view.showData(data) | |
| }, { error -> | |
| view.showLoading(false) | |
| // should we have a retry action? | |
| view.showError("boo!") | |
| }) |
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 void onAttach(View view) { | |
| repository.getLatestDataStream().subscribe({ data -> | |
| view.showData(data) | |
| }) | |
| } |
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
| // Lce -> Loading / Content / Error | |
| class Lce<T> { | |
| public static <T> Lce<T> data(T data) { | |
| // implementation | |
| } | |
| public static <T> Lce<T> error(Throwable error) { | |
| // implementation | |
| } | |
| public static <T> Lce<T> loading() { | |
| // implementation |
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
| interface DataRepository { | |
| Observable<Lce<Data>> getDataEventStream(); | |
| } |
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 void onAttach(View view) { | |
| // Remember to clean the subscription! | |
| repository.getDataEventStream().subscribe({ event -> | |
| if (event.isLoading) { | |
| view.showLoading(true) | |
| } else if (event.hasError()) { | |
| view.showError(event.getError()) | |
| } else { | |
| view.showData(event.getData()) | |
| } |
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
| Observable<Lce<Data>> getDataEventStream() { | |
| return api.getData() | |
| .map(data -> Lce.data(data)) | |
| .startWith(Lce.loading()) | |
| .onErrorReturn(e -> Lce.error(e)) | |
| } |
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
| final PublishRelay<String> refreshRelay = PublishRelay.create() | |
| void refreshData() { | |
| refreshRelay.call("refresh event") | |
| } | |
| Observable<Lce<Data>> getDataEventStream() { | |
| return refreshRelay | |
| .startWith("initial") | |
| .switchMap { event -> |
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
| class UserContent { | |
| // requires both the user and list of published content | |
| } | |
| Observable<Lce<User>> getUserEventStream(String userId); | |
| Observable<Lce<List<Content>> getContentEventStream(String userId); | |
| Observable<Lce<UserContent>> getProfileEventStream(String id) { | |
| return Observable.combineLatest( | |
| getUserEventStream(id), |
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
| class UserManager { | |
| Observable<Lce<User>> getUserEventStream() { | |
| return updateEventStream().startWith(cachedBundle().map(toLce())) | |
| } | |
| } |
OlderNewer