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

The following examples show how to use androidx.recyclerview.widget.LinearLayoutManager#getReverseLayout() . 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: DividerDecorationHelper.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
@NonNull
public static DividerDecorationHelper getHelper(int orientation, RecyclerView parent) {
    if (!(parent.getLayoutManager() instanceof LinearLayoutManager)) {
        return sNormalVerticalDividerDecorationHelper;
    }
    LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
    boolean isReversed = layoutManager.getReverseLayout();

    switch (orientation) {
        default:
        case Orientation.VERTICAL:
            if (isReversed) return sReverseVerticalDividerDecorationHelper;
            return sNormalVerticalDividerDecorationHelper;
        case Orientation.HORIZONTAL:
            if (isReversed) return sReverseHorizontalDividerDecorationHelper;
            return sNormalHorizontalDividerDecorationHelper;
    }
}
 
Example 2
Source File: GravitySnapHelper.java    From GravitySnapHelper with Apache License 2.0 5 votes vote down vote up
private boolean isAtEdgeOfList(LinearLayoutManager lm) {
    if ((!lm.getReverseLayout() && gravity == Gravity.START)
            || (lm.getReverseLayout() && gravity == Gravity.END)
            || (!lm.getReverseLayout() && gravity == Gravity.TOP)
            || (lm.getReverseLayout() && gravity == Gravity.BOTTOM)) {
        return lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else if (gravity == Gravity.CENTER) {
        return lm.findFirstCompletelyVisibleItemPosition() == 0
                || lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else {
        return lm.findFirstCompletelyVisibleItemPosition() == 0;
    }
}
 
Example 3
Source File: ScrollPositionListener.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    if (!Preferences.isViewerSwipeToTurn() || !isScrollEnabled) {
        recyclerView.stopScroll();
        return;
    }

    LinearLayoutManager llm = (LinearLayoutManager) recyclerView.getLayoutManager();
    if (llm != null) {
        if (RecyclerView.SCROLL_STATE_DRAGGING == newState) {
            dragStartPositionX = recyclerView.computeHorizontalScrollOffset();
            dragStartPositionY = recyclerView.computeVerticalScrollOffset();
            isSettlingX = false;
            isSettlingY = false;
        } else if (RecyclerView.SCROLL_STATE_SETTLING == newState) {
            // If the settling position is different from the original position, ignore that scroll
            // (e.g. snapping back to the original position after a small scroll)
            if (recyclerView.computeHorizontalScrollOffset() != dragStartPositionX)
                isSettlingX = true;
            if (recyclerView.computeVerticalScrollOffset() != dragStartPositionY)
                isSettlingY = true;
        } else if (RecyclerView.SCROLL_STATE_IDLE == newState) {
            // Don't do anything if we're not on a boundary
            if (!(llm.findLastVisibleItemPosition() == llm.getItemCount() - 1 || 0 == llm.findFirstVisibleItemPosition()))
                return;

            if (recyclerView.computeHorizontalScrollOffset() == dragStartPositionX && !isSettlingX && llm.canScrollHorizontally()) {
                if (0 == dragStartPositionX && !llm.getReverseLayout())
                    onStartOutOfBoundScroll.run();
                else if (0 == dragStartPositionX) onEndOutOfBoundScroll.run();
                else if (llm.getReverseLayout()) onStartOutOfBoundScroll.run();
                else onEndOutOfBoundScroll.run();
            }
            if (recyclerView.computeVerticalScrollOffset() == dragStartPositionY && !isSettlingY && llm.canScrollVertically()) {
                if (0 == dragStartPositionY && !llm.getReverseLayout())
                    onStartOutOfBoundScroll.run();
                else if (0 == dragStartPositionY) onEndOutOfBoundScroll.run();
                else if (llm.getReverseLayout()) onStartOutOfBoundScroll.run();
                else onEndOutOfBoundScroll.run();
            }
        }
    }
}