package com.ez.ertc.setting

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

class SettingsButtonDecoration : ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val itemCount = parent.adapter!!.itemCount
        val viewPosition = parent.getChildAdapterPosition(view)
        outRect.left = divider
        outRect.right = divider
        if (viewPosition == 0) {
            outRect.top = header
            outRect.bottom = divider / 2
        } else if (viewPosition == itemCount - 1) {
            outRect.top = divider / 2
            outRect.bottom = footer
        } else {
            outRect.top = divider / 2
            outRect.bottom = divider / 2
        }
    }

    companion object {
        private const val divider = 12
        private const val header = 4
        private const val footer = 4
    }
}