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