package com.abbidot.tracker.adapter

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

/**
 *Created  by .yzq on 2021/12/24/024.
 * @link https://qa.1r1g.com/sf/ask/1997239751/
 * @description:RecyclerView的LinearLayoutManager和FlexboxLayoutManager通用item间距设置
 */
class SpaceItemDecoration(
    left: Int = 0, right: Int = 0, top: Int = 0, bottom: Int = 0
) : RecyclerView.ItemDecoration() {

    private var mLeft = left
    private var mRight = right
    private var mTop = top
    private var mBottom = bottom

    override fun getItemOffsets(
        outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State
    ) {
        if (mLeft > 0) {
            outRect.left = mLeft
        }
        if (mRight > 0) {
            outRect.right = mRight
        }
        if (mTop > 0) {
            outRect.top = mTop
        }
        if (mBottom > 0) {
            outRect.bottom = mBottom
        }
    }
}