Exemplo n.º 1
0
 @Nonnull
 public Observable<Boolean> progressObservable() {
   return ResponseOrError.combineProgressObservable(
       ImmutableList.of(
           ResponseOrError.transform(titleObservable),
           ResponseOrError.transform(itemsObservable)));
 }
Exemplo n.º 2
0
 @Nonnull
 public Observable<Throwable> errorObservable() {
   return ResponseOrError.combineErrorsObservable(
           ImmutableList.of(
               ResponseOrError.transform(titleObservable),
               ResponseOrError.transform(itemsObservable)))
       .distinctUntilChanged();
 }
Exemplo n.º 3
0
  @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());
                                  }
                                }));
                  }
                }));
  }
Exemplo n.º 4
0
  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());
  }
Exemplo n.º 5
0
 @Nonnull
 public Observable<List<AdapterItem>> itemsObservable() {
   return itemsObservable.compose(ResponseOrError.<List<AdapterItem>>onlySuccess());
 }
Exemplo n.º 6
0
 @Nonnull
 public Observable<String> titleObservable() {
   return titleObservable.compose(ResponseOrError.<String>onlySuccess());
 }