Search in sources :

Example 1 with RecipientEntry

use of com.android.ex.chips.RecipientEntry in project instructure-android by instructure.

the class AddMessageFragment method sendMessage.

void sendMessage() {
    // Validate inputs
    if (!isValidNewMessage())
        return;
    // Ensure network is available
    if (!APIHelper.hasNetworkConnection()) {
        Toast.makeText(getContext(), AddMessageFragment.this.getString(R.string.not_available_offline), Toast.LENGTH_SHORT).show();
        return;
    }
    // Can't send a message to yourself. Canvas throws a 400, but canvas lets you select yourself as part of a list of people
    if (mChipsTextView.getSelectedRecipients().size() == 1 && mChipsTextView.getSelectedRecipients().get(0).getId() == ApiPrefs.getUser().getId()) {
        Toast.makeText(getContext(), R.string.addMorePeopleToMessage, Toast.LENGTH_SHORT).show();
        return;
    }
    // Make the progress bar visible and the other buttons not there so they can't try to re-send the message multiple times
    mToolbar.getMenu().findItem(R.id.menu_send).setVisible(false);
    mToolbar.getMenu().findItem(R.id.menu_attachment).setVisible(false);
    ViewStyler.themeProgressBar(mSavingProgressBar, Color.BLACK);
    mSavingProgressBar.announceForAccessibility(getString(R.string.sendingSimple));
    mSavingProgressBar.setVisibility(View.VISIBLE);
    // Send message
    if (isNewMessage || mIsMessageStudentsWho) {
        boolean isBulk = false;
        // we need to make sure that the switch is checked AND they have more than one recipient
        if (mChipsTextView.getSelectedRecipients().size() > 1 && mSendIndividually) {
            isBulk = true;
        } else {
            for (RecipientEntry entry : mChipsTextView.getSelectedRecipients()) {
                if (entry.getUserCount() > 1 && mSendIndividually) {
                    isBulk = true;
                    break;
                }
            }
        }
        String contextId;
        String subject;
        if (mIsMessageStudentsWho) {
            mSendIndividually = false;
            contextId = getArguments().getString(MESSAGE_STUDENTS_WHO_CONTEXT_ID, "");
            subject = mIsPersonalMessage ? mEditSubject.getText().toString() : mSubject.getText().toString();
        } else {
            contextId = mSelectedCourse.getContextId();
            subject = mEditSubject.getText().toString();
        }
        // isBulk controls the group vs individual messages, so group message flag is hardcoded to true at the api call
        getPresenter().sendNewMessage(mChipsTextView.getSelectedRecipients(), mMessage.getText().toString(), subject, contextId, isBulk);
    } else {
        getPresenter().sendMessage(mChipsTextView.getSelectedRecipients(), mMessage.getText().toString());
    }
}
Also used : RecipientEntry(com.android.ex.chips.RecipientEntry)

Example 2 with RecipientEntry

use of com.android.ex.chips.RecipientEntry in project instructure-android by instructure.

the class CanvasRecipientManager method getMatchingRecipients.

/**
 * Get a HashMap of address to RecipientEntry that contains all contact
 * information for a contact with the provided address, if one exists. This
 * may block the UI, so run it in an async task.
 */
public void getMatchingRecipients(ArrayList<RecipientEntry> recipients, BaseRecipientAdapter.RecipientMatchCallback callback) {
    Map<String, RecipientEntry> resultMap = new HashMap<>();
    for (RecipientEntry entry : recipients) {
        if (allRecipients.contains(entry)) {
            resultMap.put(entry.getDestination(), entry);
        }
    }
    callback.matchesFound(resultMap);
}
Also used : HashMap(java.util.HashMap) RecipientEntry(com.android.ex.chips.RecipientEntry)

Example 3 with RecipientEntry

use of com.android.ex.chips.RecipientEntry in project instructure-android by instructure.

the class CanvasRecipientManager method getFilteredRecipients.

// Should be called off the UI thread (performFiltering)
@Override
public synchronized List<RecipientEntry> getFilteredRecipients(String constraint) {
    if (constraint == null || TextUtils.isEmpty(constraint)) {
        return Collections.emptyList();
    }
    // has typed in additional info, and another API call needs to be performed.
    if (!constraint.equals(mLastConstraint)) {
        fetchAdditionalRecipients(constraint);
    }
    mLastConstraint = constraint;
    List<RecipientEntry> results = new ArrayList<>();
    for (RecipientEntry entry : allRecipients) {
        if (entry.getName().toLowerCase().contains(constraint.toLowerCase()) && entry.isInCourseOrGroup(canvasContext.getId())) {
            results.add(entry);
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) RecipientEntry(com.android.ex.chips.RecipientEntry)

Example 4 with RecipientEntry

use of com.android.ex.chips.RecipientEntry in project instructure-android by instructure.

the class CanvasRecipientManager method getMatchingRecipients.

/**
 * Get a HashMap of address to RecipientEntry that contains all contact
 * information for a contact with the provided address, if one exists. This
 * may block the UI, so run it in an async task.
 */
public void getMatchingRecipients(ArrayList<RecipientEntry> recipients, BaseRecipientAdapter.RecipientMatchCallback callback) {
    Map<String, RecipientEntry> resultMap = new HashMap<>();
    for (RecipientEntry entry : recipients) {
        if (allRecipients.contains(entry)) {
            resultMap.put(entry.getDestination(), entry);
        }
    }
    callback.matchesFound(resultMap);
}
Also used : HashMap(java.util.HashMap) RecipientEntry(com.android.ex.chips.RecipientEntry)

Example 5 with RecipientEntry

use of com.android.ex.chips.RecipientEntry in project instructure-android by instructure.

the class CanvasRecipientManager method getFilteredRecipients.

// Should be called off the UI thread (performFiltering)
@Override
public synchronized List<RecipientEntry> getFilteredRecipients(String constraint) {
    if (constraint == null || TextUtils.isEmpty(constraint)) {
        return Collections.emptyList();
    }
    // has typed in additional info, and another API call needs to be performed.
    if (!constraint.equals(mLastConstraint)) {
        fetchAdditionalRecipients(constraint);
    }
    mLastConstraint = constraint;
    List<RecipientEntry> results = new ArrayList<>();
    for (RecipientEntry entry : allRecipients) {
        if (entry.getName().toLowerCase().contains(constraint.toLowerCase()) && entry.isInCourseOrGroup(canvasContext.getId())) {
            results.add(entry);
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) RecipientEntry(com.android.ex.chips.RecipientEntry)

Aggregations

RecipientEntry (com.android.ex.chips.RecipientEntry)7 ArrayList (java.util.ArrayList)3 Recipient (com.instructure.canvasapi2.models.Recipient)2 HashMap (java.util.HashMap)2 Rfc822Tokenizer (android.text.util.Rfc822Tokenizer)1 RecipientAdapter (com.instructure.teacher.adapters.RecipientAdapter)1