diff options
author | ByteHamster <info@bytehamster.com> | 2022-05-08 10:21:39 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-05-08 11:18:53 +0200 |
commit | 7c0d084ffcc6a17ccac043a76f6640c89dea6272 (patch) | |
tree | f7deac1fc3f0e78d2f91670c5019c2526c7d50a4 /app | |
parent | 1fa0c32142c0c288adf8784c6c032ae3fa4a6611 (diff) | |
download | AntennaPod-7c0d084ffcc6a17ccac043a76f6640c89dea6272.zip |
Automatically select lazy loaded items if necessary
Diffstat (limited to 'app')
3 files changed, 17 insertions, 4 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java index 53223896f..8fb4a6314 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java @@ -48,6 +48,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol public void updateItems(List<FeedItem> items) { episodes = items; notifyDataSetChanged(); + updateTitle(); } @Override @@ -195,6 +196,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol return true; } else if (item.getItemId() == R.id.select_all_below) { setSelected(longPressedPosition + 1, getItemCount(), true); + shouldSelectLazyLoadedItems = true; return true; } return false; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SelectableAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SelectableAdapter.java index 43f749ff3..55669596b 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SelectableAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SelectableAdapter.java @@ -20,6 +20,7 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy private final HashSet<Long> selectedIds = new HashSet<>(); private final Activity activity; private OnSelectModeListener onSelectModeListener; + boolean shouldSelectLazyLoadedItems = false; public SelectableAdapter(Activity activity) { this.activity = activity; @@ -34,6 +35,7 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy onSelectModeListener.onStartSelectMode(); } + shouldSelectLazyLoadedItems = false; selectedIds.clear(); selectedIds.add(getItemId(pos)); notifyDataSetChanged(); @@ -56,9 +58,10 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (item.getItemId() == R.id.select_toggle) { - boolean allSelected = selectedIds.size() == getItemCount(); - setSelected(0, getItemCount(), !allSelected); - toggleSelectAllIcon(item, !allSelected); + boolean selectAll = selectedIds.size() != getItemCount(); + shouldSelectLazyLoadedItems = selectAll; + setSelected(0, getItemCount(), selectAll); + toggleSelectAllIcon(item, selectAll); updateTitle(); return true; } @@ -69,6 +72,7 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy public void onDestroyActionMode(ActionMode mode) { callOnEndSelectMode(); actionMode = null; + shouldSelectLazyLoadedItems = false; selectedIds.clear(); notifyDataSetChanged(); } @@ -147,7 +151,7 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy } } - private void updateTitle() { + void updateTitle() { if (actionMode == null) { return; } @@ -166,6 +170,10 @@ abstract class SelectableAdapter<T extends RecyclerView.ViewHolder> extends Recy } } + public boolean shouldSelectLazyLoadedItems() { + return shouldSelectLazyLoadedItems; + } + public interface OnSelectModeListener { void onStartSelectMode(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java index d47544e6f..55134cbfa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -283,6 +283,9 @@ public abstract class EpisodesListFragment extends Fragment implements EpisodeIt } episodes.addAll(data); onFragmentLoaded(episodes); + if (listAdapter.shouldSelectLazyLoadedItems()) { + listAdapter.setSelected(episodes.size() - data.size(), episodes.size(), true); + } }, error -> Log.e(TAG, Log.getStackTraceString(error)), () -> { recyclerView.post(() -> isLoadingMore = false); // Make sure to not always load 2 pages at once |