Java Code Examples for android.support.v7.widget.LinearLayoutManager#getChildCount()

The following examples show how to use android.support.v7.widget.LinearLayoutManager#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StargazerListActivityViewModel.java    From Anago with Apache License 2.0 6 votes vote down vote up
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int visible = layoutManager.getChildCount();
        int total = layoutManager.getItemCount();
        int first = layoutManager.findFirstVisibleItemPosition();
        if (visible + first >= total) {
            Timber.v("Scroll End");
            if (!loadingMore) {
                Timber.v("Start loading more");
                loadingMore = true;
                load();
            }
        }
    }
}
 
Example 2
Source File: FragmentStatusList.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    LinearLayoutManager mLayoutManager = (LinearLayoutManager)recyclerView.getLayoutManager();
    int visibleItemCount = mLayoutManager.getChildCount();
    int totalItemCount = mLayoutManager.getItemCount();
    int pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
    if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount) {
        if((!loadingMore) && (!noMoreStatusToLoad)) {
            PushStatus status = statusRecyclerAdapter.getLastItem();
            if(status == null)
                return;
            refreshStatuses(status.getTimeOfArrival(),-1);
        }
    }

    /*
     * since design version > 22, I can't use misc.ScrollAwareFABBehavior because
     * hide() makes the view to GONE and thus doesn't trigger the onNestedScroll
     * So instead we use the Recycler Scroll to trigger the hide/show.
     */
    if (dy > 0)
        composeFAB.hide();
    else if (dy < 0)
        composeFAB.show();
}
 
Example 3
Source File: ViewAdapter.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
    if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
        if (onLoadMoreCommand != null) {
            methodInvoke.onNext(recyclerView.getAdapter().getItemCount());
        }
    }
}
 
Example 4
Source File: MultiFuncRecyclerView.java    From TestChat with Apache License 2.0 5 votes vote down vote up
private void processLoadMoreData() {
                LinearLayoutManager linearLayoutManager = (LinearLayoutManager) display.getLayoutManager();
                int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
                int totalCount = linearLayoutManager.getItemCount();
                int visibleCount = linearLayoutManager.getChildCount();
//                这里分两种情况,当缓慢滑动的时候,边滑动边加载,没有接触到底部。当如果快速滑动的时候,还没加载完就滑动到底部
                if ((firstVisibleItemPosition + visibleCount >= totalCount) && !isLoading && totalCount != 1) {
                        LogUtil.e("底部加载拉");
                        if (mOnMoreDataLoadListener != null) {
                                isLoading = true;
                                moreLoadView.setVisibility(VISIBLE);
                                mOnMoreDataLoadListener.onMoreDataLoad(totalCount, firstVisibleItemPosition);
                        }
                }
        }
 
Example 5
Source File: OnScrollToLastListener.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
@Override
public final void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

  int visibleItemCount = layoutManager.getChildCount();
  int totalItemCount = layoutManager.getItemCount();
  int pastVisibleItems = layoutManager.findFirstVisibleItemPosition();

  if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
    onScrollToLast();
  }
}
 
Example 6
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the first view that we should snap to.
 *
 * @param layoutManager the RecyclerView's LayoutManager
 * @param helper        orientation helper to calculate view sizes
 * @param gravity       gravity to find the closest view
 * @return the first view in the LayoutManager to snap to, or null if we shouldn't snap to any
 */
@Nullable
private View findView(@NonNull RecyclerView.LayoutManager layoutManager,
                      @NonNull OrientationHelper helper,
                      int gravity,
                      boolean checkEdgeOfList) {

    if (layoutManager.getChildCount() == 0 || !(layoutManager instanceof LinearLayoutManager)) {
        return null;
    }

    final LinearLayoutManager lm = (LinearLayoutManager) layoutManager;

    // If we're at an edge of the list, we shouldn't snap
    // to avoid having the last item not completely visible.
    if (checkEdgeOfList && (isAtEdgeOfList(lm) && !snapLastItem)) {
        return null;
    }

    View edgeView = null;
    int distanceToTarget = Integer.MAX_VALUE;
    final int center;
    if (layoutManager.getClipToPadding()) {
        center = helper.getStartAfterPadding() + helper.getTotalSpace() / 2;
    } else {
        center = helper.getEnd() / 2;
    }

    final boolean snapToStart = (gravity == Gravity.START && !isRtl)
            || (gravity == Gravity.END && isRtl);

    final boolean snapToEnd = (gravity == Gravity.START && isRtl)
            || (gravity == Gravity.END && !isRtl);

    for (int i = 0; i < lm.getChildCount(); i++) {
        View currentView = lm.getChildAt(i);
        int currentViewDistance;
        if (snapToStart) {
            if (!snapToPadding) {
                currentViewDistance = Math.abs(helper.getDecoratedStart(currentView));
            } else {
                currentViewDistance = Math.abs(helper.getStartAfterPadding()
                        - helper.getDecoratedStart(currentView));
            }
        } else if (snapToEnd) {
            if (!snapToPadding) {
                currentViewDistance = Math.abs(helper.getDecoratedEnd(currentView)
                        - helper.getEnd());
            } else {
                currentViewDistance = Math.abs(helper.getEndAfterPadding()
                        - helper.getDecoratedEnd(currentView));
            }
        } else {
            currentViewDistance = Math.abs(helper.getDecoratedStart(currentView)
                    + (helper.getDecoratedMeasurement(currentView) / 2) - center);
        }
        if (currentViewDistance < distanceToTarget) {
            distanceToTarget = currentViewDistance;
            edgeView = currentView;
        }
    }
    return edgeView;
}