Search in sources :

Example 1 with QuizMatchSpinnerAdapter

use of com.instructure.teacher.adapters.QuizMatchSpinnerAdapter in project instructure-android by instructure.

the class QuizMatchingBinder method bind.

public static void bind(final QuizMatchingViewHolder holder, final QuizSubmissionQuestion quizSubmissionQuestion, final int position, final Context context, final CanvasWebView.CanvasEmbeddedWebViewCallback embeddedWebViewCallback, final CanvasWebView.CanvasWebViewClientCallback webViewClientCallback) {
    if (holder == null) {
        return;
    }
    setupViews(holder, quizSubmissionQuestion, position, context, embeddedWebViewCallback, webViewClientCallback);
    LayoutInflater inflater = LayoutInflater.from(context);
    // add answers to the answer container
    int index = 0;
    for (final QuizSubmissionAnswer answer : quizSubmissionQuestion.getAnswers()) {
        final LinearLayout answerWrapper = (LinearLayout) inflater.inflate(R.layout.quiz_matching_answer, null, false);
        final TextView answerTextView = (TextView) answerWrapper.findViewById(R.id.text_answer);
        final Spinner spinner = (Spinner) answerWrapper.findViewById(R.id.answer_spinner);
        ArrayList<QuizSubmissionMatch> list = new ArrayList<>();
        QuizSubmissionMatch firstMatch = new QuizSubmissionMatch();
        firstMatch.setText(context.getString(R.string.quizMatchingDefaultDisplay));
        list.add(firstMatch);
        for (QuizSubmissionMatch match : quizSubmissionQuestion.getMatches()) {
            list.add(match);
        }
        QuizMatchSpinnerAdapter adapter = new QuizMatchSpinnerAdapter(context, android.R.layout.simple_spinner_item, list);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        if (!TextUtils.isEmpty(answer.getHtml())) {
            answerTextView.setVisibility(View.GONE);
            setPreviouslySelectedAnswer(quizSubmissionQuestion, answer, spinner, list);
        } else if (!TextUtils.isEmpty(answer.getText())) {
            answerTextView.setText(answer.getText());
            setPreviouslySelectedAnswer(quizSubmissionQuestion, answer, spinner, list);
        }
        holder.answerContainer.addView(answerWrapper);
        if (index == quizSubmissionQuestion.getAnswers().length - 1) {
            // if we're on the last answer remove the bottom divider
            answerWrapper.findViewById(R.id.divider).setVisibility(View.GONE);
        } else {
            answerWrapper.findViewById(R.id.divider).setVisibility(View.VISIBLE);
            index++;
        }
    }
}
Also used : Spinner(android.widget.Spinner) LayoutInflater(android.view.LayoutInflater) QuizSubmissionAnswer(com.instructure.canvasapi2.models.QuizSubmissionAnswer) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) QuizMatchSpinnerAdapter(com.instructure.teacher.adapters.QuizMatchSpinnerAdapter) QuizSubmissionMatch(com.instructure.canvasapi2.models.QuizSubmissionMatch) LinearLayout(android.widget.LinearLayout)

Aggregations

LayoutInflater (android.view.LayoutInflater)1 LinearLayout (android.widget.LinearLayout)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 QuizSubmissionAnswer (com.instructure.canvasapi2.models.QuizSubmissionAnswer)1 QuizSubmissionMatch (com.instructure.canvasapi2.models.QuizSubmissionMatch)1 QuizMatchSpinnerAdapter (com.instructure.teacher.adapters.QuizMatchSpinnerAdapter)1 ArrayList (java.util.ArrayList)1