diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java index 674b198d5..da4cfc1c0 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java @@ -22,6 +22,7 @@ import de.danoeh.antennapod.databinding.SwipeactionsDialogBinding; import de.danoeh.antennapod.databinding.SwipeactionsPickerBinding; import de.danoeh.antennapod.databinding.SwipeactionsPickerItemBinding; import de.danoeh.antennapod.databinding.SwipeactionsRowBinding; +import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.EpisodesFragment; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import de.danoeh.antennapod.fragment.InboxFragment; @@ -64,6 +65,9 @@ public class SwipeActionsDialog { case EpisodesFragment.TAG: forFragment = context.getString(R.string.episodes_label); break; + case CompletedDownloadsFragment.TAG: + forFragment = context.getString(R.string.downloads_label); + break; case FeedItemlistFragment.TAG: forFragment = context.getString(R.string.feeds_label); break; 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..a0722f0f0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -32,8 +32,10 @@ import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler; +import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.FeedItemFilter; import de.danoeh.antennapod.view.EmptyViewHandler; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; @@ -68,6 +70,7 @@ public class CompletedDownloadsFragment extends Fragment private boolean isUpdatingFeeds = false; private SpeedDialView speedDialView; private Toolbar toolbar; + private SwipeActions swipeActions; @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -89,6 +92,8 @@ public class CompletedDownloadsFragment extends Fragment adapter = new CompletedDownloadsListAdapter((MainActivity) getActivity()); adapter.setOnSelectModeListener(this); recyclerView.setAdapter(adapter); + swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView); + swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.DOWNLOADED)); progressBar = root.findViewById(R.id.progLoading); progressBar.setVisibility(View.VISIBLE); @@ -312,6 +317,7 @@ public class CompletedDownloadsFragment extends Fragment @Override public void onStartSelectMode() { + swipeActions.detach(); speedDialView.setVisibility(View.VISIBLE); } @@ -319,6 +325,7 @@ public class CompletedDownloadsFragment extends Fragment public void onEndSelectMode() { speedDialView.close(); speedDialView.setVisibility(View.GONE); + swipeActions.attachTo(recyclerView); } private class CompletedDownloadsListAdapter extends EpisodeItemListAdapter { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java index 1786fe0bf..44330c236 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java @@ -5,23 +5,21 @@ import androidx.preference.PreferenceFragmentCompat; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.dialog.SwipeActionsDialog; +import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import de.danoeh.antennapod.fragment.InboxFragment; import de.danoeh.antennapod.fragment.QueueFragment; public class SwipePreferencesFragment extends PreferenceFragmentCompat { - private static final String PREF_SWIPE_FEED = "prefSwipeFeed"; private static final String PREF_SWIPE_QUEUE = "prefSwipeQueue"; private static final String PREF_SWIPE_INBOX = "prefSwipeInbox"; + private static final String PREF_SWIPE_DOWNLOADS = "prefSwipeDownloads"; + private static final String PREF_SWIPE_FEED = "prefSwipeFeed"; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.preferences_swipe); - findPreference(PREF_SWIPE_FEED).setOnPreferenceClickListener(preference -> { - new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { }); - return true; - }); findPreference(PREF_SWIPE_QUEUE).setOnPreferenceClickListener(preference -> { new SwipeActionsDialog(requireContext(), QueueFragment.TAG).show(() -> { }); return true; @@ -30,6 +28,14 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat { new SwipeActionsDialog(requireContext(), InboxFragment.TAG).show(() -> { }); return true; }); + findPreference(PREF_SWIPE_DOWNLOADS).setOnPreferenceClickListener(preference -> { + new SwipeActionsDialog(requireContext(), CompletedDownloadsFragment.TAG).show(() -> { }); + return true; + }); + findPreference(PREF_SWIPE_FEED).setOnPreferenceClickListener(preference -> { + new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { }); + return true; + }); } @Override 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 new file mode 100644 index 000000000..767f5c6c1 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/DeleteSwipeAction.java @@ -0,0 +1,41 @@ +package de.danoeh.antennapod.fragment.swipeactions; + +import android.content.Context; +import androidx.fragment.app.Fragment; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.FeedItemFilter; + +public class DeleteSwipeAction implements SwipeAction { + + @Override + public String getId() { + return DELETE; + } + + @Override + public int getActionIcon() { + return R.drawable.ic_delete; + } + + @Override + public int getActionColor() { + return R.attr.icon_red; + } + + @Override + public String getTitle(Context context) { + return context.getString(R.string.delete_episode_label); + } + + @Override + public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { + DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId()); + } + + @Override + public boolean willRemove(FeedItemFilter filter) { + return filter.showDownloaded; + } +} 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 58e8af82b..23bf99a55 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 @@ -17,6 +17,7 @@ public interface SwipeAction { String MARK_FAV = "MARK_FAV"; String TOGGLE_PLAYED = "MARK_PLAYED"; String REMOVE_FROM_QUEUE = "REMOVE_FROM_QUEUE"; + String DELETE = "DELETE"; String getId(); 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 d9779baf9..726c1de1a 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 @@ -21,6 +21,7 @@ import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.dialog.SwipeActionsDialog; +import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.EpisodesFragment; import de.danoeh.antennapod.fragment.InboxFragment; import de.danoeh.antennapod.fragment.QueueFragment; @@ -38,7 +39,8 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life public static final List swipeActions = Collections.unmodifiableList( Arrays.asList(new AddToQueueSwipeAction(), new RemoveFromInboxSwipeAction(), new StartDownloadSwipeAction(), new MarkFavoriteSwipeAction(), - new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction()) + new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction(), + new DeleteSwipeAction()) ); private final Fragment fragment; @@ -100,6 +102,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life case QueueFragment.TAG: defaultActions = SwipeAction.REMOVE_FROM_QUEUE + "," + SwipeAction.REMOVE_FROM_QUEUE; break; + case CompletedDownloadsFragment.TAG: + defaultActions = SwipeAction.DELETE + "," + SwipeAction.DELETE; + break; default: case EpisodesFragment.TAG: defaultActions = SwipeAction.MARK_FAV + "," + SwipeAction.START_DOWNLOAD; diff --git a/app/src/main/res/xml/preferences_swipe.xml b/app/src/main/res/xml/preferences_swipe.xml index d19a6759c..e5c3ee684 100644 --- a/app/src/main/res/xml/preferences_swipe.xml +++ b/app/src/main/res/xml/preferences_swipe.xml @@ -9,6 +9,10 @@ android:key="prefSwipeInbox" android:title="@string/inbox_label"/> + +