Search in sources :

Example 1 with SectionEntry

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

Example 2 with SectionEntry

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

Example 3 with SectionEntry

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());
            }
        }
    }
}
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 4 with SectionEntry

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);
    }
}
Also used : SectionEntry(org.edx.mobile.model.api.SectionEntry)

Example 5 with SectionEntry

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;
}
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)

Aggregations

SectionEntry (org.edx.mobile.model.api.SectionEntry)6 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 VideoResponseModel (org.edx.mobile.model.api.VideoResponseModel)3 CourseComponent (org.edx.mobile.model.course.CourseComponent)3 NonNull (android.support.annotation.NonNull)2 HashMap (java.util.HashMap)2 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 Nullable (android.support.annotation.Nullable)1 Map (java.util.Map)1 SyncLastAccessedSubsectionResponse (org.edx.mobile.model.api.SyncLastAccessedSubsectionResponse)1 IBlock (org.edx.mobile.model.course.IBlock)1