Feed view: Add "Add/Remove to/from Favorites" to context menu
This commit is contained in:
parent
8ffe2caf33
commit
ab0782b456
|
@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -25,6 +25,15 @@
|
|||
android:menuCategory="container"
|
||||
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"
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue