From 20e731c95623d9fe9b4dc25564d3107dfbde3033 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 27 Jan 2019 11:38:20 +0100 Subject: [PATCH] show context menu when long pressing own account picture --- .../ui/ConversationFragment.java | 50 ++++++++++++------- .../conversations/ui/EditAccountActivity.java | 1 + .../ui/util/MucDetailsContextMenuHelper.java | 6 ++- src/main/res/menu/account_context.xml | 12 +++++ 4 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/main/res/menu/account_context.xml diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index b345d9fc3..2faa25abe 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -83,6 +83,7 @@ import eu.siacs.conversations.entities.TransferablePlaceholder; import eu.siacs.conversations.http.HttpDownloadConnection; import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.MessageArchiveService; +import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.adapter.MediaPreviewAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter; @@ -102,6 +103,7 @@ import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.util.ShareUtil; import eu.siacs.conversations.ui.util.ViewUtil; import eu.siacs.conversations.ui.widget.EditMessage; +import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.MessageUtils; @@ -2727,36 +2729,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: @@ -2766,10 +2764,26 @@ 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(); + menu.findItem(R.id.action_manage_accounts).setVisible(QuickConversationsService.isConversations()); + 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; + case R.id.action_manage_accounts: + AccountUtils.launchManageAccounts(activity); + break; + } + return true; + }); } + popupMenu.show(); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 472da1cac..d54299fa3 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.ui; import android.app.Activity; import android.app.PendingIntent; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.content.SharedPreferences; diff --git a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java index d864fe643..747a11553 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java @@ -102,6 +102,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; @@ -110,7 +114,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..661fd2ebf --- /dev/null +++ b/src/main/res/menu/account_context.xml @@ -0,0 +1,12 @@ + + + + + +