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