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());
}
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;
}
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();
}
}
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);
}
}
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;
}
Aggregations