package me.devsaki.hentoid.widget;

import android.view.View;

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

import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.IItem;
import com.mikepenz.fastadapter.select.SelectExtension;

import java.util.Set;

@SuppressWarnings("unused")
public class FastAdapterPreClickSelectHelper<T extends IItem<? extends RecyclerView.ViewHolder>> {

    private final SelectExtension<T> selectExtension;

    public FastAdapterPreClickSelectHelper(@NonNull SelectExtension<T> selectExtension) {
        this.selectExtension = selectExtension;
    }

    public Boolean onPreClickListener(View v, IAdapter<T> adapter, T item, Integer position) {
        Set<Integer> selectedPositions = selectExtension.getSelections();
        if (0 == selectedPositions.size()) { // No selection -> normal click
            return false;
        } else { // Existing selection -> toggle selection
            if (selectedPositions.contains(position) && 1 == selectedPositions.size())
                selectExtension.setSelectOnLongClick(true);
            selectExtension.toggleSelection(position);
            return true;
        }
    }

    public Boolean onPreLongClickListener(View v, IAdapter<T> adapter, T item, Integer position) {
        Set<Integer> selectedPositions = selectExtension.getSelections();
        if (0 == selectedPositions.size()) { // No selection -> select things
            selectExtension.select(position);
            selectExtension.setSelectOnLongClick(false);
            return true;
        }
        return false;
    }
}

@@ -326,16 +326,17 @@
 ngs(
+%7B
 %22unused%22
 )%0Apu
@@ -331,16 +331,31 @@
 %22unused%22
+, %22java:S1172%22%7D
 )%0Apublic

Make Sonar happy