use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ProfileUtilsTest method getUserInitials_string3.
@Test
public void getUserInitials_string3() throws Exception {
User user = new User();
user.setShortName("Billy Bob Thorton");
String testValue = ProfileUtils.getUserInitials(user.getShortName());
assertEquals("B", testValue);
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ProfileUtilsTest method getUserInitials_string1.
@Test
public void getUserInitials_string1() throws Exception {
User user = new User();
user.setShortName("Billy Bob");
String testValue = ProfileUtils.getUserInitials(user.getShortName());
assertEquals("BB", testValue);
}
use of com.instructure.canvasapi2.models.User 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.models.User 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.models.User in project instructure-android by instructure.
the class DetailViewActivity method routeFromIntent.
private void routeFromIntent(Intent intent) {
DETAIL_FRAGMENT fragmentType = (DETAIL_FRAGMENT) intent.getExtras().getSerializable(Const.FRAGMENT_TYPE);
if (fragmentType != null) {
Student student = intent.getExtras().getParcelable(Const.STUDENT);
switch(fragmentType) {
case WEEK:
Student user = intent.getExtras().getParcelable(Const.USER);
Course course = (Course) intent.getExtras().getSerializable(Const.COURSE);
if (user != null && course != null) {
addFragment(CourseWeekFragment.newInstance(user, course));
}
break;
case ASSIGNMENT:
Assignment assignment = intent.getExtras().getParcelable(Const.ASSIGNMENT);
String courseName = intent.getExtras().getString(Const.NAME);
addFragment(AssignmentFragment.newInstance(assignment, courseName, student), false);
break;
case ANNOUNCEMENT:
DiscussionTopicHeader announcement = intent.getExtras().getParcelable(Const.ANNOUNCEMENT);
String announcementCourseName = intent.getExtras().getString(Const.NAME);
addFragment(AnnouncementFragment.newInstance(announcement, announcementCourseName, student), false);
break;
case EVENT:
ScheduleItem item = intent.getExtras().getParcelable(Const.SCHEDULE_ITEM);
addFragment(EventFragment.newInstance(item, student), false);
break;
case SYLLABUS:
Course syllabusCourse = (Course) intent.getExtras().getSerializable(Const.COURSE);
addFragment(CourseSyllabusFragment.newInstance(syllabusCourse, student), false);
break;
case ACCOUNT_NOTIFICATION:
AccountNotification accountNotification = intent.getExtras().getParcelable(Const.ACCOUNT_NOTIFICATION);
addFragment(AccountNotificationFragment.newInstance(accountNotification, student));
}
}
}
Aggregations