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