Search in sources :

Example 1 with Enrollment

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

the class ZendeskDialogStyled method generateTicketInfo.

private void generateTicketInfo(@Nullable List<Enrollment> enrollments) {
    String comment = descriptionEditText.getText().toString();
    String subject = subjectEditText.getText().toString();
    if (comment.isEmpty() || subject.isEmpty()) {
        Toast.makeText(getContext(), R.string.empty_feedback, Toast.LENGTH_LONG).show();
        return;
    }
    // contact the user
    if (fromLogin) {
        if (emailAddressEditText.getText() != null) {
            User user = new User();
            user.setPrimaryEmail(emailAddressEditText.getText().toString());
            ApiPrefs.setUser(user);
        }
    }
    final User user = ApiPrefs.getUser();
    // If a user has an email, otherwise this will be the login ID
    String email = "";
    if (user != null) {
        if (user.getPrimaryEmail() == null) {
            email = user.getLoginId();
        } else {
            email = user.getPrimaryEmail();
        }
    }
    String domain = ApiPrefs.getDomain();
    if (domain.isEmpty()) {
        domain = DEFAULT_DOMAIN;
    }
    // add device info to comment
    // try to get the version number and version code
    PackageInfo pInfo = null;
    String versionName = "";
    int versionCode = 0;
    try {
        pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        versionName = pInfo.versionName;
        versionCode = pInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
    // Do nothing
    }
    String deviceInfo = "";
    deviceInfo += getString(R.string.device) + " " + Build.MANUFACTURER + " " + Build.MODEL + "\n" + getString(R.string.osVersion) + " " + Build.VERSION.RELEASE + "\n" + getString(R.string.versionNum) + ": " + versionName + " " + versionCode + "\n" + getString(R.string.zendesk_severityText) + " " + getUserSeveritySelectionTag() + "\n" + getString(R.string.utils_installDate) + " " + getInstallDateString() + "\n\n";
    comment = deviceInfo + comment;
    String enrollmentTypes = "";
    if (enrollments != null) {
        for (Enrollment enrollment : enrollments) {
            // we don't want a ton of duplicates, so check it
            if (!enrollmentTypes.contains(enrollment.getType())) {
                enrollmentTypes += enrollment.getType() + ",";
            }
        }
        // remove last comma if necessary
        if (enrollmentTypes.endsWith(",") && enrollmentTypes.length() > 1) {
            enrollmentTypes = enrollmentTypes.substring(0, enrollmentTypes.length() - 1);
        }
    }
    String becomeUserUrl = "";
    if (user != null && user.getId() > 0L) {
        becomeUserUrl = domain + "?become_user_id=" + user.getId();
    }
    String name = "";
    if (user != null && user.getName() != null) {
        name = user.getName();
    }
    if (mUseDefaultDomain) {
        ErrorReportManager.postGenericErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), name, enrollmentTypes, becomeUserUrl, new StatusCallback<ErrorReportResult>() {

            @Override
            public void onResponse(@NonNull Response<ErrorReportResult> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                resetCachedUser();
                if (type.isAPI()) {
                    resultListener.onTicketPost();
                }
            }

            @Override
            public void onFail(@Nullable Call<ErrorReportResult> call, @NonNull Throwable error, @Nullable Response response) {
                resetCachedUser();
                resultListener.onTicketError();
            }

            @Override
            public void onFinished(ApiType type) {
                dismiss();
            }
        });
    } else {
        ErrorReportManager.postErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), name, enrollmentTypes, becomeUserUrl, new StatusCallback<ErrorReportResult>() {

            @Override
            public void onResponse(@NonNull Response<ErrorReportResult> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                resetCachedUser();
                if (type.isAPI()) {
                    resultListener.onTicketPost();
                }
            }

            @Override
            public void onFail(@Nullable Call<ErrorReportResult> call, @NonNull Throwable error, @Nullable Response response) {
                resetCachedUser();
                resultListener.onTicketError();
            }

            @Override
            public void onFinished(ApiType type) {
                dismiss();
            }
        });
    }
}
Also used : User(com.instructure.canvasapi2.models.User) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) PackageInfo(android.content.pm.PackageInfo) ErrorReportResult(com.instructure.canvasapi2.models.ErrorReportResult) Response(retrofit2.Response) PackageManager(android.content.pm.PackageManager) ApiType(com.instructure.canvasapi2.utils.ApiType) Enrollment(com.instructure.canvasapi2.models.Enrollment)

Example 2 with Enrollment

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

the class PeopleDetailsFragment method setupUserViews.

private void setupUserViews() {
    if (user != null) {
        name.setText(user.getName());
        ProfileUtils.loadAvatarForUser(userAvatar, user);
        // show the bio if one exists
        if (!TextUtils.isEmpty(user.getBio()) && !user.getBio().equals("null")) {
            bioText.setVisibility(View.VISIBLE);
            bioText.setText(user.getBio());
        }
        String roles = "";
        for (Enrollment enrollment : user.getEnrollments()) {
            roles += enrollment.getType() + " ";
        }
        userRole.setText(roles);
        userBackground.setBackgroundColor(ColorKeeper.getOrGenerateColor(getCanvasContext()));
    }
}
Also used : Enrollment(com.instructure.canvasapi2.models.Enrollment)

Example 3 with Enrollment

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

the class Analytics method trackEnrollment.

public static void trackEnrollment(Activity context, List<Course> courseList) {
    if (context == null || courseList == null) {
        return;
    }
    String enrollment = "Unknown";
    // used to track how many teacher/student enrollments
    int teacherCount = 0;
    int studentCount = 0;
    int observerCount = 0;
    for (Course course : courseList) {
        if (course.isTeacher()) {
            teacherCount++;
        } else if (course.isStudent()) {
            studentCount++;
        } else if (course.isObserver()) {
            observerCount++;
        }
    }
    // variable. This will set the custom dimension as whatever role is set the most
    if (studentCount > teacherCount && studentCount > observerCount) {
        // Set the dimension value for index 1 (Enrollment in GA, it is a 1 based list).
        enrollment = "Student";
    } else if (teacherCount >= studentCount && teacherCount >= observerCount) {
        // Set the dimension value for index 1.(Enrollment in GA, it is a 1 based list).
        enrollment = "Teacher";
    } else {
        // Set the dimension value for index 1.(Enrollment in GA, it is a 1 based list).
        enrollment = "Observer";
    }
    Application application = context.getApplication();
    if (application instanceof AnalyticsEventHandling) {
        ((AnalyticsEventHandling) application).trackEnrollment(enrollment);
    }
}
Also used : Course(com.instructure.canvasapi2.models.Course) Application(android.app.Application)

Example 4 with Enrollment

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

the class EnrollmentAPI method getNextPageEnrollments.

public static void getNextPageEnrollments(boolean forceNetwork, String nextUrl, RestBuilder adapter, StatusCallback<List<Enrollment>> callback) {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(true).withForceReadFromNetwork(forceNetwork).build();
    callback.addCall(adapter.build(EnrollmentInterface.class, params).getNextPage(nextUrl)).enqueue(callback);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 5 with Enrollment

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

the class CourseTest method addEnrollment.

@Test
public void addEnrollment() {
    Course course = new Course();
    course.setEnrollments(null);
    Enrollment enrollment = new Enrollment();
    course.addEnrollment(enrollment);
    assertEquals(true, course.getEnrollments().contains(enrollment));
}
Also used : Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

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