package com.convenient.android.common.utils.decoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.convenient.android.common.extension.dp2px

/**
 * @classname:PaddingItemDecoration
 * @author: LiuXiaoLong
 * @date: 2022/7/27
 * description: RecyclerView 条目添加Padding 装饰
 */
class PaddingItemDecoration(top: Int, bottom: Int, left: Int, right: Int) : RecyclerView.ItemDecoration() {
    private val mBottom = bottom
    private val mLeft = left
    private val mRight = right
    private val mTop = top

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)
        outRect.bottom = view.context.dp2px(mBottom.toFloat())
        outRect.top = view.context.dp2px(mTop.toFloat())
        outRect.left = view.context.dp2px(mLeft.toFloat())
        outRect.right = view.context.dp2px(mRight.toFloat())
    }
}