package com.ttstd.dialer.view;

import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.ttstd.dialer.utils.ScreenUtils;

public class EqualHeightDecoration extends RecyclerView.ItemDecoration {
    private int rowCount;

    public EqualHeightDecoration(int rowCount) {
        this.rowCount = rowCount;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int recyclerViewHeight = parent.getHeight();
        int height = recyclerViewHeight - 6 * ScreenUtils.dp2px(view.getResources(), 4);
        int itemHeight = recyclerViewHeight / rowCount;
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = itemHeight;
        view.setLayoutParams(params);
    }
}

