package com.swago.home.innerhome

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.swago.baseswago.util.DpPxUtil

/**
 *@date 2021/11/28 11:06
 *description:
 */
class HomeGridItemDecoration : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val itemPosition = (view.layoutParams as RecyclerView.LayoutParams).viewLayoutPosition
        val column = itemPosition % 2
        val margin = DpPxUtil.dip2px(6f)
        val middle = DpPxUtil.dip2px(3f)
        when(column){
            0 -> {
                outRect.set(margin, 0, middle, margin)
            }

            1 -> {
                outRect.set(middle, 0, margin, margin)
            }
        }
    }
}