From b2a3c33e7c35ac78ac45ba30d7b196f5392c7563 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 7 May 2022 20:43:30 +0200 Subject: [PATCH] Fix swiping away not yet downloaded items from downloads screen --- .../antennapod/fragment/CompletedDownloadsFragment.java | 4 ++-- .../fragment/swipeactions/AddToQueueSwipeAction.java | 2 +- .../fragment/swipeactions/DeleteSwipeAction.java | 7 +++++-- .../fragment/swipeactions/MarkFavoriteSwipeAction.java | 2 +- .../fragment/swipeactions/RemoveFromInboxSwipeAction.java | 4 ++-- .../fragment/swipeactions/RemoveFromQueueSwipeAction.java | 4 ++-- .../fragment/swipeactions/ShowFirstSwipeDialogAction.java | 2 +- .../fragment/swipeactions/StartDownloadSwipeAction.java | 2 +- .../antennapod/fragment/swipeactions/SwipeAction.java | 2 +- .../antennapod/fragment/swipeactions/SwipeActions.java | 7 ++++--- .../swipeactions/TogglePlaybackStateSwipeAction.java | 4 ++-- 11 files changed, 22 insertions(+), 18 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 a0722f0f0..18c5d8514 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -12,7 +12,6 @@ import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; -import androidx.core.util.ObjectsCompat; import androidx.fragment.app.Fragment; import com.google.android.material.snackbar.Snackbar; import com.leinardi.android.speeddial.SpeedDialView; @@ -48,6 +47,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -188,7 +188,7 @@ public class CompletedDownloadsFragment extends Fragment if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { refreshToolbarState(); } - if (!ObjectsCompat.equals(event.update.mediaIds, runningDownloads)) { + if (!Arrays.equals(event.update.mediaIds, runningDownloads)) { runningDownloads = event.update.mediaIds; loadItems(); return; // Refreshed anyway diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/AddToQueueSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/AddToQueueSwipeAction.java index 514ba9764..3580121df 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/AddToQueueSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/AddToQueueSwipeAction.java @@ -41,7 +41,7 @@ public class AddToQueueSwipeAction implements SwipeAction { } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return filter.showQueued || filter.showNew; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java index 767f5c6c1..a4c69eb2b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java @@ -31,11 +31,14 @@ public class DeleteSwipeAction implements SwipeAction { @Override public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { + if (!item.isDownloaded()) { + return; + } DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId()); } @Override - public boolean willRemove(FeedItemFilter filter) { - return filter.showDownloaded; + public boolean willRemove(FeedItemFilter filter, FeedItem item) { + return filter.showDownloaded && item.isDownloaded(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/MarkFavoriteSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/MarkFavoriteSwipeAction.java index 2458657a0..162003fab 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/MarkFavoriteSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/MarkFavoriteSwipeAction.java @@ -37,7 +37,7 @@ public class MarkFavoriteSwipeAction implements SwipeAction { } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return filter.showIsFavorite || filter.showNotFavorite; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java index df1ef42c1..41d79a711 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java @@ -34,12 +34,12 @@ public class RemoveFromInboxSwipeAction implements SwipeAction { @Override public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { if (item.isNew()) { - FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter)); + FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter, item)); } } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return filter.showNew; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromQueueSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromQueueSwipeAction.java index 87cf97f56..9687ab643 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromQueueSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromQueueSwipeAction.java @@ -41,7 +41,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction { DBWriter.removeQueueItem(fragment.requireActivity(), true, item); - if (willRemove(filter)) { + if (willRemove(filter, item)) { ((MainActivity) fragment.requireActivity()).showSnackbarAbovePlayer( fragment.getResources().getQuantityString(R.plurals.removed_from_queue_batch_label, 1, 1), Snackbar.LENGTH_LONG) @@ -51,7 +51,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction { } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return filter.showQueued || filter.showNotQueued; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/ShowFirstSwipeDialogAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/ShowFirstSwipeDialogAction.java index 7d626134d..3a6174e8f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/ShowFirstSwipeDialogAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/ShowFirstSwipeDialogAction.java @@ -36,7 +36,7 @@ public class ShowFirstSwipeDialogAction implements SwipeAction { } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return false; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/StartDownloadSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/StartDownloadSwipeAction.java index 2c0110822..84dc8f417 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/StartDownloadSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/StartDownloadSwipeAction.java @@ -38,7 +38,7 @@ public class StartDownloadSwipeAction implements SwipeAction { } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return false; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeAction.java index 23bf99a55..89360fdeb 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeAction.java @@ -31,5 +31,5 @@ public interface SwipeAction { void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter); - boolean willRemove(FeedItemFilter filter); + boolean willRemove(FeedItemFilter filter, FeedItem item); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java index 726c1de1a..be35f6503 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java @@ -158,8 +158,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life } //check if it will be removed - boolean rightWillRemove = right.willRemove(filter); - boolean leftWillRemove = left.willRemove(filter); + FeedItem item = ((EpisodeItemViewHolder) viewHolder).getFeedItem(); + boolean rightWillRemove = right.willRemove(filter, item); + boolean leftWillRemove = left.willRemove(filter, item); boolean wontLeave = (dx > 0 && !rightWillRemove) || (dx < 0 && !leftWillRemove); //Limit swipe if it's not removed @@ -251,7 +252,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life String[] actions = prefs.split(","); if (actions.length == 2) { this.right = Stream.of(swipeActions) - .filter(a -> a.getId().equals(actions[0])).single();; + .filter(a -> a.getId().equals(actions[0])).single(); this.left = Stream.of(swipeActions) .filter(a -> a.getId().equals(actions[1])).single(); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/TogglePlaybackStateSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/TogglePlaybackStateSwipeAction.java index 4ff07d13c..d4ce8b1d2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/TogglePlaybackStateSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/TogglePlaybackStateSwipeAction.java @@ -34,11 +34,11 @@ public class TogglePlaybackStateSwipeAction implements SwipeAction { @Override public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { int newState = item.getPlayState() == FeedItem.UNPLAYED ? FeedItem.PLAYED : FeedItem.UNPLAYED; - FeedItemMenuHandler.markReadWithUndo(fragment, item, newState, willRemove(filter)); + FeedItemMenuHandler.markReadWithUndo(fragment, item, newState, willRemove(filter, item)); } @Override - public boolean willRemove(FeedItemFilter filter) { + public boolean willRemove(FeedItemFilter filter, FeedItem item) { return filter.showUnplayed || filter.showPlayed || filter.showNew; } }