コード例 #1
0
ファイル: MainFragment.java プロジェクト: haikuowuya/Vineyard
 @Override
 public void onItemClicked(
     Presenter.ViewHolder itemViewHolder,
     Object item,
     RowPresenter.ViewHolder rowViewHolder,
     Row row) {
   if (item instanceof Post) {
     if (NetworkUtil.isNetworkConnected(getActivity())) {
       Post post = (Post) item;
       int index = mRowsAdapter.indexOf(row);
       PostAdapter adapter =
           ((PostAdapter) ((ListRow) mRowsAdapter.get(index)).getAdapter());
       ArrayList<Post> postList = (ArrayList<Post>) adapter.getAllItems();
       startActivity(PlaybackActivity.newStartIntent(getActivity(), post, postList));
     } else {
       ToastFactory.createWifiErrorToast(getActivity()).show();
     }
   } else if (item instanceof Option) {
     Option option = (Option) item;
     if (option.title.equals(getString(R.string.title_no_videos))
         || item.equals(getString(R.string.title_oops))) {
       int index = mRowsAdapter.indexOf(row);
       PostAdapter adapter =
           ((PostAdapter) ((ListRow) mRowsAdapter.get(index)).getAdapter());
       adapter.removeReloadCard();
       addPostLoadSubscription(adapter);
     } else {
       startActivity(GuidedStepActivity.getStartIntent(getActivity()));
     }
   }
 }
コード例 #2
0
ファイル: MainFragment.java プロジェクト: haikuowuya/Vineyard
  private void addPostLoadSubscription(final PostAdapter adapter) {
    if (adapter.shouldShowLoadingIndicator()) adapter.showLoadingIndicator();

    Map<String, String> options = adapter.getAdapterOptions();
    String tag = options.get(PaginationAdapter.KEY_TAG);
    final String anchor = options.get(PaginationAdapter.KEY_ANCHOR);
    String nextPage = options.get(PaginationAdapter.KEY_NEXT_PAGE);

    Observable<PostResponse> observable;
    if (tag.equals(mPopularText)) {
      observable = mDataManager.getPopularPosts(nextPage, anchor);
    } else if (tag.equals(mEditorsPicksText)) {
      observable = mDataManager.getEditorsPicksPosts(nextPage, anchor);
    } else {
      observable = mDataManager.getPostsByTag(tag, nextPage, anchor);
    }

    mCompositeSubscription.add(
        observable
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .unsubscribeOn(Schedulers.io())
            .subscribe(
                new Subscriber<PostResponse>() {
                  @Override
                  public void onCompleted() {}

                  @Override
                  public void onError(Throwable e) {
                    adapter.removeLoadingIndicator();
                    if (adapter.size() == 0) {
                      adapter.showTryAgainCard();
                    } else {
                      Toast.makeText(
                              getActivity(),
                              getString(R.string.error_message_loading_more_posts),
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                    Timber.e("There was an error loading the posts", e);
                  }

                  @Override
                  public void onNext(PostResponse postResponse) {
                    adapter.removeLoadingIndicator();
                    if (adapter.size() == 0 && postResponse.data.records.isEmpty()) {
                      adapter.showReloadCard();
                    } else {
                      if (anchor == null) adapter.setAnchor(postResponse.data.anchorStr);
                      adapter.setNextPage(postResponse.data.nextPage);
                      adapter.addAllItems(postResponse.data.records);
                    }
                  }
                }));
  }
コード例 #3
0
ファイル: MainFragment.java プロジェクト: haikuowuya/Vineyard
 @Override
 public void onItemSelected(
     Presenter.ViewHolder itemViewHolder,
     Object item,
     RowPresenter.ViewHolder rowViewHolder,
     Row row) {
   if (item instanceof Post) {
     String backgroundUrl = ((Post) item).thumbnailUrl;
     if (backgroundUrl != null) startBackgroundTimer(URI.create(backgroundUrl));
     int index = mRowsAdapter.indexOf(row);
     PostAdapter adapter = ((PostAdapter) ((ListRow) mRowsAdapter.get(index)).getAdapter());
     if (adapter.get(adapter.size() - 1).equals(item) && adapter.shouldLoadNextPage()) {
       addPostLoadSubscription(adapter);
     }
   }
 }