Search in sources :

Example 1 with QuizSubmit

use of com.instructure.candroid.interfaces.QuizSubmit in project instructure-android by instructure.

the class QuizSubmissionQuestionListRecyclerAdapter method bindTheHolder.

public void bindTheHolder(final QuizSubmissionQuestion baseItem, RecyclerView.ViewHolder holder, int position) {
    int courseColor = ColorKeeper.getOrGenerateColor(canvasContext);
    if (position == super.getItemCount()) {
        // submit button
        SubmitButtonBinder.bind((SubmitButtonViewHolder) holder, getContext(), canvasContext, QuizSubmissionQuestionListRecyclerAdapter.this, new QuizSubmit() {

            @Override
            public void submitQuiz() {
                QuizManager.postQuizSubmit(canvasContext, quizSubmission, true, new StatusCallback<QuizSubmissionResponse>() {

                    @Override
                    public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                        if (type == ApiType.CACHE)
                            return;
                        // Submitted!
                        Toast.makeText(getContext(), R.string.quizSubmittedSuccessfully, Toast.LENGTH_SHORT).show();
                        // Go back to the startQuizFragment
                        ((Activity) getContext()).onBackPressed();
                        Fragment fragment = ((NavigationActivity) getContext()).getTopFragment();
                        if (fragment instanceof QuizStartFragment) {
                            ((QuizStartFragment) fragment).updateQuizInfo();
                        }
                    }

                    @Override
                    public void onFail(@Nullable Call<QuizSubmissionResponse> call, @NonNull Throwable error, @Nullable Response response) {
                        Toast.makeText(getContext(), R.string.quizSubmittedFailure, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
        return;
    }
    switch(baseItem.getQuestionType()) {
        case ESSAY:
        case SHORT_ANSWER:
            addEssayQuestion(baseItem, (QuizEssayViewHolder) holder, position, courseColor);
            break;
        case MUTIPLE_CHOICE:
        case TRUE_FALSE:
            addMultipleChoiceQuestion(baseItem, (QuizMultiChoiceViewHolder) holder, position, courseColor);
            break;
        case TEXT_ONLY:
            QuizTextOnlyBinder.bind((QuizTextOnlyViewHolder) holder, baseItem);
            break;
        case MULTIPLE_ANSWERS:
            addMultipleAnswerQuestion((QuizMultiChoiceViewHolder) holder, position, courseColor);
            break;
        case MATCHING:
            addMatchingQuestion(baseItem, (QuizMatchingViewHolder) holder, position, courseColor);
            break;
        case FILE_UPLOAD:
            addFileUploadQuestion(baseItem, (QuizFileUploadViewHolder) holder, position, courseColor);
            break;
        case NUMERICAL:
            addNumericalQuestion(baseItem, (QuizNumericalViewHolder) holder, position, courseColor);
            break;
        case MULTIPLE_DROPDOWNS:
            addMultipleDropdown(baseItem, (QuizMultipleDropdownViewHolder) holder, position, courseColor);
            break;
    }
}
Also used : Call(retrofit2.Call) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FragmentActivity(android.support.v4.app.FragmentActivity) NavigationActivity(com.instructure.candroid.activity.NavigationActivity) Activity(android.app.Activity) StatusCallback(com.instructure.canvasapi2.StatusCallback) Fragment(android.support.v4.app.Fragment) InternalWebviewFragment(com.instructure.candroid.fragment.InternalWebviewFragment) QuizStartFragment(com.instructure.candroid.fragment.QuizStartFragment) QuizStartFragment(com.instructure.candroid.fragment.QuizStartFragment) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) QuizSubmit(com.instructure.candroid.interfaces.QuizSubmit) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) NavigationActivity(com.instructure.candroid.activity.NavigationActivity) Nullable(android.support.annotation.Nullable)

Aggregations

Activity (android.app.Activity)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 NavigationActivity (com.instructure.candroid.activity.NavigationActivity)1 InternalWebviewFragment (com.instructure.candroid.fragment.InternalWebviewFragment)1 QuizStartFragment (com.instructure.candroid.fragment.QuizStartFragment)1 QuizSubmit (com.instructure.candroid.interfaces.QuizSubmit)1 StatusCallback (com.instructure.canvasapi2.StatusCallback)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 Call (retrofit2.Call)1 Response (retrofit2.Response)1