Search in sources :

Example 6 with QuizSubmissionQuestionResponse

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

the class QuizManager method postQuizQuestionFileUpload.

public static void postQuizQuestionFileUpload(CanvasContext canvasContext, QuizSubmission quizSubmission, long answer, long questionId, boolean forceNetwork, StatusCallback<QuizSubmissionQuestionResponse> callback) {
    final RestBuilder adapter = new RestBuilder(callback);
    final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
    QuizAPI.postQuizQuestionFileUpload(canvasContext, quizSubmission, answer, questionId, adapter, params, callback);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 7 with QuizSubmissionQuestionResponse

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

the class QuizSubmissionQuestionListRecyclerAdapter method addMultipleDropdown.

private void addMultipleDropdown(final QuizSubmissionQuestion baseItem, QuizMultipleDropdownViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMultipleDropdownBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMultipleDropdown() {

        @Override
        public void postMultipleDropdown(final long questionId, HashMap<String, Long> answers) {
            QuizManager.postQuizQuestionMultipleDropdown(quizSubmission, questionId, answers, true, new StatusCallback<QuizSubmissionQuestionResponse>() {

                @Override
                public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (type == ApiType.CACHE)
                        return;
                    QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = response.body();
                    if (quizSubmissionQuestionResponse.getQuizSubmissionQuestions() != null) {
                        for (QuizSubmissionQuestion question : quizSubmissionQuestionResponse.getQuizSubmissionQuestions()) {
                            if (baseItem.getId() == question.getId()) {
                                baseItem.setAnswer(question.getAnswer());
                            }
                        }
                        // make sure each answer has a match
                        int numAnswers = 0;
                        // API returns a LinkedTreeMap
                        for (String map : ((LinkedTreeMap<String, String>) baseItem.getAnswer()).values()) {
                            if (map != null && !map.equals("null")) {
                                numAnswers++;
                            }
                        }
                        if (numAnswers == ((LinkedTreeMap<String, String>) baseItem.getAnswer()).size()) {
                            addAnsweredQuestion(questionId);
                        } else {
                            removeAnsweredQuestion(questionId);
                        }
                    }
                }
            });
        }
    }, flagStateCallback);
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) QuizPostMultipleDropdown(com.instructure.candroid.interfaces.QuizPostMultipleDropdown) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)

Example 8 with QuizSubmissionQuestionResponse

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

the class QuizSubmissionQuestionListRecyclerAdapter method addMultipleChoiceQuestion.

private void addMultipleChoiceQuestion(QuizSubmissionQuestion baseItem, QuizMultiChoiceViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMultiChoiceBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMultiChoice() {

        @Override
        public void postAnswer(final long questionId, long answerId) {
            addAnsweredQuestion(questionId);
            QuizManager.postQuizQuestionMultiChoice(quizSubmission, answerId, questionId, true, new StatusCallback<QuizSubmissionQuestionResponse>() {
            });
        }
    }, flagStateCallback);
}
Also used : QuizPostMultiChoice(com.instructure.candroid.interfaces.QuizPostMultiChoice) StatusCallback(com.instructure.canvasapi2.StatusCallback)

Example 9 with QuizSubmissionQuestionResponse

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

the class QuizSubmissionQuestionListRecyclerAdapter method addEssayQuestion.

private void addEssayQuestion(QuizSubmissionQuestion baseItem, QuizEssayViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizEssayBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), flagStateCallback, embeddedWebViewCallback, webViewClientCallback, new QuizPostEssay() {

        @Override
        public void postEssay(long questionId, String answer) {
            addAnsweredQuestion(questionId);
            QuizManager.postQuizQuestionEssay(quizSubmission, answer, questionId, true, new StatusCallback<QuizSubmissionQuestionResponse>() {
            });
        }
    });
}
Also used : QuizPostEssay(com.instructure.candroid.interfaces.QuizPostEssay) StatusCallback(com.instructure.canvasapi2.StatusCallback)

Example 10 with QuizSubmissionQuestionResponse

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

the class QuizSubmissionQuestionListRecyclerAdapter method addMatchingQuestion.

private void addMatchingQuestion(final QuizSubmissionQuestion baseItem, QuizMatchingViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMatchingBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMatching() {

        @Override
        public void postMatching(final long questionId, HashMap<Long, Integer> answers) {
            QuizManager.postQuizQuestionMatching(quizSubmission, questionId, answers, true, new StatusCallback<QuizSubmissionQuestionResponse>() {

                @Override
                public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (type == ApiType.CACHE)
                        return;
                    final QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = response.body();
                    if (quizSubmissionQuestionResponse.getQuizSubmissionQuestions() != null) {
                        for (QuizSubmissionQuestion question : quizSubmissionQuestionResponse.getQuizSubmissionQuestions()) {
                            if (baseItem.getId() == question.getId()) {
                                baseItem.setAnswer(question.getAnswer());
                            }
                        }
                        // make sure each answer has a match
                        int numAnswers = 0;
                        // API returns an ArrayList of LinkedTreeMaps
                        for (LinkedTreeMap<String, String> map : ((ArrayList<LinkedTreeMap<String, String>>) baseItem.getAnswer())) {
                            if (map.get(Const.QUIZ_MATCH_ID) != null && !map.get(Const.QUIZ_MATCH_ID).equals("null")) {
                                numAnswers++;
                            }
                        }
                        if (numAnswers == baseItem.getAnswers().length) {
                            addAnsweredQuestion(questionId);
                        } else {
                            removeAnsweredQuestion(questionId);
                        }
                    }
                }
            });
        }
    }, flagStateCallback);
}
Also used : QuizPostMatching(com.instructure.candroid.interfaces.QuizPostMatching) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)9 RestParams (com.instructure.canvasapi2.builders.RestParams)9 StatusCallback (com.instructure.canvasapi2.StatusCallback)5 QuizSubmissionQuestion (com.instructure.canvasapi2.models.QuizSubmissionQuestion)4 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)4 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)4 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)4 ApiType (com.instructure.canvasapi2.utils.ApiType)3 NonNull (android.support.annotation.NonNull)2 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)2 ArrayList (java.util.ArrayList)2 Response (retrofit2.Response)2 Bundle (android.os.Bundle)1 QuizSubmissionQuestionListRecyclerAdapter (com.instructure.candroid.adapter.QuizSubmissionQuestionListRecyclerAdapter)1 QuizFileUploadListener (com.instructure.candroid.interfaces.QuizFileUploadListener)1 QuizPostEssay (com.instructure.candroid.interfaces.QuizPostEssay)1 QuizPostMatching (com.instructure.candroid.interfaces.QuizPostMatching)1 QuizPostMultiChoice (com.instructure.candroid.interfaces.QuizPostMultiChoice)1 QuizPostMultipleDropdown (com.instructure.candroid.interfaces.QuizPostMultipleDropdown)1 QuizPostNumerical (com.instructure.candroid.interfaces.QuizPostNumerical)1