brought back 'copy to clipboard' and 'quote' context menu options

This commit is contained in:
Daniel Gultsch 2017-11-07 15:58:27 +01:00
parent 49b4153fb5
commit e5210bbaa0
4 changed files with 60 additions and 53 deletions

View File

@ -555,6 +555,17 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override @Override
public void onQuote(String text) { public void onQuote(String text) {
quoteText(text);
}
});
messagesView.setAdapter(messageListAdapter);
registerForContextMenu(messagesView);
return view;
}
private void quoteText(String text) {
if (mEditMessage.isEnabled()) { if (mEditMessage.isEnabled()) {
text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", ""); text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", "");
Editable editable = mEditMessage.getEditableText(); Editable editable = mEditMessage.getEditableText();
@ -578,12 +589,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
} }
} }
});
messagesView.setAdapter(messageListAdapter);
registerForContextMenu(messagesView); private void quoteMessage(Message message) {
quoteText(message.getMergedBody().toString());
return view;
} }
@Override @Override
@ -607,9 +615,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final boolean treatAsFile = m.getType() != Message.TYPE_TEXT final boolean treatAsFile = m.getType() != Message.TYPE_TEXT
&& m.getType() != Message.TYPE_PRIVATE && m.getType() != Message.TYPE_PRIVATE
&& t == null; && t == null;
final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED
|| m.getEncryption() == Message.ENCRYPTION_PGP;
activity.getMenuInflater().inflate(R.menu.message_context, menu); activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options); 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 retryDecryption = menu.findItem(R.id.retry_decryption);
MenuItem correctMessage = menu.findItem(R.id.correct_message); MenuItem correctMessage = menu.findItem(R.id.correct_message);
MenuItem shareWith = menu.findItem(R.id.share_with); MenuItem shareWith = menu.findItem(R.id.share_with);
@ -619,8 +630,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission); MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
MenuItem deleteFile = menu.findItem(R.id.delete_file); MenuItem deleteFile = menu.findItem(R.id.delete_file);
MenuItem showErrorMessage = menu.findItem(R.id.show_error_message); MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
if (!treatAsFile && !m.isGeoUri() && !m.treatAsDownloadable()) { if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
selectText.setVisible(ListSelectionManager.isSupported()); copyMessage.setVisible(true);
quoteMessage.setVisible(true);
} }
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
retryDecryption.setVisible(true); retryDecryption.setVisible(true);
@ -671,12 +683,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.share_with: case R.id.share_with:
shareWith(selectedMessage); shareWith(selectedMessage);
return true; return true;
case R.id.select_text:
selectText(selectedMessage);
return true;
case R.id.correct_message: case R.id.correct_message:
correctMessage(selectedMessage); correctMessage(selectedMessage);
return true; 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: case R.id.send_again:
resendMessage(selectedMessage); resendMessage(selectedMessage);
return true; return true;
@ -743,21 +758,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
} }
private void selectText(Message message) { private void copyMessage(Message message) {
final int index; if (activity.copyTextToClipboard(message.getMergedBody().toString(), R.string.message)) {
synchronized (this.messageList) { Toast.makeText(activity, R.string.message_copied_to_clipboard, Toast.LENGTH_SHORT).show();
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);
}
}
} }
} }

View File

@ -194,10 +194,6 @@ public class ListSelectionManager {
return SUPPORTED; return SUPPORTED;
} }
public static void startSelection(TextView textView) {
startSelection(textView, 0, textView.getText().length());
}
public static void startSelection(TextView textView, int start, int end) { public static void startSelection(TextView textView, int start, int end) {
final CharSequence text = textView.getText(); final CharSequence text = textView.getText();
if (SUPPORTED && start >= 0 && end > start && textView.isTextSelectable() && text instanceof Spannable) { if (SUPPORTED && start >= 0 && end > start && textView.isTextSelectable() && text instanceof Spannable) {

View File

@ -1,14 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <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 <item
android:id="@+id/share_with" android:id="@+id/share_with"
android:title="@string/share_with" android:title="@string/share_with"
android:visible="false"/> 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 <item
android:id="@+id/retry_decryption" android:id="@+id/retry_decryption"
android:title="@string/retry_decryption" android:title="@string/retry_decryption"

View File

@ -342,7 +342,6 @@
<string name="check_x_filesize">Check %s size</string> <string name="check_x_filesize">Check %s size</string>
<string name="check_x_filesize_on_host">Check %1$s size on %2$s</string> <string name="check_x_filesize_on_host">Check %1$s size on %2$s</string>
<string name="message_options">Message options</string> <string name="message_options">Message options</string>
<string name="select_text">Select text</string>
<string name="quote">Quote</string> <string name="quote">Quote</string>
<string name="copy_original_url">Copy original URL</string> <string name="copy_original_url">Copy original URL</string>
<string name="send_again">Send again</string> <string name="send_again">Send again</string>
@ -724,4 +723,7 @@
<string name="certificate_does_not_contain_jid">Certificate does not contain a Jabber ID</string> <string name="certificate_does_not_contain_jid">Certificate does not contain a Jabber ID</string>
<string name="server_info_partial">partial</string> <string name="server_info_partial">partial</string>
<string name="attach_record_video">Record video</string> <string name="attach_record_video">Record video</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>
</resources> </resources>