Search in sources :

Example 1 with RecyclerArrayAdapter

use of com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter in project EasyRecyclerView by Jude95.

the class DividerDecoration method onDrawOver.

public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    int orientation = 0;
    int headerCount = 0, footerCount = 0, dataCount;
    if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
        dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
    } else {
        dataCount = parent.getAdapter().getItemCount();
    }
    int dataStartPosition = headerCount;
    int dataEndPosition = headerCount + dataCount;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof GridLayoutManager) {
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof LinearLayoutManager) {
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int start, end;
    if (orientation == OrientationHelper.VERTICAL) {
        start = parent.getPaddingLeft() + mPaddingLeft;
        end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
    } else {
        start = parent.getPaddingTop() + mPaddingLeft;
        end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
    }
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(child);
        if (//数据项除了最后一项
        position >= dataStartPosition && position < dataEndPosition - 1 || //数据项最后一项
        (position == dataEndPosition - 1 && mDrawLastItem) || //header&footer且可绘制
        (!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
            if (orientation == OrientationHelper.VERTICAL) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mHeight;
                mColorDrawable.setBounds(start, top, end, bottom);
                mColorDrawable.draw(c);
            } else {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int left = child.getRight() + params.rightMargin;
                int right = left + mHeight;
                mColorDrawable.setBounds(left, start, right, end);
                mColorDrawable.draw(c);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with RecyclerArrayAdapter

use of com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter in project EasyRecyclerView by Jude95.

the class EasyDataObserver method update.

// 自动更改Container的样式
private void update() {
    int count;
    if (recyclerView.getAdapter() instanceof RecyclerArrayAdapter) {
        RecyclerArrayAdapter adapter = ((RecyclerArrayAdapter) recyclerView.getAdapter());
        // 有Header Footer就不显示Empty,但排除EventFooter。
        count = adapter.getCount() + adapter.getHeaderCount() + adapter.getFooterCount() - (adapter.hasEventFooter() ? 1 : 0);
    } else {
        count = recyclerView.getAdapter().getItemCount();
    }
    if (count == 0) {
        recyclerView.showEmpty();
    } else {
        recyclerView.showRecycler();
    }
}
Also used : RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter)

Example 3 with RecyclerArrayAdapter

use of com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter in project EasyRecyclerView by Jude95.

the class DividerDecoration method onDraw.

public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    int orientation = 0;
    int headerCount = 0, footerCount = 0, dataCount;
    if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
        dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
    } else {
        dataCount = parent.getAdapter().getItemCount();
    }
    int dataStartPosition = headerCount;
    int dataEndPosition = headerCount + dataCount;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof GridLayoutManager) {
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof LinearLayoutManager) {
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int start, end;
    if (orientation == OrientationHelper.VERTICAL) {
        start = parent.getPaddingLeft() + mPaddingLeft;
        end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
    } else {
        start = parent.getPaddingTop() + mPaddingLeft;
        end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
    }
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(child);
        if (// 数据项除了最后一项
        position >= dataStartPosition && position < dataEndPosition - 1 || // 数据项最后一项
        (position == dataEndPosition - 1 && mDrawLastItem) || // header&footer且可绘制
        (!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
            if (orientation == OrientationHelper.VERTICAL) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mHeight;
                mColorDrawable.setBounds(start, top, end, bottom);
                mColorDrawable.draw(c);
            } else {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int left = child.getRight() + params.rightMargin;
                int right = left + mHeight;
                mColorDrawable.setBounds(left, start, right, end);
                mColorDrawable.draw(c);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 4 with RecyclerArrayAdapter

use of com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter in project EasyRecyclerView by Jude95.

the class StickyHeaderDecoration method onDrawOver.

/**
 * {@inheritDoc}
 */
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    final int count = parent.getChildCount();
    long previousHeaderId = -1;
    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        int adapterPos = parent.getChildAdapterPosition(child);
        if (!mIncludeHeader) {
            if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
                int headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
                int footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
                int dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
                if (adapterPos < headerCount) {
                    continue;
                }
                if (adapterPos >= headerCount + dataCount) {
                    continue;
                }
                if (adapterPos >= headerCount) {
                    adapterPos -= headerCount;
                }
            }
        }
        if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) {
            long headerId = mAdapter.getHeaderId(adapterPos);
            if (headerId != previousHeaderId) {
                previousHeaderId = headerId;
                View header = getHeader(parent, adapterPos).itemView;
                canvas.save();
                final int left = child.getLeft();
                final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
                canvas.translate(left, top);
                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(canvas);
                canvas.restore();
            }
        }
    }
}
Also used : RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 5 with RecyclerArrayAdapter

use of com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter in project EasyRecyclerView by Jude95.

the class StickyHeaderDecoration method getItemOffsets.

/**
 * {@inheritDoc}
 */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    int headerHeight = 0;
    if (!mIncludeHeader) {
        if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
            int headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
            int footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
            int dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
            if (position < headerCount) {
                return;
            }
            if (position >= headerCount + dataCount) {
                return;
            }
            if (position >= headerCount) {
                position -= headerCount;
            }
        }
    }
    if (position != RecyclerView.NO_POSITION && hasHeader(position) && showHeaderAboveItem(position)) {
        View header = getHeader(parent, position).itemView;
        headerHeight = getHeaderHeightForLayout(header);
    }
    outRect.set(0, headerHeight, 0, 0);
}
Also used : RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerArrayAdapter (com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter)7 View (android.view.View)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 ViewGroup (android.view.ViewGroup)2 PersonViewHolder (com.jude.dome.viewholder.PersonViewHolder)2 EasyRecyclerView (com.jude.easyrecyclerview.EasyRecyclerView)2 DividerDecoration (com.jude.easyrecyclerview.decoration.DividerDecoration)2 StickyHeaderDecoration (com.jude.easyrecyclerview.decoration.StickyHeaderDecoration)1