Search in sources :

Example 11 with QuizSubmission

use of com.instructure.canvasapi2.models.QuizSubmission 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 12 with QuizSubmission

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

Example 13 with QuizSubmission

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

the class QuizSubmissionQuestionListRecyclerAdapter method addNumericalQuestion.

private void addNumericalQuestion(QuizSubmissionQuestion baseItem, QuizNumericalViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizNumericalBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), flagStateCallback, embeddedWebViewCallback, webViewClientCallback, new QuizPostNumerical() {

        @Override
        public void postNumerical(long questionId, String answer) {
            addAnsweredQuestion(questionId);
            // note: this is the same as the essay question on purpose. Numerical is just text.
            QuizManager.postQuizQuestionEssay(quizSubmission, answer, questionId, true, new StatusCallback<QuizSubmissionQuestionResponse>() {
            });
        }
    });
}
Also used : QuizPostNumerical(com.instructure.candroid.interfaces.QuizPostNumerical) StatusCallback(com.instructure.canvasapi2.StatusCallback)

Example 14 with QuizSubmission

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

the class QuizManager_Test method getQuizSubmissions.

public static void getQuizSubmissions(StatusCallback<QuizSubmissionResponse> callback) {
    Response response = new Response.Builder().code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
    List<QuizSubmission> quizSubmissions = new ArrayList<>();
    QuizSubmission quizSubmission = new QuizSubmission();
    quizSubmission.setQuizId(456321L);
    quizSubmissions.add(quizSubmission);
    QuizSubmissionResponse quizSubmissionResponse = new QuizSubmissionResponse();
    quizSubmissionResponse.setQuizSubmissions(quizSubmissions);
    retrofit2.Response<QuizSubmissionResponse> response1 = retrofit2.Response.success(quizSubmissionResponse, response);
    callback.onResponse(response1, new LinkHeaders(), ApiType.CACHE);
}
Also used : QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(okhttp3.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) QuizSubmission(com.instructure.canvasapi2.models.QuizSubmission) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse)

Example 15 with QuizSubmission

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

the class QuizManager method postQuizQuestionMultipleDropdown.

public static void postQuizQuestionMultipleDropdown(QuizSubmission quizSubmission, long questionId, HashMap<String, Long> answers, boolean forceNetwork, @NonNull StatusCallback<QuizSubmissionQuestionResponse> callback) {
    final RestBuilder adapter = new RestBuilder(callback);
    final RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
    QuizAPI.postQuizQuestionMultipleDropdown(quizSubmission, questionId, answers, adapter, params, callback);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)11 RestParams (com.instructure.canvasapi2.builders.RestParams)11 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)9 StatusCallback (com.instructure.canvasapi2.StatusCallback)8 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)8 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)7 QuizSubmission (com.instructure.canvasapi2.models.QuizSubmission)5 ApiType (com.instructure.canvasapi2.utils.ApiType)5 ArrayList (java.util.ArrayList)5 NonNull (android.support.annotation.NonNull)4 Response (retrofit2.Response)4 QuizSubmissionQuestion (com.instructure.canvasapi2.models.QuizSubmissionQuestion)3 Response (okhttp3.Response)3 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)2 QuizSubmissionTime (com.instructure.canvasapi2.models.QuizSubmissionTime)2 List (java.util.List)2 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1