From 814b5443205e1755ecd76dac0a7f37e89b3d1137 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 17 Sep 2017 20:25:58 +0200 Subject: show block menu after long press on allow/add back --- .../pixart/messenger/ui/ConversationFragment.java | 67 ++++++++++++++-------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'src/main/java/de/pixart/messenger/ui') diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 7832470a4..29862861c 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -975,32 +975,36 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } }; + private void showBlockSubmenu(View view) { + final Jid jid = conversation.getJid(); + if (jid.isDomainJid()) { + BlockContactDialog.show(activity, conversation); + } else { + PopupMenu popupMenu = new PopupMenu(activity, view); + popupMenu.inflate(R.menu.block); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + Blockable blockable; + switch (menuItem.getItemId()) { + case R.id.block_domain: + blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid()); + break; + default: + blockable = conversation; + } + BlockContactDialog.show(activity, blockable); + return true; + } + }); + popupMenu.show(); + } + } + private OnClickListener mBlockClickListener = new OnClickListener() { @Override public void onClick(final View view) { - final Jid jid = conversation.getJid(); - if (jid.isDomainJid()) { - BlockContactDialog.show(activity, conversation); - } else { - PopupMenu popupMenu = new PopupMenu(activity, view); - popupMenu.inflate(R.menu.block); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - Blockable blockable; - switch (menuItem.getItemId()) { - case R.id.block_domain: - blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid()); - break; - default: - blockable = conversation; - } - BlockContactDialog.show(activity, blockable); - return true; - } - }); - popupMenu.show(); - } + showBlockSubmenu(view); } }; @@ -1016,6 +1020,14 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } }; + private View.OnLongClickListener mLongPressBlockListener = new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + showBlockSubmenu(v); + return true; + } + }; + private OnClickListener mAllowPresenceSubscription = new OnClickListener() { @Override public void onClick(View v) { @@ -1051,9 +1063,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } else if (conversation.isBlocked()) { showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener); } else if (!contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { - showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener); + showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener, this.mLongPressBlockListener); } else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { - showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription); + showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription, this.mLongPressBlockListener); } else if (mode == Conversation.MODE_MULTI && !conversation.getMucOptions().online() && account.getStatus() == Account.State.ONLINE) { @@ -1355,6 +1367,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } protected void showSnackbar(final int message, final int action, final OnClickListener clickListener) { + showSnackbar(message, action, clickListener, null); + } + + protected void showSnackbar(final int message, final int action, final OnClickListener clickListener, final View.OnLongClickListener longClickListener) { snackbar.setVisibility(View.VISIBLE); snackbar.setOnClickListener(null); snackbarMessage.setText(message); @@ -1364,6 +1380,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa snackbarAction.setText(action); } snackbarAction.setOnClickListener(clickListener); + snackbarAction.setOnLongClickListener(longClickListener); } protected void hideSnackbar() { -- cgit v1.2.3