Ejemplo n.º 1
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mPullLoadMoreRecyclerView.setStaggeredGridLayout(2); // 参数为列数
    mPullLoadMoreRecyclerView.setRefreshing(true);
    mPullLoadMoreRecyclerView.setOnPullLoadMoreListener(
        new PullLoadMoreRecyclerView.PullLoadMoreListener() {
          @Override
          public void onRefresh() {
            mPage = 1;
            mMainPresenter.loadData(getUrl(), hasTitle);
          }

          @Override
          public void onLoadMore() {
            mPage = mPage + 1;
            mMainPresenter.loadData(getUrl(), hasTitle);
          }
        });
    mMainPresenter = new MainPresenter();
    mMainPresenter.attachView(
        new MainView() {
          @Override
          public void showData(List<MainModel> mainList) {
            if (mRecyclerViewAdapter == null) {
              mRecyclerViewAdapter = new RecyclerViewAdapter(getActivity(), mainList, hasTitle);
              mPullLoadMoreRecyclerView.setAdapter(mRecyclerViewAdapter);
            } else {
              if (mPage == 1) {
                mRecyclerViewAdapter.getmMainList().clear();
              }
              mRecyclerViewAdapter.getmMainList().addAll(mainList);
              mRecyclerViewAdapter.notifyDataSetChanged();
            }
          }

          @Override
          public void hideProgress() {
            Log.d("wxl", "hideProgress");
            mPullLoadMoreRecyclerView.setPullLoadMoreCompleted();
          }
        });
    mMainPresenter.loadData(getUrl(), hasTitle);
  }
Ejemplo n.º 2
0
 @Override
 public void onDestroy() {
   mMainPresenter.detachView();
   super.onDestroy();
 }