From 849968107eee1421d5d055bcf746c153b5303744 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 8 Dec 2020 07:08:56 +0100 Subject: [PATCH] remove unused CopyTextView after removing the ability to select and copy text the transformation methods provided by CopyTextView are no longer necessary. --- .../ui/adapter/MessageAdapter.java | 88 +------------------ .../conversations/ui/widget/CopyTextView.java | 58 ------------ src/main/res/layout/message_content.xml | 4 +- 3 files changed, 5 insertions(+), 145 deletions(-) delete mode 100644 src/main/java/eu/siacs/conversations/ui/widget/CopyTextView.java diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index c6287034c..2924a07eb 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -65,7 +65,6 @@ import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.MyLinkify; import eu.siacs.conversations.ui.util.ViewUtil; import eu.siacs.conversations.ui.widget.ClickableMovementMethod; -import eu.siacs.conversations.ui.widget.CopyTextView; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.EmojiWrapper; import eu.siacs.conversations.utils.Emoticons; @@ -77,7 +76,7 @@ import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.mam.MamReference; -public class MessageAdapter extends ArrayAdapter implements CopyTextView.CopyHandler { +public class MessageAdapter extends ArrayAdapter { public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR"; private static final int SENT = 0; @@ -671,9 +670,6 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie default: throw new AssertionError("Unknown view type"); } - if (viewHolder.messageBody != null) { - viewHolder.messageBody.setCopyHandler(this); - } view.setTag(viewHolder); } else { viewHolder = (ViewHolder) view.getTag(); @@ -868,38 +864,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie private void promptOpenKeychainInstall(View view) { activity.showInstallPgpDialog(); } - - private String transformText(CharSequence text, int start, int end, boolean forCopy) { - SpannableStringBuilder builder = new SpannableStringBuilder(text); - Object copySpan = new Object(); - builder.setSpan(copySpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - DividerSpan[] dividerSpans = builder.getSpans(0, builder.length(), DividerSpan.class); - for (DividerSpan dividerSpan : dividerSpans) { - builder.replace(builder.getSpanStart(dividerSpan), builder.getSpanEnd(dividerSpan), - dividerSpan.isLarge() ? "\n\n" : "\n"); - } - start = builder.getSpanStart(copySpan); - end = builder.getSpanEnd(copySpan); - if (start == -1 || end == -1) return ""; - builder = new SpannableStringBuilder(builder, start, end); - if (forCopy) { - QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class); - for (QuoteSpan quoteSpan : quoteSpans) { - builder.insert(builder.getSpanStart(quoteSpan), "> "); - } - } - return builder.toString(); - } - - @Override - public String transformTextForCopy(CharSequence text, int start, int end) { - if (text instanceof Spanned) { - return transformText(text, start, end, true); - } else { - return text.toString().substring(start, end); - } - } - + public FileBackend getFileBackend() { return activity.xmppConnectionService.getFileBackend(); } @@ -969,56 +934,9 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie protected ImageView indicator; protected ImageView indicatorReceived; protected TextView time; - protected CopyTextView messageBody; + protected TextView messageBody; protected ImageView contact_picture; protected TextView status_message; protected TextView encryption; } - - - private class MessageBodyActionModeCallback implements ActionMode.Callback { - - private final TextView textView; - - public MessageBodyActionModeCallback(TextView textView) { - this.textView = textView; - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - if (onQuoteListener != null) { - int quoteResId = activity.getThemeResource(R.attr.icon_quote, R.drawable.ic_action_reply); - // 3rd item is placed after "copy" item - menu.add(0, android.R.id.button1, 3, R.string.quote).setIcon(quoteResId) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - } - return false; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - if (item.getItemId() == android.R.id.button1) { - int start = textView.getSelectionStart(); - int end = textView.getSelectionEnd(); - if (end > start) { - String text = transformText(textView.getText(), start, end, false); - if (onQuoteListener != null) { - onQuoteListener.onQuote(text); - } - mode.finish(); - } - return true; - } - return false; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - } - } } diff --git a/src/main/java/eu/siacs/conversations/ui/widget/CopyTextView.java b/src/main/java/eu/siacs/conversations/ui/widget/CopyTextView.java deleted file mode 100644 index d22a2deae..000000000 --- a/src/main/java/eu/siacs/conversations/ui/widget/CopyTextView.java +++ /dev/null @@ -1,58 +0,0 @@ -package eu.siacs.conversations.ui.widget; - -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.support.v7.widget.AppCompatTextView; -import android.util.AttributeSet; - -public class CopyTextView extends AppCompatTextView { - - public CopyTextView(Context context) { - super(context); - } - - public CopyTextView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public CopyTextView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public interface CopyHandler { - String transformTextForCopy(CharSequence text, int start, int end); - } - - private CopyHandler copyHandler; - - public void setCopyHandler(CopyHandler copyHandler) { - this.copyHandler = copyHandler; - } - - @Override - public boolean onTextContextMenuItem(int id) { - final CharSequence text = getText(); - int min = 0; - int max = text.length(); - if (isFocused()) { - final int selStart = getSelectionStart(); - final int selEnd = getSelectionEnd(); - min = Math.max(0, Math.min(selStart, selEnd)); - max = Math.max(0, Math.max(selStart, selEnd)); - } - String textForCopy = null; - if (id == android.R.id.copy && copyHandler != null) { - textForCopy = copyHandler.transformTextForCopy(getText(), min, max); - } - try { - return super.onTextContextMenuItem(id); - } finally { - if (textForCopy != null) { - ClipboardManager clipboard = (ClipboardManager) getContext(). - getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setPrimaryClip(ClipData.newPlainText(null, textForCopy)); - } - } - } -} \ No newline at end of file diff --git a/src/main/res/layout/message_content.xml b/src/main/res/layout/message_content.xml index f1f584f0c..05af4e42c 100644 --- a/src/main/res/layout/message_content.xml +++ b/src/main/res/layout/message_content.xml @@ -1,12 +1,12 @@ -