fix user in textselection quotes

This commit is contained in:
Christian Schneppe 2019-11-17 20:17:54 +01:00
parent c0c45b4eab
commit 6690201ede
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
3 changed files with 28 additions and 15 deletions

View file

@ -1177,13 +1177,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList); messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
messageListAdapter.setOnContactPictureClicked(this); messageListAdapter.setOnContactPictureClicked(this);
messageListAdapter.setOnContactPictureLongClicked(this); messageListAdapter.setOnContactPictureLongClicked(this);
messageListAdapter.setOnQuoteListener(text -> quoteText(text, getUsername(selectedMessage))); messageListAdapter.setOnQuoteListener(ConversationFragment.this::quoteText);
binding.messagesView.setAdapter(messageListAdapter); binding.messagesView.setAdapter(messageListAdapter);
registerForContextMenu(binding.messagesView); registerForContextMenu(binding.messagesView);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
this.binding.textinput.setCustomInsertionActionModeCallback(new EditMessageActionModeCallback(this.binding.textinput)); this.binding.textinput.setCustomInsertionActionModeCallback(new EditMessageActionModeCallback(this.binding.textinput));
} }
return binding.getRoot(); return binding.getRoot();
} }
@ -3152,7 +3151,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
popupMenu.show(); popupMenu.show();
} }
private String getUsername(Message message) { public String getUsername(Message message) {
if (message == null) {
return null;
}
String user; String user;
try { try {
final Contact contact = message.getContact(); final Contact contact = message.getContact();

View file

@ -7,7 +7,6 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Editable; import android.text.Editable;
@ -83,7 +82,6 @@ import de.pixart.messenger.utils.Emoticons;
import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.RichPreview; import de.pixart.messenger.utils.RichPreview;
import de.pixart.messenger.utils.StylingHelper; import de.pixart.messenger.utils.StylingHelper;
import de.pixart.messenger.utils.ThemeHelper;
import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.mam.MamReference; import de.pixart.messenger.xmpp.mam.MamReference;
import pl.droidsonroids.gif.GifImageView; import pl.droidsonroids.gif.GifImageView;
@ -99,7 +97,7 @@ import static de.pixart.messenger.ui.util.MyLinkify.replaceYoutube;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler { public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
ConversationFragment mConversationFragment; private ConversationFragment mConversationFragment;
public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR"; public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR";
private static final int SENT = 0; private static final int SENT = 0;
@ -217,6 +215,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
String filesize = null; String filesize = null;
String info = null; String info = null;
boolean error = false; boolean error = false;
viewHolder.user.setText(UIHelper.getMessageDisplayName(message));
if (viewHolder.indicatorReceived != null) { if (viewHolder.indicatorReceived != null) {
viewHolder.indicatorReceived.setVisibility(View.GONE); viewHolder.indicatorReceived.setVisibility(View.GONE);
viewHolder.indicatorRead.setVisibility(View.GONE); viewHolder.indicatorRead.setVisibility(View.GONE);
@ -965,6 +964,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.gifImage = view.findViewById(R.id.message_image_gif); viewHolder.gifImage = view.findViewById(R.id.message_image_gif);
viewHolder.richlinkview = view.findViewById(R.id.richLinkView); viewHolder.richlinkview = view.findViewById(R.id.richLinkView);
viewHolder.messageBody = view.findViewById(R.id.message_body); viewHolder.messageBody = view.findViewById(R.id.message_body);
viewHolder.user = view.findViewById(R.id.message_user);
viewHolder.time = view.findViewById(R.id.message_time); viewHolder.time = view.findViewById(R.id.message_time);
viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
viewHolder.indicatorRead = view.findViewById(R.id.indicator_read); viewHolder.indicatorRead = view.findViewById(R.id.indicator_read);
@ -981,6 +981,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.gifImage = view.findViewById(R.id.message_image_gif); viewHolder.gifImage = view.findViewById(R.id.message_image_gif);
viewHolder.richlinkview = view.findViewById(R.id.richLinkView); viewHolder.richlinkview = view.findViewById(R.id.richLinkView);
viewHolder.messageBody = view.findViewById(R.id.message_body); viewHolder.messageBody = view.findViewById(R.id.message_body);
viewHolder.user = view.findViewById(R.id.message_user);
viewHolder.time = view.findViewById(R.id.message_time); viewHolder.time = view.findViewById(R.id.message_time);
viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
viewHolder.encryption = view.findViewById(R.id.message_encryption); viewHolder.encryption = view.findViewById(R.id.message_encryption);
@ -995,7 +996,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
throw new AssertionError("Unknown view type"); throw new AssertionError("Unknown view type");
} }
if (viewHolder.messageBody != null) { if (viewHolder.messageBody != null) {
listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody)); listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody, viewHolder.user));
viewHolder.messageBody.setCopyHandler(this); viewHolder.messageBody.setCopyHandler(this);
} }
view.setTag(viewHolder); view.setTag(viewHolder);
@ -1279,7 +1280,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
public interface OnQuoteListener { public interface OnQuoteListener {
void onQuote(String text); void onQuote(String text, String user);
} }
public interface OnContactPictureClicked { public interface OnContactPictureClicked {
@ -1306,6 +1307,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
protected ImageView indicatorRead; protected ImageView indicatorRead;
protected TextView time; protected TextView time;
protected CopyTextView messageBody; protected CopyTextView messageBody;
protected TextView user;
protected ImageView contact_picture; protected ImageView contact_picture;
protected TextView status_message; protected TextView status_message;
protected TextView encryption; protected TextView encryption;
@ -1313,10 +1315,12 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private class MessageBodyActionModeCallback implements ActionMode.Callback { private class MessageBodyActionModeCallback implements ActionMode.Callback {
private final TextView textView; private final TextView messageBody;
private final TextView messageUser;
public MessageBodyActionModeCallback(TextView textView) { public MessageBodyActionModeCallback(TextView messgebody, TextView user) {
this.textView = textView; this.messageBody = messgebody;
this.messageUser = user;
} }
@Override @Override
@ -1338,12 +1342,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == android.R.id.button1) { if (item.getItemId() == android.R.id.button1) {
int start = textView.getSelectionStart(); int start = messageBody.getSelectionStart();
int end = textView.getSelectionEnd(); int end = messageBody.getSelectionEnd();
if (end > start) { if (end > start) {
String text = transformText(textView.getText(), start, end, false); String text = transformText(messageBody.getText(), start, end, false);
String user = messageUser.getText().toString();
if (onQuoteListener != null) { if (onQuoteListener != null) {
onQuoteListener.onQuote(text); onQuoteListener.onQuote(text, user);
} }
mode.finish(); mode.finish();
} }

View file

@ -10,6 +10,12 @@
android:longClickable="true" android:longClickable="true"
android:textAppearance="@style/TextAppearance.Conversations.Body1" /> android:textAppearance="@style/TextAppearance.Conversations.Body1" />
<TextView
android:id="@+id/message_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<de.pixart.messenger.ui.widget.RichLinkView <de.pixart.messenger.ui.widget.RichLinkView
android:id="@+id/richLinkView" android:id="@+id/richLinkView"
android:layout_width="wrap_content" android:layout_width="wrap_content"