コード例 #1
0
  public boolean shouldHandleRecyclerViewLoadingMore(RecyclerView recyclerView) {
    if (mIsLoadingMore
        || mCurrentRefreshStatus == RefreshStatus.REFRESHING
        || mLoadMoreFooterView == null
        || mDelegate == null
        || recyclerView.getAdapter() == null
        || recyclerView.getAdapter().getItemCount() == 0) {
      return false;
    }

    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager == null || manager.getItemCount() == 0) {
      return false;
    }

    if (manager instanceof LinearLayoutManager) {
      LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
      if (layoutManager.findLastCompletelyVisibleItemPosition()
          == recyclerView.getAdapter().getItemCount() - 1) {
        return true;
      }
    } else if (manager instanceof StaggeredGridLayoutManager) {
      StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;

      int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
      int lastPosition = layoutManager.getItemCount() - 1;
      for (int position : out) {
        if (position == lastPosition) {
          return true;
        }
      }
    }
    return false;
  }
コード例 #2
0
  public int getLastVisiblePosition() {
    LayoutManager layoutManager = getLayoutManager();
    if (null == layoutManager) return -1;

    int curItemCount = (null != mReqAdapter ? mReqAdapter.getItemCount() - 1 : 0);
    int ret = -1;

    switch (mLayoutManagerType) {
      case LAYOUT_MANAGER_TYPE_LINEAR:
        ret =
            ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition()
                - getHeaderViewsCount();
        if (ret > curItemCount) {
          ret -= getFooterViewsCount();
        }
        break;
      case LAYOUT_MANAGER_TYPE_GRID:
        ret =
            ((GridLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition()
                - getHeaderViewsCount();
        if (ret > curItemCount) {
          ret -= getFooterViewsCount();
        }
        break;
      case LAYOUT_MANAGER_TYPE_STAGGERED_GRID:
        StaggeredGridLayoutManager tempStaggeredGridLayoutManager =
            (StaggeredGridLayoutManager) layoutManager;
        int[] lastVisibleItemPositions = new int[tempStaggeredGridLayoutManager.getSpanCount()];
        tempStaggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(
            lastVisibleItemPositions);
        if (lastVisibleItemPositions.length > 0) {
          int maxPos = lastVisibleItemPositions[0];
          for (int curPos : lastVisibleItemPositions) {
            if (curPos > maxPos) maxPos = curPos;
          }
          ret = maxPos - getHeaderViewsCount();
          if (ret > curItemCount) {
            ret -= getFooterViewsCount();
          }
        }
        break;
    }

    return ret < 0 ? (null != mReqAdapter ? mReqAdapter.getItemCount() - 1 : 0) : ret;
  }