diff options
author | ByteHamster <info@bytehamster.com> | 2022-05-08 11:08:34 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-05-08 11:18:53 +0200 |
commit | 072e172996ea82af8ac56880ad56714197d3fe7c (patch) | |
tree | 18553101e6661b07a3f7f0f66d97991931171773 /app/src | |
parent | 03220d07748d0908c4cf4e6b260ce828dc5ebaac (diff) | |
download | AntennaPod-072e172996ea82af8ac56880ad56714197d3fe7c.zip |
Switch around arguments in MultiSelectActionHandler
Diffstat (limited to 'app/src')
5 files changed, 51 insertions, 44 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 22a7a877c..cab7ba452 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -115,8 +115,8 @@ public class CompletedDownloadsFragment extends Fragment } }); speedDialView.setOnActionSelectedListener(actionItem -> { - new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), adapter.getSelectedItems()) - .handleAction(actionItem.getId()); + new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId()) + .handleAction(adapter.getSelectedItems()); adapter.endSelectMode(); return true; }); 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 e47599e3b..06c8148e5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -246,8 +246,8 @@ public abstract class EpisodesListFragment extends Fragment implements EpisodeIt } }); speedDialView.setOnActionSelectedListener(actionItem -> { - new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), listAdapter.getSelectedItems()) - .handleAction(actionItem.getId()); + new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId()) + .handleAction(listAdapter.getSelectedItems()); listAdapter.endSelectMode(); return true; }); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index a42abd724..80a65e518 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -197,8 +197,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem } }); speedDialBinding.fabSD.setOnActionSelectedListener(actionItem -> { - new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), adapter.getSelectedItems()) - .handleAction(actionItem.getId()); + new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId()) + .handleAction(adapter.getSelectedItems()); adapter.endSelectMode(); return true; }); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 2a89519a5..61f45f0f9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -505,8 +505,8 @@ public class QueueFragment extends Fragment implements Toolbar.OnMenuItemClickLi } }); speedDialView.setOnActionSelectedListener(actionItem -> { - new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), recyclerAdapter.getSelectedItems()) - .handleAction(actionItem.getId()); + new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId()) + .handleAction(recyclerAdapter.getSelectedItems()); recyclerAdapter.endSelectMode(); return true; }); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java index 17642874e..aad611e5d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/EpisodeMultiSelectActionHandler.java @@ -21,35 +21,37 @@ import de.danoeh.antennapod.model.feed.FeedItem; public class EpisodeMultiSelectActionHandler { private static final String TAG = "EpisodeSelectHandler"; private final MainActivity activity; - private final List<FeedItem> selectedItems; + private final int actionId; + private int totalNumItems = 0; + private Snackbar snackbar = null; - public EpisodeMultiSelectActionHandler(MainActivity activity, List<FeedItem> selectedItems) { + public EpisodeMultiSelectActionHandler(MainActivity activity, int actionId) { this.activity = activity; - this.selectedItems = selectedItems; + this.actionId = actionId; } - public void handleAction(int id) { - if (id == R.id.add_to_queue_batch) { - queueChecked(); - } else if (id == R.id.remove_from_queue_batch) { - removeFromQueueChecked(); - } else if (id == R.id.mark_read_batch) { - markedCheckedPlayed(); - } else if (id == R.id.mark_unread_batch) { - markedCheckedUnplayed(); - } else if (id == R.id.download_batch) { - downloadChecked(); - } else if (id == R.id.delete_batch) { - deleteChecked(); + public void handleAction(List<FeedItem> items) { + if (actionId == R.id.add_to_queue_batch) { + queueChecked(items); + } else if (actionId == R.id.remove_from_queue_batch) { + removeFromQueueChecked(items); + } else if (actionId == R.id.mark_read_batch) { + markedCheckedPlayed(items); + } else if (actionId == R.id.mark_unread_batch) { + markedCheckedUnplayed(items); + } else if (actionId == R.id.download_batch) { + downloadChecked(items); + } else if (actionId == R.id.delete_batch) { + deleteChecked(items); } else { - Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=" + id); + Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=" + actionId); } } - private void queueChecked() { + private void queueChecked(List<FeedItem> items) { // Check if an episode actually contains any media files before adding it to queue - LongList toQueue = new LongList(selectedItems.size()); - for (FeedItem episode : selectedItems) { + LongList toQueue = new LongList(items.size()); + for (FeedItem episode : items) { if (episode.hasMedia()) { toQueue.add(episode.getId()); } @@ -58,28 +60,28 @@ public class EpisodeMultiSelectActionHandler { showMessage(R.plurals.added_to_queue_batch_label, toQueue.size()); } - private void removeFromQueueChecked() { - long[] checkedIds = getSelectedIds(); + private void removeFromQueueChecked(List<FeedItem> items) { + long[] checkedIds = getSelectedIds(items); DBWriter.removeQueueItem(activity, true, checkedIds); showMessage(R.plurals.removed_from_queue_batch_label, checkedIds.length); } - private void markedCheckedPlayed() { - long[] checkedIds = getSelectedIds(); + private void markedCheckedPlayed(List<FeedItem> items) { + long[] checkedIds = getSelectedIds(items); DBWriter.markItemPlayed(FeedItem.PLAYED, checkedIds); showMessage(R.plurals.marked_read_batch_label, checkedIds.length); } - private void markedCheckedUnplayed() { - long[] checkedIds = getSelectedIds(); + private void markedCheckedUnplayed(List<FeedItem> items) { + long[] checkedIds = getSelectedIds(items); DBWriter.markItemPlayed(FeedItem.UNPLAYED, checkedIds); showMessage(R.plurals.marked_unread_batch_label, checkedIds.length); } - private void downloadChecked() { + private void downloadChecked(List<FeedItem> items) { // download the check episodes in the same order as they are currently displayed List<DownloadRequest> requests = new ArrayList<>(); - for (FeedItem episode : selectedItems) { + for (FeedItem episode : items) { if (episode.hasMedia() && !episode.getFeed().isLocalFeed()) { requests.add(DownloadRequestCreator.create(episode.getMedia()).build()); } @@ -88,9 +90,9 @@ public class EpisodeMultiSelectActionHandler { showMessage(R.plurals.downloading_batch_label, requests.size()); } - private void deleteChecked() { + private void deleteChecked(List<FeedItem> items) { int countHasMedia = 0; - for (FeedItem feedItem : selectedItems) { + for (FeedItem feedItem : items) { if (feedItem.hasMedia() && feedItem.getMedia().isDownloaded()) { countHasMedia++; DBWriter.deleteFeedMediaOfItem(activity, feedItem.getMedia().getId()); @@ -100,14 +102,19 @@ public class EpisodeMultiSelectActionHandler { } private void showMessage(@PluralsRes int msgId, int numItems) { - activity.showSnackbarAbovePlayer(activity.getResources() - .getQuantityString(msgId, numItems, numItems), Snackbar.LENGTH_LONG); + totalNumItems += numItems; + String text = activity.getResources().getQuantityString(msgId, totalNumItems, totalNumItems); + if (snackbar != null) { + snackbar.setText(text); + } else { + snackbar = activity.showSnackbarAbovePlayer(text, Snackbar.LENGTH_LONG); + } } - private long[] getSelectedIds() { - long[] checkedIds = new long[selectedItems.size()]; - for (int i = 0; i < selectedItems.size(); ++i) { - checkedIds[i] = selectedItems.get(i).getId(); + private long[] getSelectedIds(List<FeedItem> items) { + long[] checkedIds = new long[items.size()]; + for (int i = 0; i < items.size(); ++i) { + checkedIds[i] = items.get(i).getId(); } return checkedIds; } |