Search in sources :

Example 1 with QuizPostMultipleDropdown

use of com.instructure.candroid.interfaces.QuizPostMultipleDropdown 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)

Aggregations

NonNull (android.support.annotation.NonNull)1 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 QuizPostMultipleDropdown (com.instructure.candroid.interfaces.QuizPostMultipleDropdown)1 StatusCallback (com.instructure.canvasapi2.StatusCallback)1 QuizSubmissionQuestion (com.instructure.canvasapi2.models.QuizSubmissionQuestion)1 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)1 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)1 Response (retrofit2.Response)1