Search in sources :

Example 1 with User

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);
}
Also used : User(com.instructure.canvasapi2.models.User) Test(org.junit.Test)

Example 2 with User

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);
}
Also used : User(com.instructure.canvasapi2.models.User) Test(org.junit.Test)

Example 3 with User

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);
    }
}
Also used : BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Gson(com.google.gson.Gson) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) JsonElement(com.google.gson.JsonElement) ApiType(com.instructure.canvasapi2.utils.ApiType) List(java.util.List) JsonParser(com.google.gson.JsonParser)

Example 4 with User

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Student(com.instructure.canvasapi2.models.Student) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) Response(retrofit2.Response) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LogoutAsyncTask(com.instructure.parentapp.asynctask.LogoutAsyncTask) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType)

Example 5 with User

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));
        }
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) Student(com.instructure.canvasapi2.models.Student) Course(com.instructure.canvasapi2.models.Course) AccountNotification(com.instructure.canvasapi2.models.AccountNotification)

Aggregations

User (models.User)30 User (com.instructure.canvasapi2.models.User)25 RestParams (com.instructure.canvasapi2.builders.RestParams)22 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)19 Test (org.junit.Test)16 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)8 CurrentUser (actions.CurrentUser)7 CurrentUser.currentUser (actions.CurrentUser.currentUser)7 NonNull (android.support.annotation.NonNull)7 View (android.view.View)7 Result (play.mvc.Result)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Module (models.Module)6 UnitTest (play.test.UnitTest)6 Intent (android.content.Intent)5 RoleHolderPresent (be.objectify.deadbolt.actions.RoleHolderPresent)5 StatusCallback (com.instructure.canvasapi2.StatusCallback)5 Course (com.instructure.canvasapi2.models.Course)5