Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3f29749 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

compose: try performing recipient completion on send (fixes #1495)

This commit performs completion on recipient fields when the send button
is clicked (uncompleted text is usually present if the cursor is on the
recipient field at that time).

If any completion was performed, sending is quietly aborted. This avoids
sending mail to the wrong recipient if the uncompleted text doesn't
resolve to what the user thought.
parent 81468ac2
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -258,6 +258,18 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
        return bccView.hasUncompletedText();
    }

    public boolean recipientToTryPerformCompletion() {
        return toView.tryPerformCompletion();
    }

    public boolean recipientCcTryPerformCompletion() {
        return ccView.tryPerformCompletion();
    }

    public boolean recipientBccTryPerformCompletion() {
        return bccView.tryPerformCompletion();
    }

    public void showToUncompletedError() {
        toView.setError(toView.getContext().getString(R.string.compose_error_incomplete_recipient));
    }
+7 −0
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ public class RecipientPresenter implements PermissionPingCallback {
    }

    public boolean checkRecipientsOkForSending() {
        boolean performedAnyCompletion = recipientMvpView.recipientToTryPerformCompletion() ||
                recipientMvpView.recipientCcTryPerformCompletion() ||
                recipientMvpView.recipientBccTryPerformCompletion();
        if (performedAnyCompletion) {
            return true;
        }

        if (recipientMvpView.recipientToHasUncompletedText()) {
            recipientMvpView.showToUncompletedError();
            return true;
+15 −0
Original line number Diff line number Diff line
@@ -364,6 +364,21 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
        }
    }

    public boolean tryPerformCompletion() {
        if (!hasUncompletedText()) {
            return false;
        }
        int previousNumRecipients = getTokenCount();
        performCompletion();
        int numRecipients = getTokenCount();

        return previousNumRecipients != numRecipients;
    }

    private int getTokenCount() {
        return getObjects().size();
    }

    public boolean hasUncompletedText() {
        String currentCompletionText = currentCompletionText();
        return !TextUtils.isEmpty(currentCompletionText) && !isPlaceholderText(currentCompletionText);