Search in sources :

Example 1 with APIStatusDelegate

use of com.instructure.canvasapi.utilities.APIStatusDelegate in project instructure-android by instructure.

the class OAuthWebLogin method removeFromPreviouslySignedInUsers.

public static boolean removeFromPreviouslySignedInUsers(SignedInUser signedInUser, final Context context, String preferenceKey) {
    if (TextUtils.isEmpty(preferenceKey)) {
        prefNameOtherSignedInUsers = Const.KEY_OTHER_SIGNED_IN_USERS_PREF_NAME;
        preferenceKey = prefNameOtherSignedInUsers;
    }
    // Delete Access Token. We don't care about the result.
    APIStatusDelegate apiStatusDelegate = APIHelpers.statusDelegateWithContext(context);
    OAuthAPI.deleteToken(signedInUser.token, signedInUser.protocol, signedInUser.domain, new CanvasCallback<Response>(apiStatusDelegate) {

        @Override
        public void cache(Response response) {
        }

        @Override
        public void firstPage(Response response, LinkHeaders linkHeaders, Response response2) {
        }
    });
    // Save Signed In User to sharedPreferences
    SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceKey, MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.remove(getGlobalUserId(signedInUser.domain, signedInUser.user));
    return editor.commit();
}
Also used : WebResourceResponse(android.webkit.WebResourceResponse) Response(retrofit.client.Response) LinkHeaders(com.instructure.canvasapi.utilities.LinkHeaders) SharedPreferences(android.content.SharedPreferences) APIStatusDelegate(com.instructure.canvasapi.utilities.APIStatusDelegate)

Example 2 with APIStatusDelegate

use of com.instructure.canvasapi.utilities.APIStatusDelegate in project instructure-android by instructure.

the class ZendeskDialogStyled method saveZendeskTicket.

public void saveZendeskTicket() {
    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 && emailAddressEditText.getText().toString() != null) {
            User user = new User();
            user.setEmail(emailAddressEditText.getText().toString());
            APIHelpers.setCacheUser(getActivity(), user);
        }
    }
    final String email = APIHelpers.getCacheUser(getActivity()).getEmail();
    String domain = APIHelpers.getDomain(getActivity());
    if (domain == null) {
        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) {
        Utils.d(e.getMessage());
    }
    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;
    if (mUseDefaultDomain) {
        ErrorReportAPI.postGenericErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), new CanvasCallback<ErrorReportResult>((APIStatusDelegate) resultListener) {

            @Override
            public void firstPage(ErrorReportResult errorReportResult, LinkHeaders linkHeaders, Response response) {
                resetCachedUser();
                resultListener.onTicketPost();
            }

            @Override
            public boolean onFailure(RetrofitError retrofitError) {
                resetCachedUser();
                resultListener.onTicketError();
                return super.onFailure(retrofitError);
            }
        });
    } else {
        ErrorReportAPI.postErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), new CanvasCallback<ErrorReportResult>((APIStatusDelegate) resultListener) {

            @Override
            public void cache(ErrorReportResult errorReportResult) {
                resetCachedUser();
            }

            @Override
            public void firstPage(ErrorReportResult errorReportResult, LinkHeaders linkHeaders, Response response) {
                cache(errorReportResult);
                resultListener.onTicketPost();
            }

            @Override
            public boolean onFailure(RetrofitError retrofitError) {
                resetCachedUser();
                resultListener.onTicketError();
                return super.onFailure(retrofitError);
            }
        });
    }
}
Also used : User(com.instructure.canvasapi.model.User) LinkHeaders(com.instructure.canvasapi.utilities.LinkHeaders) PackageInfo(android.content.pm.PackageInfo) ErrorReportResult(com.instructure.canvasapi.model.ErrorReportResult) APIStatusDelegate(com.instructure.canvasapi.utilities.APIStatusDelegate) Response(retrofit.client.Response) PackageManager(android.content.pm.PackageManager) RetrofitError(retrofit.RetrofitError)

Aggregations

APIStatusDelegate (com.instructure.canvasapi.utilities.APIStatusDelegate)2 LinkHeaders (com.instructure.canvasapi.utilities.LinkHeaders)2 Response (retrofit.client.Response)2 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 WebResourceResponse (android.webkit.WebResourceResponse)1 ErrorReportResult (com.instructure.canvasapi.model.ErrorReportResult)1 User (com.instructure.canvasapi.model.User)1 RetrofitError (retrofit.RetrofitError)1