Search in sources :

Example 1 with ErrorReportResult

use of com.instructure.canvasapi2.models.ErrorReportResult 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)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Enrollment (com.instructure.canvasapi2.models.Enrollment)1 ErrorReportResult (com.instructure.canvasapi2.models.ErrorReportResult)1 User (com.instructure.canvasapi2.models.User)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)1 Response (retrofit2.Response)1