fix contact long click crash
This commit is contained in:
parent
379300bf02
commit
3f8874361b
|
@ -1285,10 +1285,18 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
|
||||
public static class MyListFragment extends SwipeRefreshListFragment {
|
||||
private AdapterView.OnItemClickListener mOnItemClickListener;
|
||||
private int mResContextMenu;
|
||||
private int mResContextMenuConference;
|
||||
private int mResContextMenuContact;
|
||||
|
||||
public void setContextMenu(final int res) {
|
||||
this.mResContextMenu = res;
|
||||
private boolean itemsFromContacts;
|
||||
|
||||
public void setContextMenu(final int resConference, final int resContact) {
|
||||
this.mResContextMenuConference = resConference;
|
||||
this.mResContextMenuContact = resContact;
|
||||
}
|
||||
|
||||
public void setItemsFromContacts(boolean itemsFromContacts) {
|
||||
this.itemsFromContacts = itemsFromContacts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1338,17 +1346,42 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
activity.getMenuInflater().inflate(mResContextMenu, menu);
|
||||
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||
if (mResContextMenu == R.menu.conference_context) {
|
||||
activity.conference_context_id = acmi.position;
|
||||
final Bookmark bookmark = (Bookmark) activity.conferences.get(acmi.position);
|
||||
|
||||
int position;
|
||||
|
||||
if (menuInfo instanceof AdapterContextMenuInfo) {
|
||||
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||
position = acmi.position;
|
||||
} else {
|
||||
final ExpandableListView.ExpandableListContextMenuInfo acmi = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
|
||||
position = (int) acmi.targetView.getTag(R.id.TAG_POSITION);
|
||||
}
|
||||
|
||||
int resContextMenu;
|
||||
|
||||
ListItem item = activity.contacts.get(position);
|
||||
if (itemsFromContacts) {
|
||||
if (item instanceof Bookmark) {
|
||||
resContextMenu = mResContextMenuConference;
|
||||
} else {
|
||||
resContextMenu = mResContextMenuContact;
|
||||
}
|
||||
} else {
|
||||
resContextMenu = mResContextMenuConference;
|
||||
}
|
||||
|
||||
activity.getMenuInflater().inflate(resContextMenu, menu);
|
||||
|
||||
|
||||
if (resContextMenu == R.menu.conference_context) {
|
||||
activity.conference_context_id = position;
|
||||
final Bookmark bookmark = (Bookmark) item;
|
||||
final Conversation conversation = bookmark.getConversation();
|
||||
final MenuItem share = menu.findItem(R.id.context_share_uri);
|
||||
share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
|
||||
} else if (mResContextMenu == R.menu.contact_context) {
|
||||
activity.contact_context_id = acmi.position;
|
||||
final Contact contact = (Contact) activity.contacts.get(acmi.position);
|
||||
} else if (resContextMenu == R.menu.contact_context) {
|
||||
activity.contact_context_id = position;
|
||||
final Contact contact = (Contact) item;
|
||||
final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
|
||||
final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
|
||||
final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
|
||||
|
@ -1463,11 +1496,13 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
final MyListFragment listFragment = new MyListFragment();
|
||||
if (position == 1) {
|
||||
listFragment.setListAdapter(mConferenceAdapter);
|
||||
listFragment.setContextMenu(R.menu.conference_context);
|
||||
listFragment.setContextMenu(R.menu.conference_context, R.menu.contact_context);
|
||||
listFragment.setItemsFromContacts(false);
|
||||
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
|
||||
} else {
|
||||
listFragment.setListAdapter(mContactsAdapter);
|
||||
listFragment.setContextMenu(R.menu.contact_context);
|
||||
listFragment.setContextMenu(R.menu.conference_context, R.menu.contact_context);
|
||||
listFragment.setItemsFromContacts(true);
|
||||
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
|
||||
if (QuickConversationsService.isQuicksy()) {
|
||||
listFragment.setOnRefreshListener(StartConversationActivity.this);
|
||||
|
@ -1772,7 +1807,10 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
|||
@Override
|
||||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
||||
ListItem item = getChildsList(groupPosition).get(childPosition);
|
||||
return super.getView(super.getPosition(item), convertView, parent);
|
||||
int position = super.getPosition(item);
|
||||
View view = super.getView(super.getPosition(item), convertView, parent);
|
||||
view.setTag(R.id.TAG_POSITION, position);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
<item type="id" name="TAG_FINGERPRINT_STATUS"/>
|
||||
<item type="id" name="TAG_AUDIO_PLAYER_VIEW_HOLDER"/>
|
||||
<item type="id" name="TAG_DRAGGABLE"/>
|
||||
<item type="id" name="TAG_POSITION"/>
|
||||
</resources>
|
Loading…
Reference in a new issue