diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-01-21 23:08:39 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-01-21 23:08:39 +0100 |
commit | 5221f5f5eca4176df26114b5da8ed59294b965fc (patch) | |
tree | 75f76e88485aa770584629db13a8ea34172e5fea /src/de | |
parent | 825ccd28c1572c2f49b1bd2c83c78cd76d0e6629 (diff) | |
download | AntennaPod-5221f5f5eca4176df26114b5da8ed59294b965fc.zip |
Added extended menu option, ignore long-press in itemlist
Diffstat (limited to 'src/de')
3 files changed, 29 insertions, 14 deletions
diff --git a/src/de/danoeh/antennapod/activity/ItemviewActivity.java b/src/de/danoeh/antennapod/activity/ItemviewActivity.java index 6cf827f41..668cb3a28 100644 --- a/src/de/danoeh/antennapod/activity/ItemviewActivity.java +++ b/src/de/danoeh/antennapod/activity/ItemviewActivity.java @@ -140,7 +140,7 @@ public class ItemviewActivity extends SherlockFragmentActivity { public void setItemVisibility(int id, boolean visible) { menu.findItem(id).setVisible(visible); } - }, item); + }, item, true); } } diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index 35710f40f..f04fc3824 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -59,6 +59,7 @@ public class ItemlistFragment extends SherlockListFragment { protected static final int NO_SELECTION = -1; protected int selectedPosition = NO_SELECTION; + protected boolean contextMenuClosed = true; /** Argument for FeeditemlistAdapter */ protected boolean showFeedtitle; @@ -194,6 +195,7 @@ public class ItemlistFragment extends SherlockListFragment { if (AppConfig.DEBUG) Log.d(TAG, "adapterCallback; position = " + position); selectedPosition = position; + contextMenuClosed = true; getListView().showContextMenu(); } }; @@ -203,21 +205,17 @@ public class ItemlistFragment extends SherlockListFragment { this.getListView().setItemsCanFocus(true); getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); registerForContextMenu(getListView()); - getListView().setOnItemLongClickListener(new OnItemLongClickListener() { - - @Override - public boolean onItemLongClick(AdapterView<?> arg0, View arg1, - int position, long id) { - adapterCallback.onActionButtonPressed(position); - return true; - } - }); + getListView().setOnItemLongClickListener(null); } @Override public void onCreateContextMenu(final ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); + if (!contextMenuClosed) { // true if context menu was cancelled before + selectedPosition = NO_SELECTION; + } + contextMenuClosed = false; getListView().setOnItemLongClickListener(null); if (selectedPosition != NO_SELECTION) { new MenuInflater(ItemlistFragment.this.getActivity()).inflate( @@ -233,7 +231,7 @@ public class ItemlistFragment extends SherlockListFragment { boolean visible) { menu.findItem(id).setVisible(visible); } - }, selection); + }, selection, false); } } } @@ -261,6 +259,7 @@ public class ItemlistFragment extends SherlockListFragment { } } selectedPosition = NO_SELECTION; + contextMenuClosed = true; return handled; } diff --git a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java index c3d3af495..389814815 100644 --- a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java +++ b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java @@ -37,7 +37,23 @@ public class FeedItemMenuHandler { abstract void setItemVisibility(int id, boolean visible); } - public static boolean onPrepareMenu(MenuInterface mi, FeedItem selectedItem) { + /** + * This method should be called in the prepare-methods of menus. It changes + * the visibility of the menu items depending on a FeedItem's attributes. + * + * @param mi + * An instance of MenuInterface that the method uses to change a + * MenuItem's visibility + * @param selectedItem + * The FeedItem for which the menu is supposed to be prepared + * @param showExtendedMenu + * True if MenuItems that let the user share information about + * the FeedItem and visit its website should be set visible. This + * parameter should be set to false if the menu space is limited. + * @return Always returns true + * */ + public static boolean onPrepareMenu(MenuInterface mi, + FeedItem selectedItem, boolean showExtendedMenu) { FeedManager manager = FeedManager.getInstance(); DownloadRequester requester = DownloadRequester.getInstance(); boolean hasMedia = selectedItem.getMedia() != null; @@ -69,7 +85,7 @@ public class FeedItemMenuHandler { if (!(!isInQueue && selectedItem.getMedia() != null)) { mi.setItemVisibility(R.id.add_to_queue_item, false); } - if (selectedItem.getLink() == null) { + if (!showExtendedMenu || selectedItem.getLink() == null) { mi.setItemVisibility(R.id.share_link_item, false); } @@ -80,7 +96,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.mark_read_item, false); } - if (selectedItem.getLink() == null) { + if (!showExtendedMenu || selectedItem.getLink() == null) { mi.setItemVisibility(R.id.visit_website_item, false); } |