|
@@ -1,78 +0,0 @@
|
|
|
-package eu.kanade.tachiyomi.ui.base.decoration;
|
|
|
-
|
|
|
-import android.content.Context;
|
|
|
-import android.content.res.TypedArray;
|
|
|
-import android.graphics.Canvas;
|
|
|
-import android.graphics.Rect;
|
|
|
-import android.graphics.drawable.Drawable;
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
-import android.util.AttributeSet;
|
|
|
-import android.view.View;
|
|
|
-
|
|
|
-public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
|
|
-
|
|
|
- private final Drawable mDivider;
|
|
|
-
|
|
|
- public DividerItemDecoration(Context context, AttributeSet attrs) {
|
|
|
- final TypedArray a = context.obtainStyledAttributes(attrs, new int [] { android.R.attr.listDivider });
|
|
|
- mDivider = a.getDrawable(0);
|
|
|
- a.recycle();
|
|
|
- }
|
|
|
-
|
|
|
- public DividerItemDecoration(Drawable divider) { mDivider = divider; }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
|
|
- super.getItemOffsets(outRect, view, parent, state);
|
|
|
- if (mDivider == null) return;
|
|
|
- if (parent.getChildPosition(view) < 1) return;
|
|
|
-
|
|
|
- if (getOrientation(parent) == LinearLayoutManager.VERTICAL) outRect.top = mDivider.getIntrinsicHeight();
|
|
|
- else outRect.left = mDivider.getIntrinsicWidth();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
|
|
- if (mDivider == null) { super.onDrawOver(c, parent, state); return; }
|
|
|
-
|
|
|
- if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
|
|
|
- final int left = parent.getPaddingLeft();
|
|
|
- final int right = parent.getWidth() - parent.getPaddingRight();
|
|
|
- final int childCount = parent.getChildCount();
|
|
|
- final int dividerHeight = mDivider.getIntrinsicHeight();
|
|
|
-
|
|
|
- for (int i=1; i < childCount; i++) {
|
|
|
- final View child = parent.getChildAt(i);
|
|
|
- final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
|
|
- final int ty = (int)(child.getTranslationY() + 0.5f);
|
|
|
- final int top = child.getTop() - params.topMargin + ty;
|
|
|
- final int bottom = top + dividerHeight;
|
|
|
- mDivider.setBounds(left, top, right, bottom);
|
|
|
- mDivider.draw(c);
|
|
|
- }
|
|
|
- } else { //horizontal
|
|
|
- final int top = parent.getPaddingTop();
|
|
|
- final int bottom = parent.getHeight() - parent.getPaddingBottom();
|
|
|
- final int childCount = parent.getChildCount();
|
|
|
-
|
|
|
- for (int i=1; i < childCount; i++) {
|
|
|
- final View child = parent.getChildAt(i);
|
|
|
- final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
|
|
- final int size = mDivider.getIntrinsicWidth();
|
|
|
- final int left = child.getLeft() - params.leftMargin;
|
|
|
- final int right = left + size;
|
|
|
- mDivider.setBounds(left, top, right, bottom);
|
|
|
- mDivider.draw(c);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private int getOrientation(RecyclerView parent) {
|
|
|
- if (parent.getLayoutManager() instanceof LinearLayoutManager) {
|
|
|
- LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
|
|
- return layoutManager.getOrientation();
|
|
|
- } else throw new IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager.");
|
|
|
- }
|
|
|
-
|
|
|
-}
|