diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-27 15:45:31 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-27 15:45:50 +0100 |
commit | dce424376f0df3e935ed610e292b2a4f6d5f9c2a (patch) | |
tree | 4e60fa88c9b233b9d4b88a92934773c4334f9a1b /src/main | |
parent | 6286dd6e112a94f6bc975008ea62d38833aec625 (diff) |
show context menu when long pressing own account picture
Diffstat (limited to 'src/main')
3 files changed, 42 insertions, 19 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 6815e11ec..1592f9d94 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -91,6 +91,7 @@ import de.pixart.messenger.entities.TransferablePlaceholder; import de.pixart.messenger.http.HttpDownloadConnection; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.MessageArchiveService; +import de.pixart.messenger.services.QuickConversationsService; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.adapter.MediaPreviewAdapter; import de.pixart.messenger.ui.adapter.MessageAdapter; @@ -109,6 +110,7 @@ import de.pixart.messenger.ui.util.SendButtonTool; import de.pixart.messenger.ui.util.ShareUtil; import de.pixart.messenger.ui.util.ViewUtil; import de.pixart.messenger.ui.widget.EditMessage; +import de.pixart.messenger.utils.AccountUtils; import de.pixart.messenger.utils.Compatibility; import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.MenuDoubleTabUtil; @@ -3088,36 +3090,32 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public void onContactPictureLongClicked(View v, final Message message) { - if (message.getStatus() <= Message.STATUS_RECEIVED) { - final PopupMenu popupMenu = new PopupMenu(getActivity(), v); + final String fingerprint; + if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + fingerprint = "pgp"; + } else { + fingerprint = message.getFingerprint(); + } + final PopupMenu popupMenu = new PopupMenu(getActivity(), v); + final Contact contact = message.getContact(); + if (message.getStatus() <= Message.STATUS_RECEIVED || (contact != null && contact.isSelf())) { 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 Jid tcp = message.getTrueCounterpart(); + final 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, activity)); + popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, activity, fingerprint)); } 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: @@ -3127,10 +3125,22 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return true; }); } - popupMenu.show(); } else { - activity.showQrCode(conversation.getAccount().getShareableUri()); + popupMenu.inflate(R.menu.account_context); + final Menu menu = popupMenu.getMenu(); + popupMenu.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_show_qr_code: + activity.showQrCode(conversation.getAccount().getShareableUri()); + break; + case R.id.action_account_details: + activity.switchToAccount(message.getConversation().getAccount(), fingerprint); + break; + } + return true; + }); } + popupMenu.show(); } @Override diff --git a/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java index e154fda94..a33d7c5c3 100644 --- a/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java @@ -107,6 +107,10 @@ public final class MucDetailsContextMenuHelper { } public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity) { + return onContextItemSelected(item, user, activity, null); + } + + public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity, final String fingerprint) { final Conversation conversation = user.getConversation(); final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null; final XmppConnectionService.OnRoleChanged onRoleChanged = activity instanceof XmppConnectionService.OnRoleChanged ? (XmppConnectionService.OnRoleChanged) activity : null; @@ -115,7 +119,7 @@ public final class MucDetailsContextMenuHelper { case R.id.action_contact_details: Contact contact = user.getContact(); if (contact != null) { - activity.switchToContactDetails(contact); + activity.switchToContactDetails(contact, fingerprint); } return true; case R.id.start_conversation: diff --git a/src/main/res/menu/account_context.xml b/src/main/res/menu/account_context.xml new file mode 100644 index 000000000..4e591f1eb --- /dev/null +++ b/src/main/res/menu/account_context.xml @@ -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_account_details" + android:title="@string/account_details" /> +<item + android:id="@+id/action_show_qr_code" + android:title="@string/show_qr_code" /> +</menu>
\ No newline at end of file |