use of org.edx.mobile.model.api.SectionEntry 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.api.SectionEntry in project edx-app-android by edx.
the class ApiTests method testSyncLastSubsection.
// TODO: Debug and fix test failure
@Ignore
@Test
public void testSyncLastSubsection() throws Exception {
login();
EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
Map<String, SectionEntry> map = courseAPI.getCourseHierarchy(e.getCourse().getId());
Entry<String, SectionEntry> entry = map.entrySet().iterator().next();
Entry<String, ArrayList<VideoResponseModel>> subsection = entry.getValue().sections.entrySet().iterator().next();
String courseId = e.getCourse().getId();
String lastVisitedModuleId = subsection.getValue().get(0).getSection().getId();
assertNotNull(courseId);
assertNotNull(lastVisitedModuleId);
print(String.format("course= %s ; sub-section= %s", courseId, lastVisitedModuleId));
// TODO: lastVisitedModuleId must be section.id (id is now available)
SyncLastAccessedSubsectionResponse model = executeStrict(courseAPI.syncLastAccessedSubsection(courseId, lastVisitedModuleId));
assertNotNull(model);
print("sync returned: " + model.last_visited_module_id);
}
use of org.edx.mobile.model.api.SectionEntry in project edx-app-android by edx.
the class ApiTests method testCourseStructure.
// TODO: Debug and fix test failure
@Ignore
@Test
public void testCourseStructure() throws Exception {
login();
// get a course id for this test
List<EnrolledCoursesResponse> courses = executeStrict(courseAPI.getEnrolledCourses());
assertTrue("Must have enrolled to at least one course", courses != null && courses.size() > 0);
String courseId = courses.get(0).getCourse().getId();
Map<String, SectionEntry> chapters = courseAPI.getCourseHierarchy(courseId);
for (Entry<String, SectionEntry> entry : chapters.entrySet()) {
print("---------------" + entry.getKey() + "---------------");
for (Entry<String, ArrayList<VideoResponseModel>> se : entry.getValue().sections.entrySet()) {
print("------------" + se.getKey() + "------------");
for (VideoResponseModel v : se.getValue()) {
print(v.getSummary().getDisplayName());
}
}
}
}
use of org.edx.mobile.model.api.SectionEntry in project edx-app-android by edx.
the class ChapterAdapter method onItemClick.
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
// This has been used so that if user clicks continuously on the screen,
// two activities should not be opened
long currentTime = SystemClock.elapsedRealtime();
if (currentTime - lastClickTime > MIN_CLICK_INTERVAL) {
lastClickTime = currentTime;
SectionEntry model = getItem(position);
if (model != null)
onItemClicked(model);
}
}
use of org.edx.mobile.model.api.SectionEntry in project edx-app-android by edx.
the class CourseAPI method getCourseHierarchy.
@NonNull
public Map<String, SectionEntry> getCourseHierarchy(@NonNull final String courseId) throws Exception {
CourseComponent course = this.getCourseStructureFromCache(courseId);
if (course != null) {
return mappingCourseHierarchyFrom(course);
}
List<VideoResponseModel> list = executeStrict(courseService.getVideosByCourseId(courseId));
// create hierarchy with chapters, sections and subsections
// HashMap<String, SectionEntry> chapterMap = new HashMap<String, SectionEntry>();
Map<String, SectionEntry> chapterMap = new LinkedHashMap<String, SectionEntry>();
for (VideoResponseModel m : list) {
// add each video to its corresponding chapter and section
// add this as a chapter
String cname = m.getChapter().getDisplayName();
// carry this courseId with video model
m.setCourseId(courseId);
SectionEntry s = null;
if (chapterMap.containsKey(cname)) {
s = chapterMap.get(cname);
} else {
s = new SectionEntry();
s.chapter = cname;
s.isChapter = true;
s.section_url = m.getSectionUrl();
chapterMap.put(cname, s);
}
// add this video to section inside in this chapter
ArrayList<VideoResponseModel> videos = s.sections.get(m.getSection().getDisplayName());
if (videos == null) {
s.sections.put(m.getSection().getDisplayName(), new ArrayList<VideoResponseModel>());
videos = s.sections.get(m.getSection().getDisplayName());
}
videos.add(m);
}
return chapterMap;
}
Aggregations