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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations