Java Code Examples for androidx.recyclerview.widget.LinearLayoutManager#getChildCount()

The following examples show how to use androidx.recyclerview.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: ThreadListFragment.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        visibleItemCount = mLayoutManager.getChildCount();
        totalItemCount = mLayoutManager.getItemCount();
        mFirstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

        if ((visibleItemCount + mFirstVisibleItem) >= totalItemCount - 5) {
            if (!mInloading) {
                mPage++;
                mInloading = true;
                mRecyclerView.setFooterState(XFooterView.STATE_LOADING);
                ThreadListJob job = new ThreadListJob(getActivity(), mSessionId, mForumId, mPage);
                JobMgr.addJob(job);
            }
        }
    }
}
 
Example 2
Source File: SimpleListFragment.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        visibleItemCount = mLayoutManager.getChildCount();
        totalItemCount = mLayoutManager.getItemCount();
        mFirstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

        if ((visibleItemCount + mFirstVisibleItem) >= totalItemCount - 5) {
            if (!mInloading) {
                mInloading = true;
                if (mPage < mMaxPage) {
                    mPage++;
                    mRecyclerView.setFooterState(XFooterView.STATE_LOADING);
                    SimpleListJob job = new SimpleListJob(getActivity(), mSessionId, mType, mPage, mSearchId);
                    JobMgr.addJob(job);
                } else {
                    mRecyclerView.setFooterState(XFooterView.STATE_END);
                }
            }
        }
    }
}
 
Example 3
Source File: SearchFragment.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        visibleItemCount = layoutManager.getChildCount();
        totalItemCount = layoutManager.getItemCount();
        int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();

        if ((visibleItemCount + firstVisibleItem) >= totalItemCount - 5) {
            if (!mInloading) {
                mInloading = true;
                if (mPage < mMaxPage) {
                    mPage++;
                    mRecyclerView.setFooterState(XFooterView.STATE_LOADING);
                    SimpleListJob job = new SimpleListJob(getActivity(), mSessionId, mType, mPage, mSearchBean);
                    JobMgr.addJob(job);
                } else {
                    mRecyclerView.setFooterState(XFooterView.STATE_END);
                }
            }
        }
    }
}
 
Example 4
Source File: UserinfoFragment.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (dy > 0) {
        LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        visibleItemCount = mLayoutManager.getChildCount();
        totalItemCount = mLayoutManager.getItemCount();
        int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

        if ((visibleItemCount + firstVisibleItem) >= totalItemCount - 5) {
            if (!mInloading) {
                mInloading = true;
                if (mPage < mMaxPage) {
                    mPage++;
                    mRecyclerView.setFooterState(XFooterView.STATE_LOADING);
                    SearchBean bean = new SearchBean();
                    bean.setUid(mUid);
                    bean.setSearchId(mSearchId);
                    SimpleListJob job = new SimpleListJob(UserinfoFragment.this.getActivity(), mSessionId,
                            SimpleListJob.TYPE_SEARCH_USER_THREADS,
                            mPage,
                            bean);
                    JobMgr.addJob(job);
                } else {
                    mRecyclerView.setFooterState(XFooterView.STATE_END);
                }
            }
        }
    }
}
 
Example 5
Source File: GravitySnapHelper.java    From GravitySnapHelper with Apache License 2.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;
}