use of org.edx.mobile.model.api.ChapterModel in project edx-app-android by edx.
the class CourseAPI method getLiveOrganizedVideosByChapter.
@NonNull
public List<SectionItemInterface> getLiveOrganizedVideosByChapter(@NonNull final String courseId, @NonNull final String chapter) throws Exception {
CourseComponent course = this.getCourseStructureFromCache(courseId);
if (course != null) {
return mappingAllVideoResponseModelFrom(course, new Filter<VideoResponseModel>() {
@Override
public boolean apply(VideoResponseModel videoResponseModel) {
return videoResponseModel != null && videoResponseModel.getChapterName().equals(chapter);
}
});
}
List<VideoResponseModel> videos = executeStrict(courseService.getVideosByCourseId(courseId));
ArrayList<SectionItemInterface> list = new ArrayList<SectionItemInterface>();
// add chapter to the result
ChapterModel c = new ChapterModel();
c.name = chapter;
list.add(c);
HashMap<String, ArrayList<VideoResponseModel>> sections = new LinkedHashMap<String, ArrayList<VideoResponseModel>>();
for (VideoResponseModel v : videos) {
// filter videos by chapter
if (v.getChapter().getDisplayName().equals(chapter)) {
// sort out the section of this video
if (sections.containsKey(v.getSection().getDisplayName())) {
ArrayList<VideoResponseModel> sv = sections.get(v.getSection().getDisplayName());
if (sv == null) {
sv = new ArrayList<VideoResponseModel>();
}
sv.add(v);
} else {
ArrayList<VideoResponseModel> vlist = new ArrayList<VideoResponseModel>();
vlist.add(v);
sections.put(v.getSection().getDisplayName(), vlist);
}
}
}
// now add sectioned videos to the result
for (Map.Entry<String, ArrayList<VideoResponseModel>> entry : sections.entrySet()) {
// add section to the result
SectionItemModel s = new SectionItemModel();
s.name = entry.getKey();
list.add(s);
// add videos to the result
if (entry.getValue() != null) {
for (VideoResponseModel v : entry.getValue()) {
list.add(v);
}
}
}
return list;
}
Aggregations