Search in sources :

Example 6 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseAPI method mappingCourseHierarchyFrom.

/**
 * from new CourseComponent to legacy data structure.
 * @param courseComponent
 * @return
 */
@NonNull
private static Map<String, SectionEntry> mappingCourseHierarchyFrom(@NonNull final CourseComponent courseComponent) {
    Map<String, SectionEntry> map = new HashMap<>();
    for (IBlock block : courseComponent.getChildren()) {
        CourseComponent chapter = (CourseComponent) block;
        SectionEntry entry = new SectionEntry();
        entry.chapter = chapter.getDisplayName();
        entry.isChapter = true;
        entry.section_url = chapter.getBlockUrl();
        map.put(entry.chapter, entry);
        for (IBlock subBlock : chapter.getChildren()) {
            CourseComponent section = (CourseComponent) subBlock;
            entry.sections.put(section.getDisplayName(), (ArrayList) mappingAllVideoResponseModelFrom(section, null));
        }
    }
    return map;
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SectionEntry(org.edx.mobile.model.api.SectionEntry) CourseComponent(org.edx.mobile.model.course.CourseComponent) NonNull(android.support.annotation.NonNull)

Example 7 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseComponentTest method setUp.

@Before
public void setUp() throws Exception {
    BlockModel bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.COURSE;
    bm.id = UUID.randomUUID().toString();
    course = new CourseComponent(bm, null);
    course.setCourseId(UUID.randomUUID().toString());
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.CHAPTER;
    bm.id = UUID.randomUUID().toString();
    chapter1 = new CourseComponent(bm, course);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.SECTION;
    bm.id = UUID.randomUUID().toString();
    sequential1 = new CourseComponent(bm, chapter1);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.VERTICAL;
    bm.id = UUID.randomUUID().toString();
    vertical1 = new CourseComponent(bm, sequential1);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.VIDEO;
    bm.id = UUID.randomUUID().toString();
    unit1 = new VideoBlockModel(bm, vertical1);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.HTML;
    bm.id = UUID.randomUUID().toString();
    unit2 = new CourseComponent(bm, vertical1);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.CHAPTER;
    bm.id = UUID.randomUUID().toString();
    chapter2 = new CourseComponent(bm, course);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.SECTION;
    bm.id = UUID.randomUUID().toString();
    sequential2 = new CourseComponent(bm, chapter2);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.VERTICAL;
    bm.id = UUID.randomUUID().toString();
    vertical2 = new CourseComponent(bm, sequential2);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.VIDEO;
    bm.id = UUID.randomUUID().toString();
    unit3 = new VideoBlockModel(bm, vertical2);
    bm = Mockito.mock(BlockModel.class);
    bm.type = BlockType.HTML;
    bm.id = UUID.randomUUID().toString();
    unit4 = new CourseComponent(bm, vertical2);
}
Also used : VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) BlockModel(org.edx.mobile.model.course.BlockModel) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent) Before(org.junit.Before)

Example 8 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseComponentTest method testFindWithFilter.

@Test
public void testFindWithFilter() throws Exception {
    CourseComponent found = course.find(new Filter<CourseComponent>() {

        @Override
        public boolean apply(CourseComponent component) {
            return false;
        }
    });
    assertTrue("find with filter failed", found == null);
    found = course.find(new Filter<CourseComponent>() {

        @Override
        public boolean apply(CourseComponent component) {
            return component == unit1;
        }
    });
    assertTrue("find with filter failed", found == unit1);
    found = course.find(new Filter<CourseComponent>() {

        @Override
        public boolean apply(CourseComponent component) {
            return component.getType() == BlockType.VIDEO;
        }
    });
    assertTrue("find with filter failed", found == unit1);
}
Also used : Filter(org.edx.mobile.model.Filter) CourseComponent(org.edx.mobile.model.course.CourseComponent) Test(org.junit.Test)

Example 9 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class CourseUnitWebViewFragmentTest method getHtmlUnit.

/**
 * Method for iterating through the mock course response data, and
 * returning the first video block leaf.
 *
 * @return The first {@link HtmlBlockModel} leaf in the mock course data
 */
private HtmlBlockModel getHtmlUnit() throws CourseContentNotValidException {
    EnrolledCoursesResponse courseData;
    try {
        courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    String courseId = courseData.getCourse().getId();
    CourseStructureV1Model model;
    try {
        model = executeStrict(courseAPI.getCourseStructure(courseId));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
    List<CourseComponent> htmlBlockUnits = new ArrayList<>();
    courseComponent.fetchAllLeafComponents(htmlBlockUnits, EnumSet.of(BlockType.HTML));
    return (HtmlBlockModel) htmlBlockUnits.get(0);
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 10 with CourseComponent

use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.

the class ViewPagerDownloadManagerTest method setUp.

@Before
public void setUp() throws Exception {
    // use mockito.answer is a little inconvenience, let's use fake approach
    mainComponentUI = new RunnableCourseComponent() {

        @Override
        public CourseComponent getCourseComponent() {
            return mainComponent;
        }

        @Override
        public void run() {
            ViewPagerDownloadManager.instance.done(this, true);
        }
    };
    prevComponentUI = new RunnableCourseComponent() {

        @Override
        public CourseComponent getCourseComponent() {
            return prevComponent;
        }

        @Override
        public void run() {
            ViewPagerDownloadManager.instance.done(this, true);
        }
    };
    nextComponentUI = new RunnableCourseComponent() {

        @Override
        public CourseComponent getCourseComponent() {
            return nextComponent;
        }

        @Override
        public void run() {
            ViewPagerDownloadManager.instance.done(this, true);
        }
    };
    otherComponentUI = new RunnableCourseComponent() {

        @Override
        public CourseComponent getCourseComponent() {
            return otherComponent;
        }

        @Override
        public void run() {
            ViewPagerDownloadManager.instance.done(this, true);
        }
    };
    ViewPagerDownloadManager.USING_UI_PRELOADING = true;
}
Also used : RunnableCourseComponent(org.edx.mobile.view.common.RunnableCourseComponent) RunnableCourseComponent(org.edx.mobile.view.common.RunnableCourseComponent) CourseComponent(org.edx.mobile.model.course.CourseComponent) Before(org.junit.Before)

Aggregations

CourseComponent (org.edx.mobile.model.course.CourseComponent)43 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)10 ArrayList (java.util.ArrayList)9 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)9 Bundle (android.os.Bundle)8 BlockPath (org.edx.mobile.model.course.BlockPath)8 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Test (org.junit.Test)7 View (android.view.View)6 IBlock (org.edx.mobile.model.course.IBlock)6 Intent (android.content.Intent)5 NonNull (android.support.annotation.NonNull)5 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)5 TextView (android.widget.TextView)4 IconImageView (com.joanzapata.iconify.widget.IconImageView)4 LinkedHashMap (java.util.LinkedHashMap)4 Fragment (android.support.v4.app.Fragment)3 HashMap (java.util.HashMap)3 CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)3