package com.common.commonlib.view;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

/**
 * rv辅助类
 *
 * @author wangym
 * @since 2021/7/28
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    /**
     * 默认图片展示单行数量
     */
    private static final int DEFAULT_MEDIA_SIZE = 3;

    /**
     * 默认图片展示间距
     */
    private static final int DEFAULT_MEDIA_OFFSET = 30;

    @Override
    public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, RecyclerView parent, @NotNull RecyclerView.State state) {
        int temp = parent.getChildAdapterPosition(view) % DEFAULT_MEDIA_SIZE;
        outRect.left = DEFAULT_MEDIA_OFFSET * (temp);

        if (parent.getChildAdapterPosition(view) >= DEFAULT_MEDIA_SIZE) {
            outRect.top = DEFAULT_MEDIA_OFFSET;
        } else {
            outRect.top = 0;
        }
    }
}
