summaryrefslogtreecommitdiff
path: root/app/src/main/java/de
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2015-10-10 19:17:49 -0400
committerTom Hennen <tom.hennen@gmail.com>2015-11-03 21:40:02 -0500
commit89bbc8882680fe0f8585d0995495e7ee2a2f8e36 (patch)
tree676c37e680699aace9553ee99ff3572b4b56930a /app/src/main/java/de
parenta02b84d2d213b903aa310e7ab646f872d2740f86 (diff)
downloadAntennaPod-89bbc8882680fe0f8585d0995495e7ee2a2f8e36.zip
replaced context menu with popup menu. still a couple of other issues
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java68
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java91
2 files changed, 71 insertions, 88 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 6963d1745..dc8ade1ca 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java
@@ -3,13 +3,15 @@ package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
@@ -28,10 +30,12 @@ import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.glide.ApGlideSettings;
+import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.fragment.ItemFragment;
+import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
/**
* List adapter for the list of new episodes
@@ -82,6 +86,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
holder.item = null;
holder.mainActivity = mainActivity;
holder.position = -1;
+ // so we can grab this later
+ view.setTag(holder);
return holder;
}
@@ -229,9 +235,58 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
}
};
+ private Menu popupMenu;
+ private final FeedItemMenuHandler.MenuInterface contextMenuInterface = new FeedItemMenuHandler.MenuInterface() {
+ @Override
+ public void setItemVisibility(int id, boolean visible) {
+ if(popupMenu == null) {
+ return;
+ }
+ MenuItem item = popupMenu.findItem(id);
+ if (item != null) {
+ item.setVisible(visible);
+ }
+ }
+ };
+
+ private final boolean showContextMenu(View view) {
+ // Create a PopupMenu, giving it the clicked view for an anchor
+ PopupMenu popup = new PopupMenu(mainActivity, view);
+ Menu menu = popup.getMenu();
+
+ // Inflate our menu resource into the PopupMenu's Menu
+ popup.getMenuInflater().inflate(R.menu.allepisodes_context, popup.getMenu());
+
+ Holder holder = (Holder) view.getTag();
+ FeedItem item = holder.item;
+ if (item == null) {
+ return false;
+ }
- public static class Holder extends RecyclerView.ViewHolder
- implements View.OnClickListener {
+ popupMenu = menu;
+ FeedItemMenuHandler.onPrepareMenu(context, contextMenuInterface, item, true, null);
+
+ // Set a listener so we are notified if a menu item is clicked
+ popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem menuItem) {
+ try {
+ FeedItemMenuHandler.onMenuItemClicked(context, menuItem.getItemId(), item);
+ return true;
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+ });
+
+ popup.show();
+ return true;
+ }
+
+
+ public class Holder extends RecyclerView.ViewHolder
+ implements View.OnClickListener, View.OnLongClickListener{
TextView placeholder;
TextView title;
TextView pubDate;
@@ -248,7 +303,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
public Holder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
- itemView.setOnCreateContextMenuListener(mainActivity);
+ itemView.setOnLongClickListener(this);
}
@Override
@@ -261,6 +316,11 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
public FeedItem getFeedItem() { return item; }
public int getItemPosition() { return position; }
+
+ @Override
+ public boolean onLongClick(View view) {
+ return showContextMenu(view);
+ }
}
public interface ItemAccess {
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 434740af8..b26ce7991 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java
@@ -78,11 +78,8 @@ public class AllEpisodesFragment extends Fragment {
private AllEpisodesRecycleAdapter listAdapter;
private TextView txtvEmpty;
private ProgressBar progLoading;
- private ContextMenu contextMenu;
- private AdapterView.AdapterContextMenuInfo lastMenuInfo = null;
private List<FeedItem> episodes;
- private LongList queuedItemsIds;
private List<Downloader> downloaderList;
private boolean itemsLoaded = false;
@@ -297,7 +294,7 @@ public class AllEpisodesFragment extends Fragment {
txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
progLoading = (ProgressBar) root.findViewById(R.id.progLoading);
- registerForContextMenu(listView);
+ //registerForContextMenu(listView);
if (!itemsLoaded) {
progLoading.setVisibility(View.VISIBLE);
@@ -313,75 +310,6 @@ public class AllEpisodesFragment extends Fragment {
return root;
}
- private final FeedItemMenuHandler.MenuInterface contextMenuInterface = new FeedItemMenuHandler.MenuInterface() {
- @Override
- public void setItemVisibility(int id, boolean visible) {
- if(contextMenu == null) {
- return;
- }
- MenuItem item = contextMenu.findItem(id);
- if (item != null) {
- item.setVisible(visible);
- }
- }
- };
-
- @Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
- super.onCreateContextMenu(menu, v, menuInfo);
- if (menuInfo == null) { return; }
- AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
- FeedItem item = itemAccess.getItem(adapterInfo.position);
- MenuInflater inflater = getActivity().getMenuInflater();
- inflater.inflate(R.menu.allepisodes_context, menu);
-
- if (item != null) {
- menu.setHeaderTitle(item.getTitle());
- }
-
- contextMenu = menu;
- lastMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
- FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queuedItemsIds);
- }
-
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- if (!getUserVisibleHint()) {
- // we're not visible, don't do anything.
- return false;
- }
- AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
- if (menuInfo == null) {
- menuInfo = lastMenuInfo;
- }
- if (menuInfo == null) {
- Log.e(TAG, "menuInfo is null, not doing anything");
- return false;
- }
-
- FeedItem selectedItem = null;
-
- // make sure the item still makes sense
- if (menuInfo.position >= 0 && menuInfo.position < itemAccess.getCount()) {
- selectedItem = itemAccess.getItem(menuInfo.position);
- } else {
- Log.d(TAG, "Selected item at position " + menuInfo.position + " does not exist, only " + itemAccess.getCount() + " items available");
- }
-
- if (selectedItem == null) {
- Log.i(TAG, "Selected item at position " + menuInfo.position + " was null, ignoring selection");
- return super.onContextItemSelected(item);
- }
-
- try {
- return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem);
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
- return true;
- }
- }
-
private void onFragmentLoaded() {
if (listAdapter == null) {
listAdapter = new AllEpisodesRecycleAdapter(activity.get(), activity.get(), itemAccess,
@@ -439,11 +367,10 @@ public class AllEpisodesFragment extends Fragment {
@Override
public boolean isInQueue(FeedItem item) {
- if (itemsLoaded) {
- return queuedItemsIds.contains(item.getId());
- } else {
- return false;
+ if (item != null) {
+ return item.isTagged(FeedItem.TAG_QUEUE);
}
+ return false;
}
};
@@ -478,8 +405,7 @@ public class AllEpisodesFragment extends Fragment {
listView.setVisibility(View.VISIBLE);
progLoading.setVisibility(View.GONE);
if (data != null) {
- episodes = data.first;
- queuedItemsIds = data.second;
+ episodes = data;
itemsLoaded = true;
if (viewsCreated && activity.get() != null) {
onFragmentLoaded();
@@ -490,11 +416,8 @@ public class AllEpisodesFragment extends Fragment {
});
}
- protected Pair<List<FeedItem>,LongList> loadData() {
- List<FeedItem> items;
- items = DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT);
- LongList queuedIds = DBReader.getQueueIDList();
- return Pair.create(items, queuedIds);
+ protected List<FeedItem> loadData() {
+ return DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT);
}
}