use of org.edx.mobile.model.api.VideoResponseModel 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.VideoResponseModel 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;
}
use of org.edx.mobile.model.api.VideoResponseModel in project edx-app-android by edx.
the class CourseAPI method getTranscriptsOfVideo.
@Nullable
public TranscriptModel getTranscriptsOfVideo(@NonNull final String enrollmentId, @NonNull final String videoId) throws Exception {
TranscriptModel transcript;
VideoResponseModel vidModel = getVideoById(enrollmentId, videoId);
if (vidModel != null) {
if (vidModel.getSummary() != null) {
transcript = vidModel.getSummary().getTranscripts();
return transcript;
}
}
return null;
}
use of org.edx.mobile.model.api.VideoResponseModel in project edx-app-android by edx.
the class CourseAPI method mappingVideoResponseModelFrom.
/**
* from new VideoBlockModel to legacy VideoRsponseModel
* @param videoBlockModel
* @return
*/
@NonNull
private static VideoResponseModel mappingVideoResponseModelFrom(@NonNull final VideoBlockModel videoBlockModel) {
VideoResponseModel model = new VideoResponseModel();
model.setCourseId(videoBlockModel.getCourseId());
SummaryModel summaryModel = mappingSummaryModelFrom(videoBlockModel);
model.setSummary(summaryModel);
model.videoBlockModel = videoBlockModel;
model.setSectionUrl(videoBlockModel.getParent().getBlockUrl());
model.setUnitUrl(videoBlockModel.getBlockUrl());
return model;
}
use of org.edx.mobile.model.api.VideoResponseModel 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