Search in sources :

Example 1 with Route

use of com.instructure.interactions.router.Route 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 2 with Route

use of com.instructure.interactions.router.Route in project instructure-android by instructure.

the class RouteTest method testRouteOneIntParam.

@Test
public void testRouteOneIntParam() {
    HashMap<String, String> expectedParams = new HashMap<>();
    expectedParams.put("course_id", "953090");
    Route route = new Route("/(?:courses|groups)/:course_id");
    assertTrue(route.apply("http://mobiledev.instructure.com/courses/953090/"));
    assertEquals(expectedParams, route.getParamsHash());
    // Test with a optional slash at the end
    route = new Route("/courses/:course_id/");
    // no slash at the end
    assertTrue(route.apply("http://mobiledev.instructure.com/courses/953090"));
    assertEquals(expectedParams, route.getParamsHash());
}
Also used : HashMap(java.util.HashMap) Route(com.instructure.interactions.router.Route) Test(org.junit.Test)

Example 3 with Route

use of com.instructure.interactions.router.Route in project instructure-android by instructure.

the class RouteTest method testRouteTwoIntParams.

@Test
public void testRouteTwoIntParams() {
    HashMap<String, String> expectedParams = new HashMap<>();
    expectedParams.put("course_id", "833052");
    expectedParams.put("file_id", "39506637");
    Route route = new Route("/courses/:course_id/files/:file_id");
    assertTrue(route.apply("https://mobiledev.instructure.com/courses/833052/files/39506637/"));
    assertEquals(expectedParams, route.getParamsHash());
    // no slash at the end
    assertTrue(route.apply("https://mobiledev.instructure.com/courses/833052/files/39506637"));
    assertEquals(expectedParams, route.getParamsHash());
}
Also used : HashMap(java.util.HashMap) Route(com.instructure.interactions.router.Route) Test(org.junit.Test)

Example 4 with Route

use of com.instructure.interactions.router.Route in project instructure-android by instructure.

the class PeopleListFragment method getAdapter.

@Override
protected PeopleListRecyclerAdapter getAdapter() {
    if (mAdapter == null) {
        mAdapter = new PeopleListRecyclerAdapter(getContext(), getPresenter(), new AdapterToFragmentCallback<User>() {

            @Override
            public void onRowClicked(User user, int position) {
                CanvasContext canvasContext = getArguments().getParcelable(Const.CANVAS_CONTEXT);
                if (CanvasContextExtensions.isDesigner(canvasContext)) {
                    Toast.makeText(getContext(), R.string.errorIsDesigner, Toast.LENGTH_SHORT).show();
                    return;
                }
                Bundle bundle = StudentContextFragment.makeBundle(user.getId(), canvasContext.getId(), true);
                RouteMatcher.route(getContext(), new Route(null, StudentContextFragment.class, canvasContext, bundle));
            }
        });
    }
    return mAdapter;
}
Also used : User(com.instructure.canvasapi2.models.User) Bundle(android.os.Bundle) AdapterToFragmentCallback(com.instructure.teacher.interfaces.AdapterToFragmentCallback) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) StudentContextFragment(com.instructure.teacher.adapters.StudentContextFragment) PeopleListRecyclerAdapter(com.instructure.teacher.adapters.PeopleListRecyclerAdapter) Route(com.instructure.interactions.router.Route)

Example 5 with Route

use of com.instructure.interactions.router.Route in project instructure-android by instructure.

the class RouteTest method testRouteMatching.

// region Matching
@Test
public void testRouteMatching() {
    Route route = new Route("/courses");
    assertFalse(route.apply("http://mobiledev.instructure.com/courses/953090/"));
    // no slash at the end
    assertFalse(route.apply("http://mobiledev.instructure.com/courses/953090"));
}
Also used : Route(com.instructure.interactions.router.Route) Test(org.junit.Test)

Aggregations

Route (com.instructure.interactions.router.Route)12 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Bundle (android.os.Bundle)3 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)2 Rfc822Tokenizer (android.text.util.Rfc822Tokenizer)1 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 User (com.instructure.canvasapi2.models.User)1 AttachmentView (com.instructure.pandautils.views.AttachmentView)1 PeopleListRecyclerAdapter (com.instructure.teacher.adapters.PeopleListRecyclerAdapter)1 RecipientAdapter (com.instructure.teacher.adapters.RecipientAdapter)1 StudentContextFragment (com.instructure.teacher.adapters.StudentContextFragment)1 AdapterToFragmentCallback (com.instructure.teacher.interfaces.AdapterToFragmentCallback)1 AddMessageView (com.instructure.teacher.viewinterface.AddMessageView)1