Search in sources :

Example 21 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 22 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)

Example 23 with User

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

the class HelpActivity method setupListeners.

private void setupListeners() {
    mSearchGuides.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Search guides
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(Const.CANVAS_USER_GUIDES));
            startActivity(intent);
        }
    });
    mReportProblem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ZendeskDialogStyled dialog = new ZendeskDialogStyled();
            // set the cached user so the dialog can use the cached user's email address
            User user = new User();
            user.setPrimaryEmail(mEmailAddress);
            ApiPrefs.setUser(user);
            dialog.setArguments(ZendeskDialogStyled.createBundle(false, true));
            dialog.show(getSupportFragmentManager(), ZendeskDialogStyled.TAG);
        }
    });
    mRequestFeature.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // let the user open their favorite mail client
            Intent intent = populateMailIntent(getString(R.string.featureSubject), getString(R.string.understandRequest), false);
            startActivity(Intent.createChooser(intent, getString(R.string.sendMail)));
        }
    });
    mShowLove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Utils.goToAppStore(AppType.PARENT, HelpActivity.this);
        }
    });
    mOpenSource.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(new Intent(HelpActivity.this, OssLicensesMenuActivity.class));
        }
    });
}
Also used : ZendeskDialogStyled(com.instructure.loginapi.login.api.zendesk.utilities.ZendeskDialogStyled) User(com.instructure.canvasapi2.models.User) Intent(android.content.Intent) View(android.view.View)

Example 24 with User

use of com.instructure.canvasapi2.models.User 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 25 with User

use of com.instructure.canvasapi2.models.User 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();
    }
}
Also used : Response(retrofit2.Response) HiddenStreamItem(com.instructure.canvasapi2.models.HiddenStreamItem) StreamItem(com.instructure.canvasapi2.models.StreamItem) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ApiType(com.instructure.canvasapi2.utils.ApiType) Conversation(com.instructure.canvasapi2.models.Conversation)

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 List (java.util.List)7 Result (play.mvc.Result)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 ArrayList (java.util.ArrayList)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