Search in sources :

Example 6 with VideoResponseModel

use of org.edx.mobile.model.api.VideoResponseModel in project edx-app-android by edx.

the class CourseAPI method getVideoById.

@Nullable
public VideoResponseModel getVideoById(@NonNull final String courseId, @NonNull final String videoId) throws Exception {
    CourseComponent course = this.getCourseStructureFromCache(courseId);
    if (course == null) {
        return getVideoById(course, videoId);
    }
    Map<String, SectionEntry> map = getCourseHierarchy(courseId);
    // iterate chapters
    for (Map.Entry<String, SectionEntry> chapterentry : map.entrySet()) {
        // iterate lectures
        for (Map.Entry<String, ArrayList<VideoResponseModel>> entry : chapterentry.getValue().sections.entrySet()) {
            // iterate videos
            for (VideoResponseModel v : entry.getValue()) {
                // identify the video
                if (videoId.equals(v.getSummary().getId())) {
                    return v;
                }
            }
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionEntry(org.edx.mobile.model.api.SectionEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CourseComponent(org.edx.mobile.model.course.CourseComponent) Nullable(android.support.annotation.Nullable)

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