Search in sources :

Example 16 with Recipient

use of com.instructure.canvasapi2.models.Recipient in project instructure-android by instructure.

the class RecipientTest method getIdAsLongTest_Group.

@Test
public void getIdAsLongTest_Group() throws Exception {
    Recipient recipient = new Recipient();
    recipient.setStringId("group_12345");
    assertEquals(12345, recipient.getIdAsLong());
}
Also used : Recipient(com.instructure.canvasapi2.models.Recipient) Test(org.junit.Test)

Example 17 with Recipient

use of com.instructure.canvasapi2.models.Recipient in project instructure-android by instructure.

the class PeopleListPresenter method convertRecipientToUser.

@NonNull
private User convertRecipientToUser(Recipient recipient) {
    User user = new User();
    user.setAvatarUrl(recipient.getAvatarURL());
    user.setId(recipient.getIdAsLong());
    user.setName(recipient.getName());
    user.setSortableName(recipient.getName());
    // get enrollments
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    if (recipient.getCommonCourses() != null) {
        String[] commonCoursesEnrollments = recipient.getCommonCourses().get(Long.toString(mCanvasContext.getId()));
        if (commonCoursesEnrollments != null) {
            for (String enrollment : commonCoursesEnrollments) {
                Enrollment newEnrollment = new Enrollment();
                newEnrollment.setType(enrollment);
                enrollments.add(newEnrollment);
            }
            user.setEnrollments(enrollments);
        }
    }
    return user;
}
Also used : User(com.instructure.canvasapi2.models.User) ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) NonNull(android.support.annotation.NonNull)

Example 18 with Recipient

use of com.instructure.canvasapi2.models.Recipient in project instructure-android by instructure.

the class CanvasRecipientManager method generateDefaultImage.

/**
 * Helper to create generate a default avatar bitmap given a recipientEntry.
 * @param callback
 * @return
 */
public void generateDefaultImage(RecipientEntry recipient, final RecipientPhotoCallback callback) {
    try {
        Context context = ContextKeeper.appContext;
        Resources resources = context.getResources();
        String initials = ProfileUtils.getUserInitials(recipient.getName());
        int imageSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, resources.getDisplayMetrics());
        Bitmap image = ProfileUtils.getInitialsAvatarBitMap(context, recipient.getName());
        // Convert the generated bitmap to a bytearray
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.JPEG, 75, stream);
        byte[] byteArray = stream.toByteArray();
        recipient.setPhotoBytes(byteArray);
        if (callback != null) {
            callback.onPhotoBytesAsynchronouslyPopulated();
        }
    } catch (Exception e) {
        callback.onPhotoBytesAsyncLoadFailed();
    }
}
Also used : Context(android.content.Context) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) Bitmap(android.graphics.Bitmap) Resources(android.content.res.Resources) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Paint(android.graphics.Paint)

Example 19 with Recipient

use of com.instructure.canvasapi2.models.Recipient in project instructure-android by instructure.

the class AddMessageFragment method addRecipients.

private void addRecipients(ArrayList<Recipient> newRecipients) {
    List<RecipientEntry> selectedRecipients = mChipsTextView.getSelectedRecipients();
    mChipsTextView.setTokenizer(new Rfc822Tokenizer());
    if (mChipsAdapter == null) {
        mChipsAdapter = new RecipientAdapter(getContext());
    }
    if (mChipsTextView.getAdapter() == null) {
        mChipsTextView.setAdapter(mChipsAdapter);
    }
    addRecipient: for (Recipient recipient : newRecipients) {
        // Skip if this recipient is already added
        for (RecipientEntry entry : selectedRecipients) {
            if (entry.getDestination().equals(recipient.getStringId())) {
                continue addRecipient;
            }
        }
        // Create RecipientEntry from Recipient and add to list
        RecipientEntry recipientEntry = new RecipientEntry(recipient.getIdAsLong(), recipient.getName(), recipient.getStringId(), "", recipient.getAvatarURL(), 0, 0, true, recipient.getCommonCourses() != null ? recipient.getCommonCourses().keySet() : null, recipient.getCommonGroups() != null ? recipient.getCommonGroups().keySet() : null);
        mChipsTextView.appendRecipientEntry(recipientEntry);
    }
}
Also used : Rfc822Tokenizer(android.text.util.Rfc822Tokenizer) RecipientAdapter(com.instructure.teacher.adapters.RecipientAdapter) Recipient(com.instructure.canvasapi2.models.Recipient) RecipientEntry(com.android.ex.chips.RecipientEntry)

Example 20 with Recipient

use of com.instructure.canvasapi2.models.Recipient in project instructure-android by instructure.

the class AddMessageFragment method getRecipientsFromRecipientEntries.

private ArrayList<Recipient> getRecipientsFromRecipientEntries() {
    List<RecipientEntry> selectedRecipients = mChipsTextView.getSelectedRecipients();
    ArrayList<Recipient> recipients = new ArrayList<>();
    for (RecipientEntry entry : selectedRecipients) {
        Recipient recipient = new Recipient();
        recipient.setAvatarURL(entry.getAvatarUrl());
        recipient.setName(entry.getName());
        recipient.setStringId(entry.getDestination());
        recipients.add(recipient);
    }
    return recipients;
}
Also used : ArrayList(java.util.ArrayList) Recipient(com.instructure.canvasapi2.models.Recipient) RecipientEntry(com.android.ex.chips.RecipientEntry)

Aggregations

Recipient (com.instructure.canvasapi2.models.Recipient)14 Test (org.junit.Test)9 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)7 RestParams (com.instructure.canvasapi2.builders.RestParams)4 NonNull (android.support.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RecipientEntry (com.android.ex.chips.RecipientEntry)2 StatusCallback (com.instructure.canvasapi2.StatusCallback)2 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 Rfc822Tokenizer (android.text.util.Rfc822Tokenizer)1 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)1 Enrollment (com.instructure.canvasapi2.models.Enrollment)1 User (com.instructure.canvasapi2.models.User)1 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)1 RecipientAdapter (com.instructure.teacher.adapters.RecipientAdapter)1