Search in sources :

Example 56 with Enrollment

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

the class EnrollmentTest method getType.

@Test
public void getType() {
    Enrollment enrollment = new Enrollment();
    enrollment.setType("studentenrollment");
    assertEquals("student", enrollment.getType());
}
Also used : Enrollment(com.instructure.canvasapi2.models.Enrollment) Test(org.junit.Test)

Example 57 with Enrollment

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

the class UserTest method getEnrollmentsHash_Test2.

@Test
public void getEnrollmentsHash_Test2() {
    Enrollment enrollment1 = new Enrollment();
    enrollment1.setCourseId(1234);
    enrollment1.setRole("student");
    Enrollment enrollment2 = new Enrollment();
    enrollment2.setCourseId(1234);
    enrollment2.setRole("teacher");
    List<Enrollment> enrollmentList = new ArrayList<>();
    enrollmentList.add(enrollment1);
    enrollmentList.add(enrollment2);
    user1.setEnrollments(enrollmentList);
    user1.getEnrollmentsHash();
    assertEquals("teacher", user1.getEnrollmentsHash().get("1234")[1]);
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Test(org.junit.Test)

Example 58 with Enrollment

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

the class UserTest method getEnrollmentsHash_Test1.

// endregion
@Test
public void getEnrollmentsHash_Test1() {
    Enrollment enrollment1 = new Enrollment();
    enrollment1.setCourseId(1234);
    enrollment1.setRole("student");
    Enrollment enrollment2 = new Enrollment();
    enrollment2.setCourseId(1234);
    enrollment2.setRole("teacher");
    List<Enrollment> enrollmentList = new ArrayList<>();
    enrollmentList.add(enrollment1);
    enrollmentList.add(enrollment2);
    user1.setEnrollments(enrollmentList);
    user1.getEnrollmentsHash();
    assertEquals("student", user1.getEnrollmentsHash().get("1234")[0]);
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Test(org.junit.Test)

Example 59 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment 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 60 with Enrollment

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

the class UserBinder method bind.

public static void bind(final Context context, final User user, final AdapterToFragmentCallback<User> adapterToFragmentCallback, final UserViewHolder holder, final int position) {
    // Set student avatar
    BasicUser basicUser = new BasicUser();
    basicUser.setName(user.getName());
    basicUser.setAvatarUrl(user.getAvatarUrl());
    ProfileUtils.loadAvatarForUser(holder.studentAvatar, basicUser);
    // Set student name
    holder.userName.setText(user.getName());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(user, position);
        }
    });
    // List enrollmentApiModel type(s)
    // get a list of strings of the enrollments
    // Use hashSet to prevent duplicate enrollments
    HashSet<String> enrollments = new HashSet<>();
    for (Enrollment enrollment : user.getEnrollments()) {
        enrollments.add(enrollment.getType());
    }
    holder.userRole.setText(android.text.TextUtils.join(", ", enrollments));
}
Also used : BasicUser(com.instructure.canvasapi2.models.BasicUser) Enrollment(com.instructure.canvasapi2.models.Enrollment) View(android.view.View) HashSet(java.util.HashSet)

Aggregations

Enrollment (com.instructure.canvasapi2.models.Enrollment)55 Test (org.junit.Test)46 Course (com.instructure.canvasapi2.models.Course)30 ArrayList (java.util.ArrayList)25 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)7 RestParams (com.instructure.canvasapi2.builders.RestParams)7 NonNull (android.support.annotation.NonNull)4 Grades (com.instructure.canvasapi2.models.Grades)4 StatusCallback (com.instructure.canvasapi2.StatusCallback)3 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)3 List (java.util.List)3 GradingPeriod (com.instructure.canvasapi2.models.GradingPeriod)2 User (com.instructure.canvasapi2.models.User)2 Application (android.app.Application)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 View (android.view.View)1 BasicUser (com.instructure.canvasapi2.models.BasicUser)1 ErrorReportResult (com.instructure.canvasapi2.models.ErrorReportResult)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1