Search in sources :

Example 1 with ParentFragment

use of com.instructure.candroid.fragment.ParentFragment in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_page.

@Test
public void testGetFragment_page() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/pages/hello-world";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("Page");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    Course course = new Course();
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.PAGE_NAME, "hello-world");
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(PageDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 2 with ParentFragment

use of com.instructure.candroid.fragment.ParentFragment in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_file.

@Test
public void testGetFragment_file() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/assignments/123456789";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("File");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    ModuleObject moduleObject = new ModuleObject();
    moduleObject.setId(1234);
    Course course = new Course();
    String expectedUrl = "courses/222/assignments/123456789";
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.FILE_URL, expectedUrl);
    expectedBundle.putLong(Const.MODULE_ID, moduleObject.getId());
    expectedBundle.putLong(Const.ITEM_ID, moduleItem.getId());
    ParentFragment parentFragment = callGetFragment(moduleItem, course, moduleObject);
    assertNotNull(parentFragment);
    assertEquals(FileDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
    // test module object is null
    moduleObject = null;
    expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.FILE_URL, expectedUrl);
    parentFragment = callGetFragment(moduleItem, course, moduleObject);
    assertNotNull(parentFragment);
    assertEquals(FileDetailsFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ModuleObject(com.instructure.canvasapi2.models.ModuleObject) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 3 with ParentFragment

use of com.instructure.candroid.fragment.ParentFragment in project instructure-android by instructure.

the class TabHelper method getFragmentByTabId.

public static ParentFragment getFragmentByTabId(Tab tab, CanvasContext canvasContext) {
    if (tab == null) {
        return null;
    }
    String tabId = tab.getTabId();
    final Bundle standardTabBundle = ParentFragment.createBundle(canvasContext, tab);
    if (TextUtils.isEmpty(tabId)) {
        tabId = canvasContext.getHomePageID();
    }
    if (tabId.equalsIgnoreCase(canvasContext.getHomePageID()) || "home".equalsIgnoreCase(tabId)) {
        tabId = canvasContext.getHomePageID();
    }
    ParentFragment fragment = null;
    if (tabId.equalsIgnoreCase(Tab.MODULES_ID)) {
        fragment = ParentFragment.createFragment(ModuleListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.DISCUSSIONS_ID)) {
        fragment = ParentFragment.createFragment(DiscussionListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.PAGES_ID)) {
        fragment = ParentFragment.createFragment(PageListFragment.class, PageListFragment.createBundle(canvasContext, false, tab));
    } else if (tabId.equalsIgnoreCase(Tab.PEOPLE_ID)) {
        fragment = ParentFragment.createFragment(PeopleListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.FILES_ID)) {
        fragment = ParentFragment.createFragment(FileListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.SYLLABUS_ID)) {
        fragment = ParentFragment.createFragment(ScheduleListFragment.class, ScheduleListFragment.createBundle(canvasContext, true, tab));
    } else if (tabId.equalsIgnoreCase(Tab.QUIZZES_ID)) {
        fragment = ParentFragment.createFragment(QuizListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.OUTCOMES_ID)) {
        fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(canvasContext, tab.getTabId(), R.string.outcomes));
    } else if (tabId.equalsIgnoreCase(Tab.CONFERENCES_ID)) {
        fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(canvasContext, tab.getTabId(), R.string.conferences));
    } else if (tabId.equalsIgnoreCase(Tab.ANNOUNCEMENTS_ID)) {
        fragment = ParentFragment.createFragment(AnnouncementListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.ASSIGNMENTS_ID)) {
        fragment = ParentFragment.createFragment(AssignmentListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.GRADES_ID)) {
        fragment = ParentFragment.createFragment(GradesListFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.COLLABORATIONS_ID)) {
        fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(canvasContext, tab.getTabId(), R.string.collaborations));
    } else if (tabId.equalsIgnoreCase(Tab.SETTINGS_ID)) {
        fragment = ParentFragment.createFragment(CourseSettingsFragment.class, standardTabBundle);
    } else if (tabId.equalsIgnoreCase(Tab.NOTIFICATIONS_ID)) {
        fragment = ParentFragment.createFragment(NotificationListFragment.class, standardTabBundle);
    } else // we just care if it's external, some external tabs (Attendance) have an id after "external"
    if (tabId.contains(Tab.TYPE_EXTERNAL)) {
        // Assumes we are not routing from a link, if so use LTIWebViewRoutingFragment.class
        fragment = ParentFragment.createFragment(LTIWebViewFragment.class, LTIWebViewFragment.Companion.createBundle(canvasContext, tab));
    }
    return fragment;
}
Also used : FileListFragment(com.instructure.candroid.fragment.FileListFragment) ParentFragment(com.instructure.candroid.fragment.ParentFragment) NotificationListFragment(com.instructure.candroid.fragment.NotificationListFragment) PageListFragment(com.instructure.candroid.fragment.PageListFragment) UnSupportedTabFragment(com.instructure.candroid.fragment.UnSupportedTabFragment) AssignmentListFragment(com.instructure.candroid.fragment.AssignmentListFragment) Bundle(android.os.Bundle) QuizListFragment(com.instructure.candroid.fragment.QuizListFragment) ModuleListFragment(com.instructure.candroid.fragment.ModuleListFragment)

Example 4 with ParentFragment

use of com.instructure.candroid.fragment.ParentFragment in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_externalurl_externaltool.

@Test
public void testGetFragment_externalurl_externaltool() {
    String url = "https://instructure.com";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("ExternalUrl");
    moduleItem.setId(4567);
    moduleItem.setTitle("Hello");
    moduleItem.setHtml_url(url);
    Course course = new Course();
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.INTERNAL_URL, "https://instructure.com?display=borderless");
    expectedBundle.putString(Const.ACTION_BAR_TITLE, "Hello");
    expectedBundle.putBoolean(Const.AUTHENTICATE, true);
    expectedBundle.putBoolean(com.instructure.pandautils.utils.Const.IS_EXTERNAL_TOOL, true);
    expectedBundle.putBoolean(com.instructure.pandautils.utils.Const.IS_UNSUPPORTED_FEATURE, true);
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(InternalWebviewFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
    // test external tool type
    moduleItem.setType("ExternalTool");
    parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(InternalWebviewFragment.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 5 with ParentFragment

use of com.instructure.candroid.fragment.ParentFragment in project instructure-android by instructure.

the class ModuleUtilityTest method testGetFragment_quiz.

@Test
public void testGetFragment_quiz() {
    String url = "https://mobile.canvas.net/api/v1/courses/222/quizzes/123456789";
    ModuleItem moduleItem = new ModuleItem();
    moduleItem.setType("Quiz");
    moduleItem.setId(4567);
    moduleItem.setUrl(url);
    Course course = new Course();
    String htmlUrl = "https://mobile.canvas.net/courses/222/quizzes/123456789";
    String apiUrl = "courses/222/quizzes/123456789";
    moduleItem.setHtml_url(htmlUrl);
    Bundle expectedBundle = new Bundle();
    expectedBundle.putSerializable(Const.CANVAS_CONTEXT, course);
    expectedBundle.putString(Const.URL, htmlUrl);
    expectedBundle.putString(Const.API_URL, apiUrl);
    ParentFragment parentFragment = callGetFragment(moduleItem, course, null);
    assertNotNull(parentFragment);
    assertEquals(ModuleQuizDecider.class, parentFragment.getClass());
    assertEquals(expectedBundle.toString(), parentFragment.getArguments().toString());
}
Also used : ModuleItem(com.instructure.canvasapi2.models.ModuleItem) ParentFragment(com.instructure.candroid.fragment.ParentFragment) Bundle(android.os.Bundle) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Aggregations

ParentFragment (com.instructure.candroid.fragment.ParentFragment)8 Bundle (android.os.Bundle)7 Course (com.instructure.canvasapi2.models.Course)7 ModuleItem (com.instructure.canvasapi2.models.ModuleItem)7 Test (org.junit.Test)7 AssignmentListFragment (com.instructure.candroid.fragment.AssignmentListFragment)1 FileListFragment (com.instructure.candroid.fragment.FileListFragment)1 ModuleListFragment (com.instructure.candroid.fragment.ModuleListFragment)1 NotificationListFragment (com.instructure.candroid.fragment.NotificationListFragment)1 PageListFragment (com.instructure.candroid.fragment.PageListFragment)1 QuizListFragment (com.instructure.candroid.fragment.QuizListFragment)1 UnSupportedTabFragment (com.instructure.candroid.fragment.UnSupportedTabFragment)1 ModuleObject (com.instructure.canvasapi2.models.ModuleObject)1