Search in sources :

Example 1 with QuizSubmissionQuestionResponse

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

the class QuizQuestionsFragment method setupCallbacks.

private void setupCallbacks() {
    quizFileUploadListener = new QuizFileUploadListener() {

        @Override
        public void onFileUploadClicked(long quizQuestionId, int position) {
            Bundle bundle = UploadFilesDialog.createQuizFileBundle(quizQuestionId, course.getId(), quiz.getId(), position);
            UploadFilesDialog.show(getFragmentManager(), bundle, new Function1<Integer, Unit>() {

                @Override
                public Unit invoke(Integer integer) {
                    return null;
                }
            });
        }
    };
    quizSubmissionQuestionResponseCanvasCallback = new StatusCallback<QuizSubmissionQuestionResponse>() {

        @Override
        public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (type == ApiType.CACHE)
                return;
            List<QuizSubmissionQuestion> questions = response.body().getQuizSubmissionQuestions();
            // sort the questions based on position that is part of the model object
            if (questions != null) {
                Collections.sort(questions, new Comparator<QuizSubmissionQuestion>() {

                    @Override
                    public int compare(QuizSubmissionQuestion lh, QuizSubmissionQuestion rh) {
                        if (lh != null && rh != null) {
                            if (lh.getPosition() < rh.getPosition()) {
                                return -1;
                            } else if (lh.getPosition() > rh.getPosition()) {
                                return 1;
                            }
                        }
                        return 0;
                    }
                });
            }
            if (quizQuestionAdapter == null) {
                quizQuestionAdapter = new QuizSubmissionQuestionListRecyclerAdapter(getActivity(), questions, course, shouldLetAnswer, quizSubmission, quizFileUploadListener);
            } else {
                quizQuestionAdapter.addAll(questions);
            }
            // cache the views after we view them
            recyclerView.setItemViewCacheSize(response.body().getQuizSubmissionQuestions().size());
            recyclerView.setAdapter(quizQuestionAdapter);
            if (linkHeaders.nextUrl != null) {
                QuizManager.getNextPageSubmissionQuestions(linkHeaders.nextUrl, false, quizSubmissionQuestionResponseCanvasCallback);
            }
        }
    };
    submitQuizCallback = new StatusCallback<QuizSubmissionResponse>() {

        @Override
        public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (type == ApiType.CACHE)
                return;
            switch(auto_submit_reason) {
                case TIMED_QUIZ:
                    showToast(R.string.submitReasonTimedQuiz);
                    break;
                case DUE_DATE:
                    showToast(R.string.quizSubmittedSuccessfully);
                    break;
                case LOCK_DATE:
                    showToast(R.string.submitReasonLockAt);
                    break;
                default:
                    showToast(R.string.quizSubmittedSuccessfully);
            }
            if (chronometer != null) {
                chronometer.stop();
            }
            if (countDownTimer != null) {
                countDownTimer.cancel();
            }
            getActivity().onBackPressed();
        }
    };
    quizSubmissionTimeCanvasCallback = new StatusCallback<QuizSubmissionTime>() {

        @Override
        public void onResponse(@NonNull Response<QuizSubmissionTime> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (type == ApiType.CACHE)
                return;
            mQuizSubmissionTime = response.body();
            if (shouldLetAnswer && isAdded()) {
                if (quiz.getTimeLimit() == 0 && quiz.getDueAt() == null && quiz.getLockAt() == null) {
                    normalTimer();
                } else if (quiz.getTimeLimit() > 0) {
                    timeLimitCountDown(mQuizSubmissionTime.getTimeLeft());
                } else if (quiz.getDueAt() != null && (quiz.getLockAt() == null || quiz.getDueAt().before(quiz.getLockAt()))) {
                    // if we have a due date, we want to give them an option to submit it when it gets to that point, but only if the due date is before the lock date
                    auto_submit_reason = AUTO_SUBMIT_REASON.DUE_DATE;
                    countDownForSubmit(mQuizSubmissionTime.getTimeLeft() * MILLISECOND);
                } else if (quiz.getLockAt() != null) {
                    auto_submit_reason = AUTO_SUBMIT_REASON.LOCK_DATE;
                    countDownForSubmit(mQuizSubmissionTime.getTimeLeft() * MILLISECOND);
                }
            } else {
                int minutes = (int) Math.ceil((double) (quizSubmission.getTimeSpent()) / 60);
                chronometer.setVisibility(View.GONE);
                timer.setText(String.format(Locale.getDefault(), getString(R.string.timeSpentFormat), minutes));
            }
        }
    };
}
Also used : QuizSubmissionTime(com.instructure.canvasapi2.models.QuizSubmissionTime) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Bundle(android.os.Bundle) QuizFileUploadListener(com.instructure.candroid.interfaces.QuizFileUploadListener) Function1(kotlin.jvm.functions.Function1) Comparator(java.util.Comparator) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) List(java.util.List) ArrayList(java.util.ArrayList) QuizSubmissionQuestionListRecyclerAdapter(com.instructure.candroid.adapter.QuizSubmissionQuestionListRecyclerAdapter) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse)

Example 2 with QuizSubmissionQuestionResponse

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

the class QuizManager_Test method getQuizSubmissionQuestions.

public static void getQuizSubmissionQuestions(long quizSubmissionId, StatusCallback<QuizSubmissionQuestionResponse> callback) {
    // TODO:
    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();
    QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = new QuizSubmissionQuestionResponse();
    List<QuizSubmissionQuestion> quizQuestions = new ArrayList<>();
    QuizSubmissionQuestion question = new QuizSubmissionQuestion();
    question.setQuestionText("TEST");
    question.setQuestionType("essay_question");
    quizQuestions.add(question);
    quizSubmissionQuestionResponse.setQuizSubmissionQuestions(quizQuestions);
    retrofit2.Response<QuizSubmissionQuestionResponse> response1 = retrofit2.Response.success(quizSubmissionQuestionResponse, 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) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) ArrayList(java.util.ArrayList) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion)

Example 3 with QuizSubmissionQuestionResponse

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

the class QuizManager method postQuizQuestionMatching.

public static void postQuizQuestionMatching(QuizSubmission quizSubmission, long questionId, HashMap<Long, Integer> 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.postQuizQuestionMatching(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)

Example 4 with QuizSubmissionQuestionResponse

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

the class QuizManager method postQuizQuestionMultiAnswer.

public static void postQuizQuestionMultiAnswer(QuizSubmission quizSubmission, long questionId, ArrayList<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.postQuizQuestionMultiAnswers(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)

Example 5 with QuizSubmissionQuestionResponse

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

the class QuizManager method getFirstPageSubmissionQuestions.

public static void getFirstPageSubmissionQuestions(long quizSubmissionId, 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.getFirstPageSubmissionQuestions(quizSubmissionId, 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)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