/**
  * 设置当前RecyclerView.FooterView的状态
  *
  * @param recyclerView
  * @param state
  */
 public static void setFooterViewState(RecyclerView recyclerView, LoadingFooter.State state) {
   RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
   if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
     if (((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterViewsCount() > 0) {
       LoadingFooter footerView =
           (LoadingFooter) ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterView();
       footerView.setState(state);
     }
   }
 }
  /**
   * 获取当前RecyclerView.FooterView的状态
   *
   * @param recyclerView
   */
  public static LoadingFooter.State getFooterViewState(RecyclerView recyclerView) {

    RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
    if (outerAdapter != null && outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter) {
      if (((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterViewsCount() > 0) {
        LoadingFooter footerView =
            (LoadingFooter) ((HeaderAndFooterRecyclerViewAdapter) outerAdapter).getFooterView();
        return footerView.getState();
      }
    }

    return LoadingFooter.State.Normal;
  }
 @Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   if (mLoadingFooter.getState() == LoadingFooter.State.Loading
       || mLoadingFooter.getState() == LoadingFooter.State.TheEnd) {
     return;
   }
   if (firstVisibleItem + visibleItemCount >= totalItemCount
       && totalItemCount != 0
       && totalItemCount != (getHeaderViewsCount() + getFooterViewsCount())
       && mLoadNextListener != null) {
     mLoadingFooter.setState(LoadingFooter.State.Loading);
     mLoadNextListener.onLoadNext();
   }
 }
  /**
   * 设置headerAndFooterAdapter的FooterView State
   *
   * @param recyclerView recyclerView
   * @param pageSize 分页展示时,recyclerView每一页的数量
   * @param state FooterView State
   * @param errorListener FooterView处于Error状态时的点击事件
   */
  public static void setFooterViewState(
      Context context,
      RecyclerView recyclerView,
      int pageSize,
      LoadingFooter.State state,
      View.OnClickListener errorListener) {

    if (context == null) {
      return;
    }

    RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();

    if (outerAdapter == null || !(outerAdapter instanceof HeaderAndFooterRecyclerViewAdapter)) {
      return;
    }

    HeaderAndFooterRecyclerViewAdapter headerAndFooterAdapter =
        (HeaderAndFooterRecyclerViewAdapter) outerAdapter;

    // 只有一页的时候,就别加什么FooterView了
    if (headerAndFooterAdapter.getInnerAdapter().getItemCount() < pageSize) {
      return;
    }

    LoadingFooter footerView;

    // 已经有footerView了
    if (headerAndFooterAdapter.getFooterViewsCount() > 0) {
      footerView = (LoadingFooter) headerAndFooterAdapter.getFooterView();
      footerView.setState(state);

      if (state == LoadingFooter.State.NetWorkError) {
        footerView.setOnClickListener(errorListener);
      }
      recyclerView.scrollToPosition(headerAndFooterAdapter.getItemCount() - 1);
    } else {
      footerView = new LoadingFooter(context);
      footerView.setState(state);

      if (state == LoadingFooter.State.NetWorkError) {
        footerView.setOnClickListener(errorListener);
      }

      headerAndFooterAdapter.addFooterView(footerView);
      recyclerView.scrollToPosition(headerAndFooterAdapter.getItemCount() - 1);
    }
  }
 public void stopFooterAnimition() {
   mLoadingFooter.stopFooterAnim();
 }
 public void setState(LoadingFooter.State status, long delay) {
   mLoadingFooter.setState(status, delay);
 }
 public void setState(LoadingFooter.State status) {
   mLoadingFooter.setState(status);
 }
 private void init() {
   mLoadingFooter = new LoadingFooter(getContext());
   addFooterView(mLoadingFooter.getView());
   setOnScrollListener(this);
 }