diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2018-09-27 17:32:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 17:32:30 +0200 |
commit | 340fbfb231d881b62315f0c412b2d25b5a018707 (patch) | |
tree | cc48168dcfa179884d285e51f686bbd9584d12b1 | |
parent | 18043cc979ad156f33323a147175db37bc40344a (diff) | |
parent | 221ca84aaf17360ba2604f7699832580ca3caf2f (diff) | |
download | AntennaPod-340fbfb231d881b62315f0c412b2d25b5a018707.zip |
Merge pull request #2666 from orionlee/mark_as_seen_in_context_menu_2580
Expose "Mark as seen" as a context menu item in Episodes screen
5 files changed, 55 insertions, 33 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index 33b61b916..9739b999b 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -295,6 +295,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR } }; FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, null); + + contextMenuInterface.setItemVisibility(R.id.mark_as_seen_item, item.isNew()); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index f3846c8a4..497891dbd 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -4,6 +4,8 @@ import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.LinearLayoutManager; @@ -36,12 +38,12 @@ import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; @@ -284,6 +286,16 @@ public class AllEpisodesFragment extends Fragment { return super.onContextItemSelected(item); } + // Mark as seen contains UI logic specific to All/New/FavoriteSegments, + // e.g., Undo with Snackbar, + // and is handled by this class rather than the generic FeedItemMenuHandler + // Undo is useful for Mark as seen, given there is no UI to undo it otherwise, + // i.e., there is context menu item for Mark as new + if (R.id.mark_as_seen_item == item.getItemId()) { + markItemAsSeenWithUndo(selectedItem); + return true; + } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } @@ -481,4 +493,36 @@ public class AllEpisodesFragment extends Fragment { return DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT); } + void markItemAsSeenWithUndo(FeedItem item) { + if (item == null) { + return; + } + + Log.d(TAG, "markItemAsSeenWithUndo(" + item.getId() + ")"); + if (subscription != null) { + subscription.unsubscribe(); + } + // we're marking it as unplayed since the user didn't actually play it + // but they don't want it considered 'NEW' anymore + DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId()); + + final Handler h = new Handler(getActivity().getMainLooper()); + final Runnable r = () -> { + FeedMedia media = item.getMedia(); + if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) { + DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId()); + } + }; + + Snackbar snackbar = Snackbar.make(getView(), getString(R.string.marked_as_seen_label), + Snackbar.LENGTH_LONG); + snackbar.setAction(getString(R.string.undo), v -> { + DBWriter.markItemPlayed(FeedItem.NEW, item.getId()); + // don't forget to cancel the thing that's going to remove the media + h.removeCallbacks(r); + }); + snackbar.show(); + h.postDelayed(r, (int)Math.ceil(snackbar.getDuration() * 1.05f)); + } + } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index c136eb6ae..6695ba427 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -1,8 +1,6 @@ package de.danoeh.antennapod.fragment; import android.os.Bundle; -import android.os.Handler; -import android.support.design.widget.Snackbar; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log; @@ -16,10 +14,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter; import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; @@ -74,33 +69,7 @@ public class NewEpisodesFragment extends AllEpisodesFragment { @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)viewHolder; - - Log.d(TAG, "remove(" + holder.getItemId() + ")"); - if (subscription != null) { - subscription.unsubscribe(); - } - FeedItem item = holder.getFeedItem(); - // we're marking it as unplayed since the user didn't actually play it - // but they don't want it considered 'NEW' anymore - DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId()); - - final Handler h = new Handler(getActivity().getMainLooper()); - final Runnable r = () -> { - FeedMedia media = item.getMedia(); - if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) { - DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId()); - } - }; - - Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_seen_label), - Snackbar.LENGTH_LONG); - snackbar.setAction(getString(R.string.undo), v -> { - DBWriter.markItemPlayed(FeedItem.NEW, item.getId()); - // don't forget to cancel the thing that's going to remove the media - h.removeCallbacks(r); - }); - snackbar.show(); - h.postDelayed(r, (int)Math.ceil(snackbar.getDuration() * 1.05f)); + markItemAsSeenWithUndo(holder.getFeedItem()); } @Override diff --git a/app/src/main/res/menu/allepisodes_context.xml b/app/src/main/res/menu/allepisodes_context.xml index 7398b9118..28493c5b6 100644 --- a/app/src/main/res/menu/allepisodes_context.xml +++ b/app/src/main/res/menu/allepisodes_context.xml @@ -7,6 +7,12 @@ android:menuCategory="container" android:title="@string/skip_episode_label" /> + + <item + android:id="@+id/mark_as_seen_item" + android:menuCategory="container" + android:title="@string/mark_as_seen_label" /> + <item android:id="@+id/mark_read_item" android:menuCategory="container" diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 244a69861..b91c07648 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -166,6 +166,7 @@ <string name="delete_label">Delete</string> <string name="delete_failed">Unable to delete file. Rebooting the device could help.</string> <string name="remove_episode_lable">Remove Episode</string> + <string name="mark_as_seen_label">Mark as seen</string> <string name="marked_as_seen_label">Marked as seen</string> <string name="mark_read_label">Mark as played</string> <string name="marked_as_read_label">Marked as played</string> |