package com.gh.gamecenter.common.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.gh.gamecenter.core.utils.DisplayUtils;

public class HorizontalItemDecoration extends RecyclerView.ItemDecoration {

    private Paint paint;
    private int mInterval = 0;
    private int mSize = 0;
    private boolean mIncludeEnd = false;

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

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


//	@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 (!mIncludeEnd && parent.getChildPosition(view) == mSize - 1) {
            outRect.set(0, 0, 0, 0);
        } else {
            outRect.set(0, 0, mInterval, 0);
        }
    }
}
