Fix context menu
This commit is contained in:
parent
ab0782b456
commit
c876d4b819
|
@ -35,6 +35,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.DateUtils;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.fragment.ItemFragment;
|
||||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||
|
@ -328,8 +329,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||
item1.setVisible(visible);
|
||||
}
|
||||
};
|
||||
FeedItemMenuHandler.onPrepareMenu(mainActivityRef.get(), contextMenuInterface, item, true,
|
||||
null);
|
||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true,
|
||||
itemAccess.getQueueIds(), itemAccess.getFavoritesIds());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -344,6 +345,10 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
|
|||
|
||||
boolean isInQueue(FeedItem item);
|
||||
|
||||
LongList getQueueIds();
|
||||
|
||||
LongList getFavoritesIds();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -183,8 +183,8 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||
item1.setVisible(visible);
|
||||
}
|
||||
};
|
||||
FeedItemMenuHandler.onPrepareMenu(mainActivity.get(), contextMenuInterface, item, true,
|
||||
itemAccess.getQueueIds());
|
||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true,
|
||||
itemAccess.getQueueIds(), itemAccess.getFavoritesIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -351,6 +351,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
|
|||
long getItemDownloadSize(FeedItem item);
|
||||
int getItemDownloadProgressPercent(FeedItem item);
|
||||
LongList getQueueIds();
|
||||
LongList getFavoritesIds();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,6 +46,7 @@ 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;
|
||||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
@ -382,6 +383,34 @@ public class AllEpisodesFragment extends Fragment {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongList getQueueIds() {
|
||||
LongList queueIds = new LongList();
|
||||
if(episodes == null) {
|
||||
return queueIds;
|
||||
}
|
||||
for(FeedItem item : episodes) {
|
||||
if(item.isTagged(FeedItem.TAG_QUEUE)) {
|
||||
queueIds.add(item.getId());
|
||||
}
|
||||
}
|
||||
return queueIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongList getFavoritesIds() {
|
||||
LongList favoritesIds = new LongList();
|
||||
if(episodes == null) {
|
||||
return favoritesIds;
|
||||
}
|
||||
for(FeedItem item : episodes) {
|
||||
if(item.isTagged(FeedItem.TAG_FAVORITE)) {
|
||||
favoritesIds.add(item.getId());
|
||||
}
|
||||
}
|
||||
return favoritesIds;
|
||||
}
|
||||
};
|
||||
|
||||
public void onEventMainThread(FeedItemEvent event) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
|
@ -40,6 +39,7 @@ import de.danoeh.antennapod.activity.MainActivity;
|
|||
import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
|
||||
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;
|
||||
|
@ -95,6 +95,7 @@ public class ItemFragment extends Fragment {
|
|||
private long itemID;
|
||||
private FeedItem item;
|
||||
private LongList queue;
|
||||
private LongList favorites;
|
||||
private String webviewData;
|
||||
private List<Downloader> downloaderList;
|
||||
|
||||
|
@ -249,10 +250,10 @@ public class ItemFragment extends Fragment {
|
|||
inflater.inflate(R.menu.feeditem_options, menu);
|
||||
popupMenu = menu;
|
||||
if (item.hasMedia()) {
|
||||
FeedItemMenuHandler.onPrepareMenu(getActivity(), popupMenuInterface, item, true, queue);
|
||||
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue, favorites);
|
||||
} else {
|
||||
// these are already available via button1 and button2
|
||||
FeedItemMenuHandler.onPrepareMenu(getActivity(), popupMenuInterface, item, true, queue,
|
||||
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue, favorites,
|
||||
R.id.mark_read_item, R.id.visit_website_item);
|
||||
}
|
||||
}
|
||||
|
@ -457,6 +458,12 @@ public class ItemFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(FavoritesEvent event) {
|
||||
if(event.item.getId() == itemID) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(FeedItemEvent event) {
|
||||
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
|
||||
for(FeedItem item : event.items) {
|
||||
|
@ -500,8 +507,9 @@ public class ItemFragment extends Fragment {
|
|||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
item = result.first;
|
||||
queue = result.second;
|
||||
item = (FeedItem) result[0];
|
||||
queue = (LongList) result[1];
|
||||
favorites = (LongList) result[2];
|
||||
if (!itemsLoaded) {
|
||||
itemsLoaded = true;
|
||||
onFragmentLoaded();
|
||||
|
@ -513,14 +521,25 @@ public class ItemFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private Pair<FeedItem,LongList> loadInBackground() {
|
||||
FeedItem data1 = DBReader.getFeedItem(itemID);
|
||||
if (data1 != null) {
|
||||
Timeline t = new Timeline(getActivity(), data1);
|
||||
private Object[] loadInBackground() {
|
||||
FeedItem feedItem = DBReader.getFeedItem(itemID);
|
||||
if (feedItem != null) {
|
||||
Timeline t = new Timeline(getActivity(), feedItem);
|
||||
webviewData = t.processShownotes(false);
|
||||
}
|
||||
LongList data2 = DBReader.getQueueIDList();
|
||||
return Pair.create(data1, data2);
|
||||
LongList queue;
|
||||
if(feedItem.isTagged(FeedItem.TAG_QUEUE)) {
|
||||
queue = LongList.of(feedItem.getId());
|
||||
} else {
|
||||
queue = new LongList(0);
|
||||
}
|
||||
LongList favorites;
|
||||
if(feedItem.isTagged(FeedItem.TAG_FAVORITE)) {
|
||||
favorites = LongList.of(feedItem.getId());
|
||||
} else {
|
||||
favorites = new LongList(0);
|
||||
}
|
||||
return new Object[] { feedItem, queue, favorites };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -568,6 +568,20 @@ public class QueueFragment extends Fragment {
|
|||
public LongList getQueueIds() {
|
||||
return queue != null ? LongList.of(FeedItemUtil.getIds(queue)) : new LongList(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongList getFavoritesIds() {
|
||||
LongList favoritesIds = new LongList();
|
||||
if(queue == null) {
|
||||
return favoritesIds;
|
||||
}
|
||||
for(FeedItem item : queue) {
|
||||
if(item.isTagged(FeedItem.TAG_FAVORITE)) {
|
||||
favoritesIds.add(item.getId());
|
||||
}
|
||||
}
|
||||
return favoritesIds;
|
||||
}
|
||||
};
|
||||
|
||||
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
|
|
|
@ -140,9 +140,13 @@ public class FeedItemMenuHandler {
|
|||
* @param excludeIds Menu item that should be excluded
|
||||
* @return true if selectedItem is not null.
|
||||
*/
|
||||
public static boolean onPrepareMenu(Context context, MenuInterface mi, FeedItem selectedItem,
|
||||
boolean showExtendedMenu, LongList queueAccess, int... excludeIds) {
|
||||
boolean rc = onPrepareMenu(context, mi, selectedItem, showExtendedMenu, queueAccess);
|
||||
public static boolean onPrepareMenu(MenuInterface mi,
|
||||
FeedItem selectedItem,
|
||||
boolean showExtendedMenu,
|
||||
LongList queueAccess,
|
||||
LongList favorites,
|
||||
int... excludeIds) {
|
||||
boolean rc = onPrepareMenu(mi, selectedItem, showExtendedMenu, queueAccess, favorites);
|
||||
if (rc && excludeIds != null) {
|
||||
for (int id : excludeIds) {
|
||||
mi.setItemVisibility(id, false);
|
||||
|
|
Loading…
Reference in New Issue