diff --git a/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java b/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java deleted file mode 100644 index 9b8fe04b..00000000 --- a/app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java +++ /dev/null @@ -1,104 +0,0 @@ -package awais.instagrabber.adapters; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DiffUtil; -import androidx.recyclerview.widget.ListAdapter; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.ArrayList; -import java.util.List; - -public abstract class MultiSelectListAdapter extends - ListAdapter { - - private boolean isSelecting; - private OnItemClickListener internalOnItemClickListener; - private OnItemLongClickListener internalOnLongItemClickListener; - - private final List selectedItems = new ArrayList<>(); - - protected MultiSelectListAdapter(@NonNull final DiffUtil.ItemCallback diffCallback, - final OnItemClickListener clickListener, - final OnItemLongClickListener longClickListener) { - super(diffCallback); - internalOnItemClickListener = (item, position) -> { - if (isSelecting) { - toggleSelection(item, position); - } - if (clickListener == null) { - return; - } - clickListener.onItemClick(item, position); - }; - internalOnLongItemClickListener = (item, position) -> { - if (!isSelecting) { - isSelecting = true; - } - toggleSelection(item, position); - if (longClickListener == null) { - return true; - } - return longClickListener.onItemLongClick(item, position); - }; - } - - public OnItemClickListener getInternalOnItemClickListener() { - return internalOnItemClickListener; - } - - public OnItemLongClickListener getInternalOnLongItemClickListener() { - return internalOnLongItemClickListener; - } - - private void toggleSelection(final T item, final int position) { - if (item == null) { - return; - } - if (selectedItems.size() >= 100) { - // Toast.makeText(mainActivity, R.string.downloader_too_many, Toast.LENGTH_SHORT); - return; - } - if (item.isSelected()) { - item.setSelected(false); - selectedItems.remove(item); - } else { - item.setSelected(true); - selectedItems.add(item); - } - if (selectedItems.size() == 0) { - isSelecting = false; - } - notifyItemChanged(position); - } - - public boolean isSelecting() { - return isSelecting; - } - - public List getSelectedModels() { - return selectedItems; - } - - public void clearSelection() { - for (final T item : selectedItems) { - item.setSelected(false); - } - selectedItems.clear(); - isSelecting = false; - notifyDataSetChanged(); - } - - public interface Selectable { - boolean isSelected(); - - void setSelected(boolean selected); - } - - public interface OnItemClickListener { - void onItemClick(T item, int position); - } - - public interface OnItemLongClickListener { - boolean onItemLongClick(T item, int position); - } -}