Search in sources :

Example 6 with CanvasContext

use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.

the class CanvasContextSpinnerAdapter method newAdapterInstance.

public static CanvasContextSpinnerAdapter newAdapterInstance(Context context, List<Course> courses, List<Group> groups) {
    ArrayList<CanvasContext> canvasContexts = new ArrayList<>();
    Course courseSeparator = new Course();
    courseSeparator.setName(context.getString(R.string.courses));
    courseSeparator.setId(COURSE_SEPARATOR);
    canvasContexts.add(courseSeparator);
    canvasContexts.addAll(courses);
    if (groups.size() > 0) {
        Course groupSeparator = new Course();
        groupSeparator.setName(context.getString(R.string.assignee_type_groups));
        groupSeparator.setId(GROUP_SEPARATOR);
        canvasContexts.add(groupSeparator);
        canvasContexts.addAll(groups);
    }
    return new CanvasContextSpinnerAdapter(context, canvasContexts);
}
Also used : ArrayList(java.util.ArrayList) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) Course(com.instructure.canvasapi2.models.Course)

Example 7 with CanvasContext

use of com.instructure.canvasapi2.models.CanvasContext 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)

Example 8 with CanvasContext

use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.

the class AddMessageFragment method onReadySetGo.

@Override
protected void onReadySetGo(AddMessagePresenter presenter) {
    setupToolbar();
    // Set conversation subject
    if (!isNewMessage && !mIsMessageStudentsWho) {
        mSubject.setText(presenter.getConversation().getSubject());
    } else if (mIsMessageStudentsWho) {
        if (mIsPersonalMessage) {
            mSubject.setVisibility(View.GONE);
            mEditSubject.setVisibility(View.VISIBLE);
            mEditSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        } else {
            mSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        }
    }
    // Set up recipients view
    mChipsTextView.setTokenizer(new Rfc822Tokenizer());
    if (mChipsAdapter == null) {
        mChipsAdapter = new RecipientAdapter(getContext());
    }
    if (mChipsTextView.getAdapter() == null) {
        mChipsTextView.setAdapter(mChipsAdapter);
    }
    if (getPresenter().getCourse().getId() != 0) {
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(getPresenter().getCourse());
    } else if (mSelectedCourse != null) {
        courseWasSelected();
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(mSelectedCourse);
    }
    ColorUtils.colorIt(ThemePrefs.getButtonColor(), mContactsButton);
    // don't show the contacts button if there is no selected course and there is no context_code from the conversation (shouldn't happen, but it does)
    if (mSelectedCourse == null && getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
        mContactsButton.setVisibility(View.INVISIBLE);
    }
    mContactsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CanvasContext canvasContext;
            if (getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
                // presenter doesn't know what the course is, use the mSelectedCourse instead
                canvasContext = mSelectedCourse;
            } else {
                canvasContext = getPresenter().getCourse();
            }
            RouteMatcher.route(getContext(), new Route(ChooseRecipientsFragment.class, canvasContext, ChooseRecipientsFragment.createBundle(canvasContext, getRecipientsFromRecipientEntries())));
        }
    });
    // Ensure attachments are up to date
    refreshAttachments();
    // get courses and groups if this is a new compose message
    if (isNewMessage) {
        getPresenter().getAllCoursesAndGroups(true);
    }
}
Also used : Rfc822Tokenizer(android.text.util.Rfc822Tokenizer) RecipientAdapter(com.instructure.teacher.adapters.RecipientAdapter) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) 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) Route(com.instructure.interactions.router.Route)

Example 9 with CanvasContext

use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.

the class PeopleListFragment method setupViews.

private void setupViews() {
    final CanvasContext canvasContext = getArguments().getParcelable(Const.CANVAS_CONTEXT);
    mToolbar.setTitle(R.string.tab_people);
    mToolbar.setSubtitle(canvasContext.getName());
    if (mToolbar.getMenu().size() == 0)
        mToolbar.inflateMenu(R.menu.menu_people_list);
    final SearchView searchView = (SearchView) mToolbar.getMenu().findItem(R.id.search).getActionView();
    MenuItemCompat.setOnActionExpandListener(mToolbar.getMenu().findItem(R.id.search), new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.GONE);
            mSwipeRefreshLayout.setEnabled(false);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(false);
            }
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.VISIBLE);
            mSwipeRefreshLayout.setEnabled(true);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(true);
            }
            getPresenter().refresh(false);
            return true;
        }
    });
    searchView.setOnQueryTextListener(this);
    if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
        mToolbar.getMenu().findItem(R.id.peopleFilter).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // let the user select the course/group they want to see
                PeopleListFilterDialog.getInstance(getActivity().getSupportFragmentManager(), getPresenter().getCanvasContextListIds(), canvasContext, true, new Function1<ArrayList<CanvasContext>, Unit>() {

                    @Override
                    public Unit invoke(ArrayList<CanvasContext> canvasContexts) {
                        mCanvasContextsSelected = new ArrayList<>();
                        mCanvasContextsSelected.addAll(canvasContexts);
                        getPresenter().setCanvasContextList(mCanvasContextsSelected);
                        setupTitle(canvasContexts);
                        return null;
                    }
                }).show(getActivity().getSupportFragmentManager(), PeopleListFilterDialog.class.getSimpleName());
                return false;
            }
        });
    }
    mClearFilterTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mPeopleFilter.setText(R.string.allPeople);
            getPresenter().clearCanvasContextList();
            mClearFilterTextView.setVisibility(View.GONE);
        }
    });
    setupTitle(getPresenter().getCanvasContextList());
    ViewStyler.themeToolbar(getActivity(), mToolbar, ColorKeeper.INSTANCE.getOrGenerateColor(canvasContext), Color.WHITE);
    ViewUtils.setupToolbarBackButton(mToolbar, this);
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) ArrayList(java.util.ArrayList) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) MenuItem(android.view.MenuItem) Unit(kotlin.Unit) SearchView(android.support.v7.widget.SearchView) EmptyPandaView(com.instructure.teacher.view.EmptyPandaView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PeopleListView(com.instructure.teacher.viewinterface.PeopleListView) SearchView(android.support.v7.widget.SearchView)

Example 10 with CanvasContext

use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.

the class RouterUtilsTest method testCreateBookmarkCourse.

@Test
public void testCreateBookmarkCourse() {
    ApiPrefs.setDomain("mobiledev.instructure.com");
    HashMap<String, String> replacementParams = new HashMap<>();
    replacementParams.put(Param.COURSE_ID, "123");
    replacementParams.put(Param.QUIZ_ID, "456");
    CanvasContext canvasContext = CanvasContext.getGenericContext(CanvasContext.Type.COURSE, 123, "");
    HashMap<String, String> queryParams = new HashMap<>();
    String url = RouterUtils.createUrl(canvasContext.getType(), QuizListFragment.class, BasicQuizViewFragment.class, replacementParams, queryParams);
    assertEquals("https://mobiledev.instructure.com/courses/123/quizzes/456", url);
}
Also used : HashMap(java.util.HashMap) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) Test(org.junit.Test)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)60 RestParams (com.instructure.canvasapi2.builders.RestParams)55 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)19 StatusCallback (com.instructure.canvasapi2.StatusCallback)8 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)7 List (java.util.List)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)6 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)5 FileFolder (com.instructure.canvasapi2.models.FileFolder)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 NonNull (android.support.annotation.NonNull)4 View (android.view.View)4 TextView (android.widget.TextView)4 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)4 Bundle (android.os.Bundle)3 ImageView (android.widget.ImageView)3 BindView (butterknife.BindView)3 Course (com.instructure.canvasapi2.models.Course)3