Added extended menu option, ignore long-press in itemlist

This commit is contained in:
daniel oeh 2013-01-21 23:08:39 +01:00
parent 825ccd28c1
commit 5221f5f5ec
3 changed files with 29 additions and 14 deletions

View File

@ -140,7 +140,7 @@ public class ItemviewActivity extends SherlockFragmentActivity {
public void setItemVisibility(int id, boolean visible) {
menu.findItem(id).setVisible(visible);
}
}, item);
}, item, true);
}
}

View File

@ -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;
}

View File

@ -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);
}