do not show 'paste as quote' if clip is NULL

This commit is contained in:
Daniel Gultsch 2018-09-24 20:33:05 +02:00
parent 9e7db440df
commit cdcd2f8b04

View file

@ -32,13 +32,12 @@ package eu.siacs.conversations.ui.util;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.text.TextUtils;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.widget.EditMessage; import eu.siacs.conversations.ui.widget.EditMessage;
@ -54,12 +53,14 @@ public class EditMessageActionModeCallback implements ActionMode.Callback {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater(); final MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.edit_message_actions, menu); inflater.inflate(R.menu.edit_message_actions, menu);
MenuItem pasteAsQuote = menu.findItem(R.id.paste_as_quote); final MenuItem pasteAsQuote = menu.findItem(R.id.paste_as_quote);
ClipData primaryClip = clipboardManager.getPrimaryClip(); final ClipData primaryClip = clipboardManager.getPrimaryClip();
if (primaryClip != null && primaryClip.getItemCount() >= 0) { if (primaryClip != null && primaryClip.getItemCount() >= 0) {
pasteAsQuote.setVisible(primaryClip.getDescription().getMimeType(0).startsWith("text/") && primaryClip.getItemAt(0).getText() != null); pasteAsQuote.setVisible(primaryClip.getDescription().getMimeType(0).startsWith("text/") && !TextUtils.isEmpty(primaryClip.getItemAt(0).getText()));
} else {
pasteAsQuote.setVisible(false);
} }
return true; return true;
} }