diff options
author | Vishnu Sanal T <50027064+VishnuSanal@users.noreply.github.com> | 2023-01-01 19:59:23 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-01 15:29:23 +0100 |
commit | 88289d02ae2a402ec77723dd53da33e9cf4c7311 (patch) | |
tree | 998806d05abcb74bed8d56e74742aa3473783a0c /app/src/main/java/de/danoeh | |
parent | 97889a46ed2f9e6e5fc6144b84f1c2367d311a05 (diff) | |
download | AntennaPod-88289d02ae2a402ec77723dd53da33e9cf4c7311.zip |
Possibility to remove a single episode from playback history (#6184)
Diffstat (limited to 'app/src/main/java/de/danoeh')
6 files changed, 84 insertions, 5 deletions
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 a4ed7ac8c..02336949e 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SwipeActionsDialog.java @@ -27,6 +27,7 @@ import de.danoeh.antennapod.fragment.AllEpisodesFragment; import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import de.danoeh.antennapod.fragment.InboxFragment; +import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.swipeactions.SwipeAction; import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; @@ -62,22 +63,32 @@ public class SwipeActionsDialog { case InboxFragment.TAG: forFragment = context.getString(R.string.inbox_label); keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.TOGGLE_PLAYED) - && !a.getId().equals(SwipeAction.DELETE)).toList(); + && !a.getId().equals(SwipeAction.DELETE) + && !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList(); break; case AllEpisodesFragment.TAG: forFragment = context.getString(R.string.episodes_label); + keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList(); break; case CompletedDownloadsFragment.TAG: forFragment = context.getString(R.string.downloads_label); - keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList(); + keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX) + && !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY) + && !a.getId().equals(SwipeAction.START_DOWNLOAD)).toList(); break; case FeedItemlistFragment.TAG: forFragment = context.getString(R.string.feeds_label); + keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList(); break; case QueueFragment.TAG: forFragment = context.getString(R.string.queue_label); keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.ADD_TO_QUEUE) - && !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList(); + && !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX) + && !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList(); + break; + case PlaybackHistoryFragment.TAG: + forFragment = context.getString(R.string.playback_history_label); + keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList(); break; default: break; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index db36a504a..01a1968ed 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -32,7 +32,6 @@ public class PlaybackHistoryFragment extends EpisodesListFragment { emptyView.setIcon(R.drawable.ic_history); emptyView.setTitle(R.string.no_history_head_label); emptyView.setMessage(R.string.no_history_label); - swipeActions.detach(); return root; } 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 b56dd5253..5b81ff7a5 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 @@ -9,6 +9,7 @@ import de.danoeh.antennapod.fragment.AllEpisodesFragment; import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import de.danoeh.antennapod.fragment.InboxFragment; +import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; public class SwipePreferencesFragment extends PreferenceFragmentCompat { @@ -17,6 +18,7 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat { private static final String PREF_SWIPE_EPISODES = "prefSwipeEpisodes"; private static final String PREF_SWIPE_DOWNLOADS = "prefSwipeDownloads"; private static final String PREF_SWIPE_FEED = "prefSwipeFeed"; + private static final String PREF_SWIPE_HISTORY = "prefSwipeHistory"; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -42,6 +44,10 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat { new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { }); return true; }); + findPreference(PREF_SWIPE_HISTORY).setOnPreferenceClickListener(preference -> { + new SwipeActionsDialog(requireContext(), PlaybackHistoryFragment.TAG).show(() -> { }); + return true; + }); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromHistorySwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromHistorySwipeAction.java new file mode 100644 index 000000000..385beb2dd --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromHistorySwipeAction.java @@ -0,0 +1,58 @@ +package de.danoeh.antennapod.fragment.swipeactions; + +import android.content.Context; + +import androidx.fragment.app.Fragment; + +import com.google.android.material.snackbar.Snackbar; + +import java.util.Date; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.FeedItemFilter; + +public class RemoveFromHistorySwipeAction implements SwipeAction { + + public static final String TAG = "RemoveFromHistorySwipeAction"; + + @Override + public String getId() { + return REMOVE_FROM_HISTORY; + } + + @Override + public int getActionIcon() { + return R.drawable.ic_history_remove; + } + + @Override + public int getActionColor() { + return R.attr.icon_purple; + } + + @Override + public String getTitle(Context context) { + return context.getString(R.string.remove_history_label); + } + + @Override + public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) { + + Date playbackCompletionDate = item.getMedia().getPlaybackCompletionDate(); + + DBWriter.deleteFromPlaybackHistory(item); + + ((MainActivity) fragment.requireActivity()) + .showSnackbarAbovePlayer(R.string.removed_history_label, Snackbar.LENGTH_LONG) + .setAction(fragment.getString(R.string.undo), + v -> DBWriter.addItemToPlaybackHistory(item.getMedia(), playbackCompletionDate)); + } + + @Override + public boolean willRemove(FeedItemFilter filter, FeedItem item) { + return true; + } +}
\ No newline at end of file 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 89360fdeb..4b1cfdc78 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 @@ -18,6 +18,7 @@ public interface SwipeAction { String TOGGLE_PLAYED = "MARK_PLAYED"; String REMOVE_FROM_QUEUE = "REMOVE_FROM_QUEUE"; String DELETE = "DELETE"; + String REMOVE_FROM_HISTORY = "REMOVE_FROM_HISTORY"; 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 afb79e497..4ad9df531 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 @@ -24,6 +24,7 @@ import de.danoeh.antennapod.dialog.SwipeActionsDialog; import de.danoeh.antennapod.fragment.AllEpisodesFragment; import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.InboxFragment; +import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; @@ -40,7 +41,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life Arrays.asList(new AddToQueueSwipeAction(), new RemoveFromInboxSwipeAction(), new StartDownloadSwipeAction(), new MarkFavoriteSwipeAction(), new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction(), - new DeleteSwipeAction()) + new DeleteSwipeAction(), new RemoveFromHistorySwipeAction()) ); private final Fragment fragment; @@ -105,6 +106,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life case CompletedDownloadsFragment.TAG: defaultActions = SwipeAction.DELETE + "," + SwipeAction.DELETE; break; + case PlaybackHistoryFragment.TAG: + defaultActions = SwipeAction.REMOVE_FROM_HISTORY + "," + SwipeAction.REMOVE_FROM_HISTORY; + break; default: case AllEpisodesFragment.TAG: defaultActions = SwipeAction.MARK_FAV + "," + SwipeAction.START_DOWNLOAD; |