Search in sources :

Example 1 with LTITool

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

the class SubmissionManager method getLtiFromAuthenticationUrl.

public static void getLtiFromAuthenticationUrl(String url, StatusCallback<LTITool> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        SubmissionAPI.getLtiFromAuthenticationUrl(url, adapter, params, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 2 with LTITool

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

the class SubmissionDetailsFragment method setupCallbacks.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setupCallbacks() {
    notoriousConfigCallback = new StatusCallback<NotoriousConfig>() {

        @Override
        public void onResponse(@NonNull Response<NotoriousConfig> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            NotoriousConfig notoriousConfig = response.body();
            if (notoriousConfig.isEnabled()) {
                mediaComment.setEnabled(true);
            }
        }
    };
    // We use a NoNetworkErrorDelegate because sometimes old submissions are deleted.
    // We don't want to display unnecessary croutons.
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            if (response.body() != null) {
                populateAdapter(response.body());
            }
        }
    };
    canvasCallbackMessage = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            // See if it was successful.
            Submission submission = response.body();
            if (submission != null) {
                SubmissionComment comment = submission.getSubmissionComments().get(submission.getSubmissionComments().size() - 1);
                // Our list is a list of Submission, so add the comment to a SubmissionGrade object
                Submission newSub = new Submission();
                ArrayList<SubmissionComment> comments = new ArrayList<>();
                comments.add(comment);
                newSub.setSubmittedAt(comment.getCreatedAt());
                newSub.setSubmissionComments(comments);
                adapter.subList.add(0, newSub);
                message.setText("");
            } else {
                showToast(R.string.errorPostingComment);
            }
            adapter.notifyDataSetChanged();
            // Close the keyboard
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
            // Enable the send message button again
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }

        @Override
        public void onFail(@Nullable Call<Submission> call, @NonNull Throwable error, @Nullable Response response) {
            // Enable the send message button again if there was an Error
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }
    };
    canvasCallbackLTITool = new StatusCallback<LTITool>() {

        @Override
        public void onResponse(@NonNull Response<LTITool> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            LTITool ltiTool = response.body();
            String url = ltiTool.getUrl();
            // Append platform for quizzes 2 lti tool
            Uri uri = Uri.parse(url).buildUpon().appendQueryParameter("platform", "android").build();
            // Do NOT authenticate or the LTI tool won't load.
            InternalWebviewFragment.Companion.loadInternalWebView(getActivity(), ((Navigation) getActivity()), InternalWebviewFragment.Companion.createBundle(getCanvasContext(), uri.toString(), ltiTool.getName(), false, false, true, assignment.getUrl()));
        }

        @Override
        public void onFail(@Nullable Call<LTITool> call, @NonNull Throwable error, @Nullable Response response) {
            // If it wasn't a network Error, then the LTI tool must be expired or invalid.
            if (APIHelper.hasNetworkConnection() && (response == null || (response != null && response.code() != 504))) {
                showToast(R.string.invalidExternal);
            }
        }
    };
    canvasCallbackAssignment = new StatusCallback<Assignment>() {

        @Override
        public void onResponse(@NonNull Response<Assignment> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Assignment newAssignment = response.body();
            String authenticationURL;
            if (newAssignment == null) {
                authenticationURL = null;
            } else {
                authenticationURL = newAssignment.getUrl();
            }
            // Now get the LTITool
            // This API call handles url being null
            SubmissionManager.getLtiFromAuthenticationUrl(authenticationURL, canvasCallbackLTITool, true);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) SubmissionComment(com.instructure.canvasapi2.models.SubmissionComment) Assignment(com.instructure.canvasapi2.models.Assignment) ApiType(com.instructure.canvasapi2.utils.ApiType) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Response(retrofit2.Response) NotoriousConfig(com.instructure.canvasapi2.models.NotoriousConfig)

Example 3 with LTITool

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

the class AddSubmissionFragment method setUpCallback.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setUpCallback() {
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Submission result = response.body();
            if (result.getBody() != null || result.getUrl() != null) {
                Toast.makeText(getActivity(), R.string.successPostingSubmission, Toast.LENGTH_LONG).show();
                // clear text fields because they are saved
                textSubmission.setText("");
                urlSubmission.setText("");
                // Send broadcast so list is updated.
                EventBus.getDefault().post(new FileUploadEvent(new FileUploadNotification(null, new ArrayList<Attachment>())));
                Navigation navigation = getNavigation();
                if (navigation != null)
                    navigation.popCurrentFragment();
            } else {
                Toast.makeText(getActivity(), R.string.errorPostingSubmission, Toast.LENGTH_LONG).show();
            }
        }
    };
    mLTIToolCallback = new StatusCallback<List<LTITool>>() {

        @Override
        public void onResponse(@NonNull Response<List<LTITool>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            for (LTITool ltiTool : response.body()) {
                final String url = ltiTool.getUrl();
                if (url != null && url.contains("instructuremedia.com/lti/launch")) {
                    mArcUpload.setVisibility(View.VISIBLE);
                    mArcLTITool = ltiTool;
                    break;
                }
            }
            // check to see if we should automatically show the file upload dialog
            showFileUploadDialog();
        }

        @Override
        public void onFail(@Nullable Call<List<LTITool>> call, @NonNull Throwable error, @Nullable Response response) {
            // we don't want to show it if this failed due to there being no cache
            if (response != null && response.code() != 504) {
                showFileUploadDialog();
            }
        }
    };
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) FileUploadNotification(com.instructure.pandautils.utils.FileUploadNotification) Response(retrofit2.Response) ApiType(com.instructure.canvasapi2.utils.ApiType) FileUploadEvent(com.instructure.pandautils.utils.FileUploadEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

LTITool (com.instructure.canvasapi2.models.LTITool)2 Submission (com.instructure.canvasapi2.models.Submission)2 ApiType (com.instructure.canvasapi2.utils.ApiType)2 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)2 ArrayList (java.util.ArrayList)2 Response (retrofit2.Response)2 Uri (android.net.Uri)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)1 RestParams (com.instructure.canvasapi2.builders.RestParams)1 Assignment (com.instructure.canvasapi2.models.Assignment)1 GradeableStudentSubmission (com.instructure.canvasapi2.models.GradeableStudentSubmission)1 NotoriousConfig (com.instructure.canvasapi2.models.NotoriousConfig)1 SubmissionComment (com.instructure.canvasapi2.models.SubmissionComment)1 Navigation (com.instructure.interactions.Navigation)1 FileUploadEvent (com.instructure.pandautils.utils.FileUploadEvent)1 FileUploadNotification (com.instructure.pandautils.utils.FileUploadNotification)1 List (java.util.List)1