package com.bxzk.afxj.other;

import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.bxzk.afxj.util.DensityUtils;


/*
* LinearLayoutManager设置Item间距的的一个辅助类
* */
public class SpacesItemDecoration3 extends RecyclerView.ItemDecoration {
    private int itemSpaceLeft;
    private int itemSpaceCenter;
    private int itemNum;

    public SpacesItemDecoration3(int itemSpaceLeft, int itemSpaceCenter, int itemNum) {
        this.itemSpaceLeft = itemSpaceLeft;
        this.itemSpaceCenter = itemSpaceCenter;
        this.itemNum = itemNum;
    }


    private  int column;
    private  int space;

    public SpacesItemDecoration3(int space, int column) {
        this.space = space;
        this.column = column;
    }


    public SpacesItemDecoration3() {
    }


    public SpacesItemDecoration3(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        int mod = parent.getChildAdapterPosition(view) % column;
        outRect.left = space * mod;
        outRect.bottom = DensityUtils.dip2px(10);
        /*DisplayMetrics dm = BApplication.getContext().getResources().getDisplayMetrics();
        int w = dm.widthPixels; //获取当前界面的宽度
        int i = DensityUtil.dip2px(BApplication.getContext(), 38f);
        LinearLayout ll = (LinearLayout) view;
        View childAt = ll.getChildAt(0);
        int width = childAt.getLayoutParams().width;
        int gap = (w-i - 6 * width)/5;
        if(parent.getChildAdapterPosition(view)%6  ==  0) {
            outRect.left = 0;
            outRect.right = 0;
        }else if(parent.getChildAdapterPosition(view) %5 ==  0) {
            outRect.right = 0;
            outRect.left = 0;
        }else {
            outRect.left =0;
            outRect.right =gap;
        }*/
        /*outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        if (parent.getChildLayoutPosition(view) == 0) {
            outRect.top = space;
        } else {
            outRect.top = 0;
        }*/

        // Add top margin only for the first item to avoid double space between items

    }
}
