From b1f31ab7361b0ff59c06f1742f2f314224497bad Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 1 Jul 2021 20:05:27 -0400 Subject: [PATCH] remove unused code --- .../adapters/MultiSelectListAdapter.java | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 app/src/main/java/awais/instagrabber/adapters/MultiSelectListAdapter.java 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); - } -}