@Override public void showLoading() { if (canCustomFooter()) { if (mHeaderAdapter != null) { mHeaderAdapter.setFooter(getLoading()); } else if (mListView != null) { removeListViewFooters(); mListView.addFooterView(getLoading(), null, false); } } }
@Override public void showEnd() { if (canCustomFooter()) { if (mHeaderAdapter != null) { if (mHeaderAdapter.getBasicItemCount() != 0) { mHeaderAdapter.setFooter(getLoadEnd()); } else { mHeaderAdapter.removeFooter(); } } else if (mListView != null) { removeListViewFooters(); int actualChildCount = mListView.getCount() - mListView.getHeaderViewsCount() - mListView.getFooterViewsCount(); if (actualChildCount > 0) { mListView.addFooterView(getLoadEnd(), null, false); } } } }
@Override public boolean setAutoLoading(View target) { if (target instanceof RecyclerView) { mRecyclerView = (RecyclerView) target; mRecyclerView.addOnScrollListener( new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); boolean canScrollDown = ViewCompat.canScrollVertically(recyclerView, 1); if (canLoadMore() && !canScrollDown && dy > 0) { startLoading(); } } }); return true; } else if (getTarget() instanceof CommonListView) { mListView = (CommonListView) target; mListView.addOnScrollListener( new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // 当不滚动时 if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { // 判断是否滚动到底部 if (view.getLastVisiblePosition() == view.getCount() - 1) { if (!isLoadFail() && !isLoading() && isLoadEnable()) { startLoading(); } } } } @Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {} }); return true; } return false; }
private void removeListViewFooters() { mListView.removeFooterView(getLoading()); mListView.removeFooterView(getLoadFail()); mListView.removeFooterView(getLoadEnd()); }