package com.gh.common.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.gh.common.util.DisplayUtils;

public class HorizontalItemDecoration extends RecyclerView.ItemDecoration {

	private Paint paint;
	private int mInterval = 0;
	private int mSize = 0;

	public HorizontalItemDecoration(Context context, int interval, int size) {
		paint = new Paint();
		paint.setColor(Color.WHITE);
		mInterval = DisplayUtils.dip2px(context, interval);
		mSize = size;
	}

//	@Override
//	public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//		int top = parent.getPaddingTop();
//		int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
//		for (int i = 0, size = parent.getChildCount(); i < size; i++) {
//			View child = parent.getChildAt(i);
//			RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child
//					.getLayoutParams();
//			int left = child.getRight() + layoutParams.rightMargin;
//			int right = left + mInterval;
//			c.drawRect(left, top, right, bottom, paint);
//		}
//	}

	@Override
	public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
			RecyclerView.State state) {
		if (parent.getChildPosition(view) == mSize - 1) {
			outRect.set(0, 0, 0, 0);
		} else {
			outRect.set(0, 0, mInterval, 0);
		}
	}
}
