show context menu when long clicking avatar in 1:1

This commit is contained in:
Daniel Gultsch 2018-12-04 12:23:14 +01:00
parent 875810e1c7
commit c01bd38d00
2 changed files with 94 additions and 54 deletions

View file

@ -119,7 +119,7 @@ import static eu.siacs.conversations.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSAT
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
public class ConversationFragment extends XmppFragment implements EditMessage.KeyboardListener { public class ConversationFragment extends XmppFragment implements EditMessage.KeyboardListener, MessageAdapter.OnContactPictureLongClicked, MessageAdapter.OnContactPictureClicked {
public static final int REQUEST_SEND_MESSAGE = 0x0201; public static final int REQUEST_SEND_MESSAGE = 0x0201;
@ -997,59 +997,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
mediaPreviewAdapter = new MediaPreviewAdapter(this); mediaPreviewAdapter = new MediaPreviewAdapter(this);
binding.mediaPreview.setAdapter(mediaPreviewAdapter); binding.mediaPreview.setAdapter(mediaPreviewAdapter);
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList); messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
messageListAdapter.setOnContactPictureClicked(message -> { messageListAdapter.setOnContactPictureClicked(this);
String fingerprint; messageListAdapter.setOnContactPictureLongClicked(this);
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
if (received) {
if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
Jid tcp = message.getTrueCounterpart();
Jid user = message.getCounterpart();
if (user != null && !user.isBareJid()) {
final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions();
if (mucOptions.participating() || ((Conversation) message.getConversation()).getNextCounterpart() != null) {
if (!mucOptions.isUserInRoom(user) && mucOptions.findUserByRealJid(tcp == null ? null : tcp.asBareJid()) == null) {
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
}
highlightInConference(user.getResource());
} else {
Toast.makeText(getActivity(), R.string.you_are_not_participating, Toast.LENGTH_SHORT).show();
}
}
return;
} else {
if (!message.getContact().isSelf()) {
activity.switchToContactDetails(message.getContact(), fingerprint);
return;
}
}
}
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
});
messageListAdapter.setOnContactPictureLongClicked((v, message) -> {
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
Jid tcp = message.getTrueCounterpart();
Jid cp = message.getCounterpart();
if (cp != null && !cp.isBareJid()) {
User userByRealJid = tcp != null ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp) : null;
final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp);
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
popupMenu.inflate(R.menu.muc_details_context);
final Menu menu = popupMenu.getMenu();
MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, conversation, user);
popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, conversation, activity));
popupMenu.show();
}
}
} else {
activity.showQrCode(conversation.getAccount().getShareableUri());
}
});
messageListAdapter.setOnQuoteListener(this::quoteText); messageListAdapter.setOnQuoteListener(this::quoteText);
binding.messagesView.setAdapter(messageListAdapter); binding.messagesView.setAdapter(messageListAdapter);
@ -2751,4 +2700,86 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public Conversation getConversation() { public Conversation getConversation() {
return conversation; return conversation;
} }
@Override
public void onContactPictureLongClicked(View v, final Message message) {
if (message.getStatus() <= Message.STATUS_RECEIVED) {
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
final Jid cp = message.getCounterpart();
if (cp == null || cp.isBareJid()) {
return;
}
Jid tcp = message.getTrueCounterpart();
User userByRealJid = tcp != null ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp) : null;
final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp);
popupMenu.inflate(R.menu.muc_details_context);
final Menu menu = popupMenu.getMenu();
MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, conversation, user);
popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, conversation, activity));
} else {
final Contact contact = message.getContact();
if (contact.isSelf()) {
activity.showQrCode(conversation.getAccount().getShareableUri());
return;
}
popupMenu.inflate(R.menu.one_on_one_context);
popupMenu.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.action_contact_details:
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
activity.switchToContactDetails(message.getContact(), fingerprint);
break;
case R.id.action_show_qr_code:
activity.showQrCode("xmpp:" + message.getContact().getJid().asBareJid().toEscapedString());
break;
}
return true;
});
}
popupMenu.show();
} else {
activity.showQrCode(conversation.getAccount().getShareableUri());
}
}
@Override
public void onContactPictureClicked(Message message) {
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
if (received) {
if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
Jid tcp = message.getTrueCounterpart();
Jid user = message.getCounterpart();
if (user != null && !user.isBareJid()) {
final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions();
if (mucOptions.participating() || ((Conversation) message.getConversation()).getNextCounterpart() != null) {
if (!mucOptions.isUserInRoom(user) && mucOptions.findUserByRealJid(tcp == null ? null : tcp.asBareJid()) == null) {
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
}
highlightInConference(user.getResource());
} else {
Toast.makeText(getActivity(), R.string.you_are_not_participating, Toast.LENGTH_SHORT).show();
}
}
return;
} else {
if (!message.getContact().isSelf()) {
activity.switchToContactDetails(message.getContact(), fingerprint);
return;
}
}
}
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
}
} }

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_contact_details"
android:title="@string/action_contact_details"/>
<item
android:id="@+id/action_show_qr_code"
android:title="@string/show_qr_code"/>
</menu>