package com.example.base.decoration

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

/**
 * 设置上下左右间隔
 */
class FirstItemOffsetDecoration(
    private val space: Int,
    private val position: Int = left
) : ItemDecoration() {

    companion object {
        var left = 0
        var top = 1
        var right = 2
        var bottom = 3
    }

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        if (parent.getChildLayoutPosition(view) == 0) {
            when (position) {
                left -> outRect.left = space
                top -> outRect.top = space
                right -> outRect.right = space
                bottom -> outRect.bottom = space
            }
        }
    }
}