package com.swago.home.innerhome

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

/**
 *@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)
        if (itemPosition <= 0) {
            outRect.set(0, 0, 0, 0)
            return
        }

        if (SwagoInfo.getLanguageCode()=="ar"){
            when(column){
                0 -> {
                    outRect.set(margin, margin, middle, 0)
                }

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

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