use of com.instructure.canvasapi2.utils.ApiType in project instructure-android by instructure.
the class BaseParentActivity method handleError.
public void handleError(int code, String error) {
if (code == 418) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
RevokedTokenResponse revokedTokenResponse = gson.fromJson(mJson, RevokedTokenResponse.class);
showRevokedTokenDialog(revokedTokenResponse, this);
}
if (code == 403) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
BlockedStudentResponse blockedStudentResponse = gson.fromJson(mJson, BlockedStudentResponse.class);
if (blockedStudentResponse.code.equals("studentBlocked")) {
Prefs prefs = new Prefs(this, getString(R.string.app_name_parent));
String parentId = prefs.load(Const.ID, "");
// We want to refresh cache so the main activity can load quickly with accurate information
UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {
@Override
public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (response.body() != null && !response.body().isEmpty()) {
// They have students that they are observing, take them to that activity
startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
overridePendingTransition(0, 0);
finish();
} else {
// Take the parent to the add user page.
FindSchoolActivity.Companion.createIntent(BaseParentActivity.this, true);
finish();
}
}
});
}
}
if (code == 451) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
MismatchedRegionResponse mismatchedRegionResponse = gson.fromJson(mJson, MismatchedRegionResponse.class);
showMismatchedRegionDialog(mismatchedRegionResponse.getStudentRegion(), this);
}
}
use of com.instructure.canvasapi2.utils.ApiType in project instructure-android by instructure.
the class BaseParentActivity method showMismatchedRegionDialog.
private void showMismatchedRegionDialog(final String regionString, final Context context) {
new AlertDialog.Builder(context).setTitle(R.string.unauthorizedRegion).setMessage(getString(R.string.mismatchedRegionMessage, getReadableRegion(this, regionString))).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Prefs prefs = new Prefs(BaseParentActivity.this, getString(R.string.app_name_parent));
String parentId = prefs.load(Const.ID, "");
UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {
@Override
public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (response.body() != null && !response.body().isEmpty()) {
// They have students that they are observing, take them to that activity
startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
overridePendingTransition(0, 0);
finish();
} else {
// Log the user out
new LogoutAsyncTask(BaseParentActivity.this, "").execute();
}
}
});
}
}).setCancelable(false).show();
}
use of com.instructure.canvasapi2.utils.ApiType in project instructure-android by instructure.
the class PublishPollActivity method setupCourseSpinner.
// /////////////////////////////////////////////////////////////////////////
// Helpers
// /////////////////////////////////////////////////////////////////////////
private void setupCourseSpinner(List<Course> courseList) {
// We only want courses we're a teacher for if we're trying to publish a poll
Iterator<Course> iterator = courseList.iterator();
while (iterator.hasNext()) {
if (!iterator.next().isTeacher()) {
iterator.remove();
}
}
if (courseList.size() == 0 || !courseList.get(0).getName().equals(getString(R.string.selectCourse))) {
Course selectCourse = new Course();
selectCourse.setId(Long.MIN_VALUE);
selectCourse.setName(getString(R.string.selectCourse));
courseList.add(0, selectCourse);
}
courseAdapter = new CourseSpinnerAdapter(this, android.R.layout.simple_spinner_dropdown_item, courseList);
coursesSpinner.setAdapter(courseAdapter);
coursesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Course course = (Course) parent.getAdapter().getItem(position);
// Handle the loading cell.
if (course == null || course.getEnrollments() == null) {
return;
}
if (!isCourseTermActive(course)) {
AppMsg.makeText(PublishPollActivity.this, getString(R.string.courseTermInactive), AppMsg.STYLE_WARNING).show();
return;
}
currentCourse = course;
// unselect all the selections, if we don't it still thinks some are selected when we go to another course
for (int i = 0; i < sectionListView.getCount(); i++) {
sectionListView.setItemChecked(i, false);
}
SectionManager.getAllSectionsForCourse(course.getId(), new StatusCallback<List<Section>>() {
@Override
public void onResponse(@NonNull retrofit2.Response<List<Section>> response, @NonNull com.instructure.canvasapi2.utils.LinkHeaders linkHeaders, @NonNull ApiType type) {
setupSectionAdapter(response.body());
ApplicationManager.saveSections(PublishPollActivity.this, response.body(), ((Course) coursesSpinner.getSelectedItem()).getId());
}
}, true);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
use of com.instructure.canvasapi2.utils.ApiType 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.utils.ApiType in project instructure-android by instructure.
the class NotificationListRecyclerAdapter method populateActivityStreamAdapter.
public void populateActivityStreamAdapter() {
if (mIsNoNetwork) {
// workaround for the multiple callbacks, which mess up the generic solution
getAdapterToRecyclerViewCallback().setDisplayNoConnection(true);
getAdapterToRecyclerViewCallback().setIsEmpty(size() == 0);
}
// wait until all calls return;
if (mCourseMap == null || mGroupMap == null || mStreamItems == null) {
return;
}
for (final StreamItem streamItem : mStreamItems) {
streamItem.setCanvasContextFromMap(mCourseMap, mGroupMap);
// load conversations if needed
if (streamItem.getType() == StreamItem.Type.CONVERSATION && ApiPrefs.getUser() != null) {
InboxManager.getConversation(streamItem.getConversationId(), false, new StatusCallback<Conversation>() {
@Override
public void onResponse(@NonNull Response<Conversation> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
// need to make sure the user isn't null
if (ApiPrefs.getUser() != null) {
streamItem.setConversation(getContext(), response.body(), ApiPrefs.getUser().getId(), getContext().getString(R.string.monologue));
notifyDataSetChanged();
}
}
@Override
public void onFail(@Nullable Call<Conversation> call, @NonNull Throwable error, @Nullable Response response) {
// Show crouton if it's a network error
if (!APIHelper.hasNetworkConnection()) {
mAdapterToFragmentCallback.onShowErrorCrouton(R.string.noDataConnection);
} else // Otherwise show that it's been deleted if we have a valid user
if (ApiPrefs.getUser() != null) {
Conversation conversation = new Conversation();
conversation.setDeleted(true);
conversation.setDeletedString(getContext().getString(R.string.deleted));
streamItem.setConversation(getContext(), conversation, ApiPrefs.getUser().getId(), getContext().getString(R.string.monologue));
notifyDataSetChanged();
}
}
});
}
// make sure there's something there
if (streamItem.getUpdatedAtDate() == null) {
continue;
}
addOrUpdateItem(DateHelper.getCleanDate(streamItem.getUpdatedAtDate().getTime()), streamItem);
}
mStreamItems = null;
// update count in dashboard
if (mOnNotificationCountInvalidated != null) {
mOnNotificationCountInvalidated.invalidateNotificationsCount();
}
}
Aggregations