@Nonnull public Observable<Boolean> progressObservable() { return ResponseOrError.combineProgressObservable( ImmutableList.of( ResponseOrError.transform(titleObservable), ResponseOrError.transform(itemsObservable))); }
@Nonnull public Observable<Throwable> errorObservable() { return ResponseOrError.combineErrorsObservable( ImmutableList.of( ResponseOrError.transform(titleObservable), ResponseOrError.transform(itemsObservable))) .distinctUntilChanged(); }
@Nonnull private Observable<ResponseOrError<PostsResponse>> postsObservable2() { return this.postsDao .postsIdsObservable() .compose( ResponseOrError.switchMap( new Func1<PostsIdsResponse, Observable<ResponseOrError<PostsResponse>>>() { @Override public Observable<ResponseOrError<PostsResponse>> call(final PostsIdsResponse o) { return Observable.from(o.items()) .map( new Func1<PostId, Observable<ResponseOrError<Post>>>() { @Override public Observable<ResponseOrError<Post>> call(PostId postId) { return postsDao.postDao(postId.id()).postObservable(); } }) .toList() .compose(MoreOperators.<ResponseOrError<Post>>newCombineAll()) .compose(ResponseOrError.<Post>newFromListObservable()) .compose( ResponseOrError.map( new Func1<List<Post>, PostsResponse>() { @Override public PostsResponse call(List<Post> posts) { return new PostsResponse(o.title(), posts, o.nextToken()); } })); } })); }
public MainPresenter(@Nonnull PostsDao postsDao) { this.postsDao = postsDao; titleObservable = postsObservable() .compose( ResponseOrError.map( new Func1<PostsResponse, String>() { @Override public String call(PostsResponse postsResponse) { return Strings.nullToEmpty(postsResponse.title()); } })) .compose(ObservableExtensions.<ResponseOrError<String>>behaviorRefCount()); itemsObservable = postsObservable() .compose( ResponseOrError.map( new Func1<PostsResponse, List<AdapterItem>>() { @Override public List<AdapterItem> call(PostsResponse postsResponse) { final List<Post> posts = postsResponse.items(); return FluentIterable.from(posts) .transform( new Function<Post, AdapterItem>() { @Nonnull @Override public AdapterItem apply(Post input) { return new AdapterItem(input.id(), input.name()); } }) .toList(); } })) .compose(ObservableExtensions.<ResponseOrError<List<AdapterItem>>>behaviorRefCount()); }
@Nonnull public Observable<List<AdapterItem>> itemsObservable() { return itemsObservable.compose(ResponseOrError.<List<AdapterItem>>onlySuccess()); }
@Nonnull public Observable<String> titleObservable() { return titleObservable.compose(ResponseOrError.<String>onlySuccess()); }