package com.bokecc.livemodule.live.chat.util;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class EmojiItemDecoration extends RecyclerView.ItemDecoration {
    private final int itemHeight;

    public EmojiItemDecoration(int itemHeight) {
        this.itemHeight = itemHeight;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (parent.getAdapter() != null) {
            int itemCount = parent.getAdapter().getItemCount();
            if (itemCount != 0) {
                int itemPosition = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
                if (itemPosition == itemCount - 1) {
                    outRect.set(0, 0, 0, itemHeight);
                }
            }
        }
    }
}
