use of com.instructure.candroid.interfaces.QuizFileUploadListener 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));
}
}
};
}
Aggregations