diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java | 116 |
1 files changed, 65 insertions, 51 deletions
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 aa5987912..dc338e02c 100644 --- a/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java @@ -1,9 +1,13 @@ package de.pixart.messenger.ui.util; +import android.app.Activity; +import android.preference.PreferenceManager; import android.support.v7.app.AlertDialog; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.TypefaceSpan; import android.view.Menu; import android.view.MenuItem; -import android.widget.Toast; import de.pixart.messenger.Config; import de.pixart.messenger.R; @@ -12,66 +16,67 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.MucOptions.User; import de.pixart.messenger.services.XmppConnectionService; +import de.pixart.messenger.ui.ConferenceDetailsActivity; +import de.pixart.messenger.ui.ConversationFragment; +import de.pixart.messenger.ui.ConversationsActivity; import de.pixart.messenger.ui.XmppActivity; import rocks.xmpp.addr.Jid; public final class MucDetailsContextMenuHelper { - public static void configureMucDetailsContextMenu(Menu menu, Conversation conversation, MucOptions.User user, boolean advancedMode) { - if (user != null) { - if (user.getRealJid() != null) { - MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); - MenuItem startConversation = menu.findItem(R.id.start_conversation); - MenuItem giveMembership = menu.findItem(R.id.give_membership); - MenuItem removeMembership = menu.findItem(R.id.remove_membership); - MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges); - MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges); - MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room); - MenuItem banFromConference = menu.findItem(R.id.ban_from_conference); - MenuItem invite = menu.findItem(R.id.invite); - startConversation.setVisible(true); - final Contact contact = user.getContact(); - final User self = conversation.getMucOptions().getSelf(); - if (contact != null && contact.showInRoster()) { - showContactDetails.setVisible(!contact.isSelf()); - } - if (user.getRole() == MucOptions.Role.NONE) { - invite.setVisible(true); - } - if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && - self.getAffiliation().outranks(user.getAffiliation())) { - if (advancedMode) { - if (user.getAffiliation() == MucOptions.Affiliation.NONE) { - giveMembership.setVisible(true); - } else { - removeMembership.setVisible(true); - } - if (!Config.DISABLE_BAN) { - banFromConference.setVisible(true); - } + public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) { + final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); + if (user != null && user.getRealJid() != null) { + MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); + MenuItem startConversation = menu.findItem(R.id.start_conversation); + MenuItem giveMembership = menu.findItem(R.id.give_membership); + MenuItem removeMembership = menu.findItem(R.id.remove_membership); + MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges); + MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges); + MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room); + MenuItem banFromConference = menu.findItem(R.id.ban_from_conference); + MenuItem invite = menu.findItem(R.id.invite); + startConversation.setVisible(true); + final Contact contact = user.getContact(); + final User self = conversation.getMucOptions().getSelf(); + if (contact != null && contact.showInRoster()) { + showContactDetails.setVisible(!contact.isSelf()); + } + if (activity instanceof ConferenceDetailsActivity && user.getRole() == MucOptions.Role.NONE) { + invite.setVisible(true); + } + if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && + self.getAffiliation().outranks(user.getAffiliation())) { + if (advancedMode) { + if (user.getAffiliation() == MucOptions.Affiliation.NONE) { + giveMembership.setVisible(true); } else { - if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) { - removeFromRoom.setVisible(true); - } + removeMembership.setVisible(true); } - if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) { - giveAdminPrivileges.setVisible(true); - } else { - removeAdminPrivileges.setVisible(true); + if (!Config.DISABLE_BAN) { + banFromConference.setVisible(true); + } + } else { + if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) { + removeFromRoom.setVisible(true); } } - } else { - MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); - sendPrivateMessage.setVisible(true); - sendPrivateMessage.setEnabled(user.getRole().ranks(MucOptions.Role.VISITOR)); + if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) { + giveAdminPrivileges.setVisible(true); + } else { + removeAdminPrivileges.setVisible(true); + } } } else { + final MucOptions mucOptions = conversation.getMucOptions(); MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); sendPrivateMessage.setVisible(true); - sendPrivateMessage.setEnabled(false); + sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); } } - public static boolean onContextItemSelected(MenuItem item, User user, Conversation conversation, XmppActivity activity, XmppConnectionService.OnAffiliationChanged onAffiliationChanged, XmppConnectionService.OnRoleChanged onRoleChanged) { + public static boolean onContextItemSelected(MenuItem item, User user, Conversation conversation, XmppActivity activity) { + final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null; + final XmppConnectionService.OnRoleChanged onRoleChanged = activity instanceof XmppConnectionService.OnRoleChanged ? (XmppConnectionService.OnRoleChanged) activity : null; Jid jid = user.getRealJid(); switch (item.getItemId()) { case R.id.action_contact_details: @@ -105,11 +110,14 @@ public final class MucDetailsContextMenuHelper { } return true; case R.id.send_private_message: - if (conversation.getMucOptions().allowPm()) { - activity.privateMsgInMuc(conversation, user.getName()); - } else { - Toast.makeText(activity, R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show(); + if (activity instanceof ConversationsActivity) { + ConversationFragment conversationFragment = ConversationFragment.get(activity); + if (conversationFragment != null) { + conversationFragment.privateMessageWith(user.getFullJid()); + return true; + } } + activity.privateMsgInMuc(conversation, user.getName()); return true; case R.id.invite: activity.xmppConnectionService.directInvite(conversation, jid); @@ -128,7 +136,13 @@ public final class MucDetailsContextMenuHelper { } else { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.ban_from_conference); - builder.setMessage(activity.getString(R.string.removing_from_public_conference, user.getName())); + String jid = user.getRealJid().asBareJid().toString(); + SpannableString message = new SpannableString(activity.getString(R.string.removing_from_public_conference, jid)); + int start = message.toString().indexOf(jid); + if (start >= 0) { + message.setSpan(new TypefaceSpan("monospace"), start, start + jid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + builder.setMessage(message); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.ban_now, (dialog, which) -> { activity.xmppConnectionService.changeAffiliationInConference(conversation, user.getRealJid(), MucOptions.Affiliation.OUTCAST, onAffiliationChanged); |