@Override
        public void handleMessage(Message msg) {
          super.handleMessage(msg);

          switch (msg.what) {
            case WHAT_DISPATCH_NOTIFY_REFRESH:
              Object[] argsRefresh = (Object[]) msg.obj;
              RecyclerFooterAdapterWrapper wrapperRefresh =
                  (RecyclerFooterAdapterWrapper) argsRefresh[0];
              List<WeakReference<SwipeRefreshLayout.OnRefreshListener>> listenersRefresh =
                  (List<WeakReference<SwipeRefreshLayout.OnRefreshListener>>) argsRefresh[1];

              wrapperRefresh.setLoadmoreEnabled(false);
              for (WeakReference<SwipeRefreshLayout.OnRefreshListener> weak : listenersRefresh) {
                SwipeRefreshLayout.OnRefreshListener listener = weak.get();
                if (listener != null) {
                  onNotify(listener);
                }
              }
              break;

            case WHAT_DISPATCH_NOTIFY_LOADMORE:
              Object[] argsLoadmore = (Object[]) msg.obj;
              RecyclerFooterAdapterWrapper wrapperLoadmore =
                  (RecyclerFooterAdapterWrapper) argsLoadmore[0];
              List<WeakReference<OnLoadmoreListener>> listenersLoadmore =
                  (List<WeakReference<OnLoadmoreListener>>) argsLoadmore[1];
              if (!wrapperLoadmore.isLoadingmoreEnabled() || wrapperLoadmore.isLoadingmoreing()) {
                return;
              }

              // TODO 此处需要禁用下拉功能

              wrapperLoadmore.setLoadmoreing(true);
              for (WeakReference<OnLoadmoreListener> weak : listenersLoadmore) {
                OnLoadmoreListener listener = weak.get();
                if (listener != null) {
                  onNotify(listener);
                }
              }
              break;

            case WHAT_ON_REFRESH:
            case WHAT_ON_LOADMORE:
              Object listener = msg.obj;
              if (listener != null) {
                if (listener instanceof SwipeRefreshLayout.OnRefreshListener) {
                  ((SwipeRefreshLayout.OnRefreshListener) listener).onRefresh();
                } else if (listener instanceof OnLoadmoreListener) {
                  ((OnLoadmoreListener) listener).onLoadmore();
                }
              }
              break;
          }
        }
Example #2
0
  /** swipeRefreshLayout自动下拉刷新 */
  private void autoRefresh() {
    refreshLayout.post(
        new Runnable() {
          @Override
          public void run() {
            refreshLayout.setRefreshing(true);
          }
        });

    refreshLayout.setOnRefreshListener(listener);
    listener.onRefresh();
  }