예제 #1
0
  private void loadMore() {
    mRecyclerView.setLoadingMore(true);

    ZhiHuApplication.getRepository()
        .getBeforeDailyStories(
            mDate,
            new Repository.Callback<DailyStories>() {
              @Override
              public void success(DailyStories dailyStories, boolean outDate) {
                /**
                 * 注意,若果需要查询 11 月 18 日的消息,before 后的数字应为 20131119 所以在加载前一日时,只需要mDate =
                 * dailyStories.getDate()
                 */
                mDate = dailyStories.getDate();
                mRecyclerView.setLoadingMore(false);
                mAdapter.appendList(dailyStories);
              }

              @Override
              public void failure(Exception e) {
                mRecyclerView.setLoadingMore(false);
                Toast.makeText(getActivity(), "加载失败", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
              }
            });
  }
예제 #2
0
  private void refresh() {
    isDataLoaded = false;
    mSwipeRefreshLayout.setRefreshing(true);
    ZhiHuApplication.getRepository()
        .getLatestDailyStories(
            new Repository.Callback<DailyStories>() {
              @Override
              public void success(DailyStories dailyStories, boolean outDate) {
                isDataLoaded = true;
                mSwipeRefreshLayout.setRefreshing(false);
                mDate = dailyStories.getDate();
                mAdapter.setList(dailyStories);
              }

              @Override
              public void failure(Exception e) {
                isDataLoaded = false;
                mSwipeRefreshLayout.setRefreshing(false);
                Toast.makeText(getActivity(), "刷新失败", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
              }
            });
  }