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 | |
parent | fdeeff6fd381d6f9d259d9ae0f440230731d2f71 (diff) |
brought back 'copy to clipboard' and 'quote' context menu options
Diffstat (limited to '')
4 files changed, 57 insertions, 53 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) { diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml index a7e46bc7f..66b26d907 100644 --- a/src/main/res/menu/message_context.xml +++ b/src/main/res/menu/message_context.xml @@ -2,14 +2,18 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item - android:id="@+id/select_text" - android:title="@string/select_text" - android:visible="false" /> - <item android:id="@+id/share_with" android:title="@string/share_with" android:visible="false"/> <item + android:id="@+id/copy_message" + android:title="@string/copy_to_clipboard" + android:visible="false" /> + <item + android:id="@+id/quote_message" + android:title="@string/quote" + android:visible="false" /> + <item android:id="@+id/retry_decryption" android:title="@string/retry_decryption" android:visible="false" /> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e867a0c2a..a7c74f603 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -636,7 +636,9 @@ <string name="missing_presence_subscription">Missing presence subscription</string> <string name="missing_omemo_keys">Missing OMEMO keys</string> <string name="error_publish_avatar_offline">You need to be connected to publish your avatar.</string> - <string name="select_text">Select text</string> + <string name="copy_to_clipboard">Copy to clipboard</string> + <string name="message_copied_to_clipboard">Message copied to clipboard</string> + <string name="message">Message</string> <string name="quote">Quote</string> <string name="show_error_message">Show error message</string> <string name="error_message">Error Message</string> |