From cdcd2f8b04b418b502fe4c1df310a3115202283f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Sep 2018 20:33:05 +0200 Subject: [PATCH] do not show 'paste as quote' if clip is NULL --- .../util/EditMessageActionModeCallback.java | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/util/EditMessageActionModeCallback.java b/src/main/java/eu/siacs/conversations/ui/util/EditMessageActionModeCallback.java index 54cf30927..fca8ebbbc 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/EditMessageActionModeCallback.java +++ b/src/main/java/eu/siacs/conversations/ui/util/EditMessageActionModeCallback.java @@ -32,57 +32,58 @@ package eu.siacs.conversations.ui.util; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.util.Log; +import android.text.TextUtils; import android.view.ActionMode; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.ui.widget.EditMessage; public class EditMessageActionModeCallback implements ActionMode.Callback { - private final EditMessage editMessage; - private final ClipboardManager clipboardManager; + private final EditMessage editMessage; + private final ClipboardManager clipboardManager; - public EditMessageActionModeCallback(EditMessage editMessage) { - this.editMessage = editMessage; - this.clipboardManager = (ClipboardManager) editMessage.getContext().getSystemService(Context.CLIPBOARD_SERVICE); - } + public EditMessageActionModeCallback(EditMessage editMessage) { + this.editMessage = editMessage; + this.clipboardManager = (ClipboardManager) editMessage.getContext().getSystemService(Context.CLIPBOARD_SERVICE); + } - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = mode.getMenuInflater(); - inflater.inflate(R.menu.edit_message_actions, menu); - MenuItem pasteAsQuote = menu.findItem(R.id.paste_as_quote); - ClipData primaryClip = clipboardManager.getPrimaryClip(); - if (primaryClip != null && primaryClip.getItemCount() >= 0) { - pasteAsQuote.setVisible(primaryClip.getDescription().getMimeType(0).startsWith("text/") && primaryClip.getItemAt(0).getText() != null); - } - return true; - } + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + final MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.edit_message_actions, menu); + final MenuItem pasteAsQuote = menu.findItem(R.id.paste_as_quote); + final ClipData primaryClip = clipboardManager.getPrimaryClip(); + if (primaryClip != null && primaryClip.getItemCount() >= 0) { + pasteAsQuote.setVisible(primaryClip.getDescription().getMimeType(0).startsWith("text/") && !TextUtils.isEmpty(primaryClip.getItemAt(0).getText())); + } else { + pasteAsQuote.setVisible(false); + } + return true; + } - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; - } + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - if (item.getItemId() == R.id.paste_as_quote) { - final ClipData primaryClip = clipboardManager.getPrimaryClip(); - if (primaryClip != null && primaryClip.getItemCount() >= 1) { - editMessage.insertAsQuote(primaryClip.getItemAt(0).getText().toString()); - return true; - } - } - return false; - } + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + if (item.getItemId() == R.id.paste_as_quote) { + final ClipData primaryClip = clipboardManager.getPrimaryClip(); + if (primaryClip != null && primaryClip.getItemCount() >= 1) { + editMessage.insertAsQuote(primaryClip.getItemAt(0).getText().toString()); + return true; + } + } + return false; + } - @Override - public void onDestroyActionMode(ActionMode mode) { + @Override + public void onDestroyActionMode(ActionMode mode) { - } + } }