Search in sources :

Example 1 with VideoResponseModel

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());
            }
        }
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionEntry(org.edx.mobile.model.api.SectionEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with VideoResponseModel

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;
}
Also used : VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionEntry(org.edx.mobile.model.api.SectionEntry) CourseComponent(org.edx.mobile.model.course.CourseComponent) LinkedHashMap(java.util.LinkedHashMap) NonNull(android.support.annotation.NonNull)

Example 3 with VideoResponseModel

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;
}
Also used : TranscriptModel(org.edx.mobile.model.api.TranscriptModel) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) Nullable(android.support.annotation.Nullable)

Example 4 with VideoResponseModel

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;
}
Also used : VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SummaryModel(org.edx.mobile.model.api.SummaryModel) NonNull(android.support.annotation.NonNull)

Example 5 with VideoResponseModel

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;
}
Also used : ArrayList(java.util.ArrayList) CourseComponent(org.edx.mobile.model.course.CourseComponent) LinkedHashMap(java.util.LinkedHashMap) SectionItemModel(org.edx.mobile.model.api.SectionItemModel) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionItemInterface(org.edx.mobile.interfaces.SectionItemInterface) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ChapterModel(org.edx.mobile.model.api.ChapterModel) NonNull(android.support.annotation.NonNull)

Aggregations

VideoResponseModel (org.edx.mobile.model.api.VideoResponseModel)6 NonNull (android.support.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 SectionEntry (org.edx.mobile.model.api.SectionEntry)3 CourseComponent (org.edx.mobile.model.course.CourseComponent)3 Nullable (android.support.annotation.Nullable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SectionItemInterface (org.edx.mobile.interfaces.SectionItemInterface)1 ChapterModel (org.edx.mobile.model.api.ChapterModel)1 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)1 SectionItemModel (org.edx.mobile.model.api.SectionItemModel)1 SummaryModel (org.edx.mobile.model.api.SummaryModel)1 TranscriptModel (org.edx.mobile.model.api.TranscriptModel)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1