diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-01-21 13:57:21 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-01-21 13:57:21 +0100 |
commit | ab0782b45627d8e2cef5f25afd5c11072c1c616c (patch) | |
tree | b42ab05008262e5dd30ee5a90144baf3639351d5 | |
parent | 8ffe2caf3351d8000454ee6fda884e8ae001be0a (diff) | |
download | AntennaPod-ab0782b45627d8e2cef5f25afd5c11072c1c616c.zip |
Feed view: Add "Add/Remove to/from Favorites" to context menu
4 files changed, 32 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index 97c446fab..7a9b73982 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -10,7 +10,6 @@ import android.graphics.LightingColorFilter; import android.os.Build; import android.os.Bundle; import android.support.v4.app.ListFragment; -import android.support.v4.util.Pair; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.SearchView; import android.util.Log; @@ -48,6 +47,7 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.event.DownloadEvent; import de.danoeh.antennapod.core.event.DownloaderUpdate; +import de.danoeh.antennapod.core.event.FavoritesEvent; import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.EventDistributor; @@ -99,6 +99,7 @@ public class ItemlistFragment extends ListFragment { private long feedID; private Feed feed; private LongList queuedItemsIds; + private LongList favoritedItemsId; private boolean itemsLoaded = false; private boolean viewsCreated = false; @@ -324,7 +325,8 @@ public class ItemlistFragment extends ListFragment { contextMenu = menu; lastMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; - FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queuedItemsIds); + FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds, + favoritedItemsId); } @Override @@ -389,6 +391,11 @@ public class ItemlistFragment extends ListFragment { loadItems(); } + public void onEvent(FavoritesEvent event) { + Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); + loadItems(); + } + public void onEvent(FeedEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); if(event.feedId == feedID) { @@ -626,8 +633,9 @@ public class ItemlistFragment extends ListFragment { .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { if (result != null) { - feed = result.first; - queuedItemsIds = result.second; + feed = (Feed) result[0]; + queuedItemsIds = (LongList) result[1]; + favoritedItemsId = (LongList) result[2]; itemsLoaded = true; if (viewsCreated) { onFragmentLoaded(); @@ -638,14 +646,15 @@ public class ItemlistFragment extends ListFragment { }); } - private Pair<Feed, LongList> loadData() { + private Object[] loadData() { Feed feed = DBReader.getFeed(feedID); if(feed != null && feed.getItemFilter() != null) { FeedItemFilter filter = feed.getItemFilter(); feed.setItems(filter.filter(feed.getItems())); } LongList queuedItemsIds = DBReader.getQueueIDList(); - return Pair.create(feed, queuedItemsIds); + LongList favoritedItemsId = DBReader.getFavoriteIDList(); + return new Object[] { feed, queuedItemsIds, favoritedItemsId }; } } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 0224d2c7e..55f522dfe 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -57,16 +57,16 @@ public class FeedItemMenuHandler { * @param queueAccess Used for testing if the queue contains the selected item * @return Returns true if selectedItem is not null. */ - public static boolean onPrepareMenu(Context context, MenuInterface mi, FeedItem selectedItem, - boolean showExtendedMenu, LongList queueAccess) { + public static boolean onPrepareMenu(MenuInterface mi, + FeedItem selectedItem, + boolean showExtendedMenu, + LongList queueAccess, + LongList favorites) { if (selectedItem == null) { return false; } boolean hasMedia = selectedItem.getMedia() != null; - boolean isPlaying = hasMedia - && selectedItem.getState() == FeedItem.State.PLAYING; - - FeedItem.State state = selectedItem.getState(); + boolean isPlaying = hasMedia && selectedItem.getState() == FeedItem.State.PLAYING; if (!isPlaying) { mi.setItemVisibility(R.id.skip_episode_item, false); @@ -126,7 +126,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.support_item, false); } - boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE); + boolean isFavorite = favorites != null && favorites.contains(selectedItem.getId()); mi.setItemVisibility(R.id.add_to_favorites_item, !isFavorite); mi.setItemVisibility(R.id.remove_from_favorites_item, isFavorite); diff --git a/app/src/main/res/menu/feeditemlist_context.xml b/app/src/main/res/menu/feeditemlist_context.xml index 7b10e5cce..271cb96a7 100644 --- a/app/src/main/res/menu/feeditemlist_context.xml +++ b/app/src/main/res/menu/feeditemlist_context.xml @@ -26,6 +26,15 @@ android:title="@string/remove_from_queue_label" /> <item + android:id="@+id/add_to_favorites_item" + android:menuCategory="container" + android:title="@string/add_to_favorite_label" /> + <item + android:id="@+id/remove_from_favorites_item" + android:menuCategory="container" + android:title="@string/remove_from_favorite_label" /> + + <item android:id="@+id/reset_position" android:menuCategory="container" android:title="@string/reset_position" /> diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 16e65f9f3..bc4c671a2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -408,7 +408,7 @@ public final class DBReader { return items; } - static LongList getFavoriteIDList() { + public static LongList getFavoriteIDList() { Log.d(TAG, "getFavoriteIDList() called"); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); |