diff options
4 files changed, 81 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 296b1b215..ac88e2870 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -3078,7 +3078,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke 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); + MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, conversation, user, true, getUsername(message)); popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, activity, fingerprint)); } else { popupMenu.inflate(R.menu.one_on_one_context); @@ -3112,6 +3112,32 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke popupMenu.show(); } + private String getUsername(Message message) { + String user; + try { + final Contact contact = message.getContact(); + if (conversation.getMode() == Conversation.MODE_MULTI) { + if (contact != null) { + user = contact.getDisplayName(); + } else { + user = UIHelper.getDisplayedMucCounterpart(message.getCounterpart()); + } + } else { + user = contact != null ? contact.getDisplayName() : null; + } + if (message.getStatus() == Message.STATUS_SEND + || message.getStatus() == Message.STATUS_SEND_FAILED + || message.getStatus() == Message.STATUS_SEND_RECEIVED + || message.getStatus() == Message.STATUS_SEND_DISPLAYED) { + user = getString(R.string.me); + } + } catch (Exception e) { + e.printStackTrace(); + user = null; + } + return user; + } + @Override public void onContactPictureClicked(Message message) { String fingerprint; diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 5e7c5962f..6cff1aebd 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -9,8 +9,10 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; import android.preference.PreferenceManager; + import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; + import android.text.Editable; import android.text.Spannable; import android.text.SpannableString; @@ -1039,16 +1041,14 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } }); - viewHolder.contact_picture - .setOnLongClickListener(v -> { - if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { - MessageAdapter.this.mOnContactPictureLongClickedListener - .onContactPictureLongClicked(v, message); - return true; - } else { - return false; - } - }); + viewHolder.contact_picture.setOnLongClickListener(v -> { + if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { + MessageAdapter.this.mOnContactPictureLongClickedListener.onContactPictureLongClicked(v, message); + return true; + } else { + return false; + } + }); final Transferable transferable = message.getTransferable(); if (message.isFileDeleted() || (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING)) { 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 2abff6973..5a6415d75 100644 --- a/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java @@ -1,16 +1,22 @@ package de.pixart.messenger.ui.util; import android.app.Activity; +import android.graphics.Typeface; import android.preference.PreferenceManager; -import androidx.appcompat.app.AlertDialog; import android.text.SpannableString; +import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.style.ForegroundColorSpan; +import android.text.style.RelativeSizeSpan; +import android.text.style.StyleSpan; import android.text.style.TypefaceSpan; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import androidx.appcompat.app.AlertDialog; + import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Contact; @@ -27,6 +33,8 @@ import rocks.xmpp.addr.Jid; public final class MucDetailsContextMenuHelper { + private static int titleColor = 0xff0091ea; + public static void onCreateContextMenu(ContextMenu menu, View v) { final XmppActivity activity = XmppActivity.find(v); final Object tag = v.getTag(); @@ -48,9 +56,24 @@ public final class MucDetailsContextMenuHelper { } public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) { + configureMucDetailsContextMenu(activity, menu, conversation, user, false, null); + } + + public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user, boolean forceContextMenu, String username) { final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); final MucOptions mucOptions = conversation.getMucOptions(); final boolean isGroupChat = mucOptions.isPrivateAndNonAnonymous(); + MenuItem title = menu.findItem(R.id.title); + if (forceContextMenu && username != null) { + SpannableStringBuilder menuTitle = new SpannableStringBuilder(username); + menuTitle.setSpan(new ForegroundColorSpan(titleColor), 0, menuTitle.length(), 0); + menuTitle.setSpan(new StyleSpan(Typeface.BOLD), 0, menuTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + menuTitle.setSpan(new RelativeSizeSpan(0.875f), 0, menuTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + title.setTitle(menuTitle); + title.setVisible(true); + } else { + title.setVisible(false); + } MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); if (user != null && user.getRealJid() != null) { MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); diff --git a/src/main/res/menu/muc_details_context.xml b/src/main/res/menu/muc_details_context.xml index 44522cf87..22d99268f 100644 --- a/src/main/res/menu/muc_details_context.xml +++ b/src/main/res/menu/muc_details_context.xml @@ -1,62 +1,82 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item + android:id="@+id/title" + android:checkable="false" + android:orderInCategory="1" + android:enabled="false" + android:visible="false" /> + <item android:id="@+id/highlight_in_muc" + android:orderInCategory="100" android:title="@string/highlight_in_muc" android:visible="false" /> <item android:id="@+id/start_conversation" + android:orderInCategory="100" android:title="@string/start_conversation" android:visible="false" /> <item android:id="@+id/action_contact_details" + android:orderInCategory="100" android:title="@string/action_contact_details" android:visible="false" /> <item android:id="@+id/invite" + android:orderInCategory="100" android:title="@string/invite_again" android:visible="false" /> <item android:id="@+id/send_private_message" + android:orderInCategory="100" android:title="@string/send_private_message" android:visible="false" /> <item android:id="@+id/manage_permissions" + android:orderInCategory="100" android:title="@string/manage_permission" android:visible="false"> <menu> <item android:id="@+id/give_membership" + android:orderInCategory="100" android:title="@string/grant_membership" android:visible="false" /> <item android:id="@+id/remove_membership" + android:orderInCategory="100" android:title="@string/remove_membership" android:visible="false" /> <item android:id="@+id/give_admin_privileges" + android:orderInCategory="100" android:title="@string/grant_admin_privileges" android:visible="false" /> <item android:id="@+id/remove_admin_privileges" + android:orderInCategory="100" android:title="@string/remove_admin_privileges" android:visible="false" /> <item android:id="@+id/give_owner_privileges" + android:orderInCategory="100" android:title="@string/grant_owner_privileges" android:visible="false" /> <item android:id="@+id/revoke_owner_privileges" + android:orderInCategory="100" android:title="@string/remove_owner_privileges" android:visible="false" /> </menu> </item> <item android:id="@+id/kick_from_room" + android:orderInCategory="100" android:title="@string/kick_from_room" android:visible="false" /> <item android:id="@+id/ban_from_room" + android:orderInCategory="100" android:title="@string/ban_from_conference" android:visible="false" /> </menu> |