Search in sources :

Example 1 with CanvasContextSpinnerAdapter

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

the class AddMessageFragment method addCoursesAndGroups.

@Override
public void addCoursesAndGroups(ArrayList<Course> courses, ArrayList<Group> groups) {
    final CanvasContextSpinnerAdapter adapter = CanvasContextSpinnerAdapter.newAdapterInstance(getContext(), courses, groups);
    mCourseSpinner.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.spinner_item_nothing_selected, getContext()));
    if (mSelectedCourse != null) {
        // prevent listener from firing the when selection is placed
        mCourseSpinner.setOnItemSelectedListener(null);
        // + 1 is for the nothingSelected position
        mCourseSpinner.setSelection(adapter.getPosition(mSelectedCourse) + 1, false);
        courseWasSelected();
    }
    mCourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != 0) {
                // position zero is nothingSelected prompt
                // -1 to account for nothingSelected item
                CanvasContext canvasContext = adapter.getItem(position - 1);
                if (mSelectedCourse == null || mSelectedCourse.getId() != canvasContext.getId()) {
                    mChipsTextView.removeAllRecipientEntry();
                    mSelectedCourse = canvasContext;
                    courseWasSelected();
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : NothingSelectedSpinnerAdapter(com.instructure.teacher.adapters.NothingSelectedSpinnerAdapter) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) RecipientEditTextView(com.android.ex.chips.RecipientEditTextView) TextView(android.widget.TextView) AddMessageView(com.instructure.teacher.viewinterface.AddMessageView) AttachmentView(com.instructure.pandautils.views.AttachmentView) ScrollView(android.widget.ScrollView) CanvasContextSpinnerAdapter(com.instructure.teacher.adapters.CanvasContextSpinnerAdapter)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 RecipientEditTextView (com.android.ex.chips.RecipientEditTextView)1 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)1 AttachmentView (com.instructure.pandautils.views.AttachmentView)1 CanvasContextSpinnerAdapter (com.instructure.teacher.adapters.CanvasContextSpinnerAdapter)1 NothingSelectedSpinnerAdapter (com.instructure.teacher.adapters.NothingSelectedSpinnerAdapter)1 AddMessageView (com.instructure.teacher.viewinterface.AddMessageView)1