diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-11-20 20:42:52 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-11-20 20:42:52 +0100 |
commit | 979e02fdc46573e260114e0f9112dcf326753d62 (patch) | |
tree | d8a63a6250c962dc3cf5ed8b6f2aa49426f6c3f3 /src/main/java/de/pixart | |
parent | fdeeff6fd381d6f9d259d9ae0f440230731d2f71 (diff) |
brought back 'copy to clipboard' and 'quote' context menu options
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 90 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/widget/ListSelectionManager.java | 4 |
2 files changed, 46 insertions, 48 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index f76c8a56d..dae0e4b73 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -72,7 +72,6 @@ import de.pixart.messenger.ui.XmppActivity.OnValueEdited; import de.pixart.messenger.ui.adapter.MessageAdapter; import de.pixart.messenger.ui.adapter.MessageAdapter.OnContactPictureClicked; import de.pixart.messenger.ui.adapter.MessageAdapter.OnContactPictureLongClicked; -import de.pixart.messenger.ui.widget.ListSelectionManager; import de.pixart.messenger.utils.NickValidityChecker; import de.pixart.messenger.utils.StylingHelper; import de.pixart.messenger.utils.UIHelper; @@ -566,28 +565,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa @Override public void onQuote(String text) { - if (mEditMessage.isEnabled()) { - text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", ""); - Editable editable = mEditMessage.getEditableText(); - int position = mEditMessage.getSelectionEnd(); - if (position == -1) position = editable.length(); - if (position > 0 && editable.charAt(position - 1) != '\n') { - editable.insert(position++, "\n"); - } - editable.insert(position, text); - position += text.length(); - editable.insert(position++, "\n"); - if (position < editable.length() && editable.charAt(position) != '\n') { - editable.insert(position, "\n"); - } - mEditMessage.setSelection(position); - mEditMessage.requestFocus(); - InputMethodManager inputMethodManager = (InputMethodManager) getActivity() - .getSystemService(Context.INPUT_METHOD_SERVICE); - if (inputMethodManager != null) { - inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT); - } - } + quoteText(text); } }); messagesView.setAdapter(messageListAdapter); @@ -597,6 +575,35 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa return view; } + private void quoteText(String text) { + if (mEditMessage.isEnabled()) { + text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", ""); + Editable editable = mEditMessage.getEditableText(); + int position = mEditMessage.getSelectionEnd(); + if (position == -1) position = editable.length(); + if (position > 0 && editable.charAt(position - 1) != '\n') { + editable.insert(position++, "\n"); + } + editable.insert(position, text); + position += text.length(); + editable.insert(position++, "\n"); + if (position < editable.length() && editable.charAt(position) != '\n') { + editable.insert(position, "\n"); + } + mEditMessage.setSelection(position); + mEditMessage.requestFocus(); + InputMethodManager inputMethodManager = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputMethodManager != null) { + inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT); + } + } + } + + private void quoteMessage(Message message) { + quoteText(message.getMergedBody().toString()); + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { synchronized (this.messageList) { @@ -618,9 +625,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa final boolean treatAsFile = m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE && t == null; + final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED + || m.getEncryption() == Message.ENCRYPTION_PGP; activity.getMenuInflater().inflate(R.menu.message_context, menu); menu.setHeaderTitle(R.string.message_options); - MenuItem selectText = menu.findItem(R.id.select_text); + MenuItem copyMessage = menu.findItem(R.id.copy_message); + MenuItem quoteMessage = menu.findItem(R.id.quote_message); MenuItem retryDecryption = menu.findItem(R.id.retry_decryption); MenuItem correctMessage = menu.findItem(R.id.correct_message); MenuItem shareWith = menu.findItem(R.id.share_with); @@ -630,8 +640,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa MenuItem downloadFile = menu.findItem(R.id.download_file); MenuItem deleteFile = menu.findItem(R.id.delete_file); MenuItem showErrorMessage = menu.findItem(R.id.show_error_message); - if (!treatAsFile && !m.isGeoUri() && !m.isXmppUri() && !m.treatAsDownloadable()) { - selectText.setVisible(ListSelectionManager.isSupported()); + if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) { + copyMessage.setVisible(true); + quoteMessage.setVisible(true); } if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { retryDecryption.setVisible(true); @@ -685,12 +696,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa case R.id.share_with: shareWith(selectedMessage); return true; - case R.id.select_text: - selectText(selectedMessage); - return true; case R.id.correct_message: correctMessage(selectedMessage); return true; + case R.id.copy_message: + copyMessage(selectedMessage); + return true; + case R.id.quote_message: + quoteMessage(selectedMessage); + return true; case R.id.send_again: resendMessage(selectedMessage); return true; @@ -757,21 +771,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } - private void selectText(Message message) { - final int index; - synchronized (this.messageList) { - index = this.messageList.indexOf(message); - } - if (index >= 0) { - final int first = this.messagesView.getFirstVisiblePosition(); - final int last = first + this.messagesView.getChildCount(); - if (index >= first && index < last) { - final View view = this.messagesView.getChildAt(index - first); - final TextView messageBody = this.messageListAdapter.getMessageBody(view); - if (messageBody != null) { - ListSelectionManager.startSelection(messageBody); - } - } + private void copyMessage(Message message) { + if (activity.copyTextToClipboard(message.getMergedBody().toString(), R.string.message)) { + Toast.makeText(activity, R.string.message_copied_to_clipboard, Toast.LENGTH_SHORT).show(); } } diff --git a/src/main/java/de/pixart/messenger/ui/widget/ListSelectionManager.java b/src/main/java/de/pixart/messenger/ui/widget/ListSelectionManager.java index 7ccf94dbe..5ac6f9134 100644 --- a/src/main/java/de/pixart/messenger/ui/widget/ListSelectionManager.java +++ b/src/main/java/de/pixart/messenger/ui/widget/ListSelectionManager.java @@ -194,10 +194,6 @@ public class ListSelectionManager { return SUPPORTED; } - public static void startSelection(TextView textView) { - startSelection(textView, 0, textView.getText().length()); - } - public static void startSelection(TextView textView, int start, int end) { final CharSequence text = textView.getText(); if (SUPPORTED && start >= 0 && end > start && textView.isTextSelectable() && text instanceof Spannable) { |