Search in sources :

Example 1 with IBlock

use of org.edx.mobile.model.course.IBlock 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 IBlock

use of org.edx.mobile.model.course.IBlock in project edx-app-android by edx.

the class CourseAPI method getLecture.

/**
 * we handle both name and id for backward compatibility. legacy code use name, it is not a good idea as name is not
 * grantee to be unique.
 */
@Nullable
public LectureModel getLecture(@NonNull final CourseComponent courseComponent, @NonNull final String chapterName, @NonNull final String chapterId, @NonNull final String lectureName, @NonNull final String lectureId) throws Exception {
    // TODO - we may use a generic filter to fetch the data?
    for (IBlock chapter : courseComponent.getChildren()) {
        if (chapter.getId().equals(chapterId)) {
            for (IBlock lecture : chapter.getChildren()) {
                // TODO - check to see if need to compare id or not
                if (lecture.getId().equals(lectureId)) {
                    LectureModel lm = new LectureModel();
                    lm.name = lecture.getDisplayName();
                    lm.videos = (ArrayList) mappingAllVideoResponseModelFrom((CourseComponent) lecture, null);
                    return lm;
                }
            }
        }
    }
    // if we can not find object by id, try to get by name.
    for (IBlock chapter : courseComponent.getChildren()) {
        if (chapter.getDisplayName().equals(chapterName)) {
            for (IBlock lecture : chapter.getChildren()) {
                // TODO - check to see if need to compare id or not
                if (lecture.getDisplayName().equals(lectureName)) {
                    LectureModel lm = new LectureModel();
                    lm.name = lecture.getDisplayName();
                    lm.videos = (ArrayList) mappingAllVideoResponseModelFrom((CourseComponent) lecture, null);
                    return lm;
                }
            }
        }
    }
    return null;
}
Also used : LectureModel(org.edx.mobile.model.api.LectureModel) IBlock(org.edx.mobile.model.course.IBlock) Nullable(android.support.annotation.Nullable)

Example 3 with IBlock

use of org.edx.mobile.model.course.IBlock in project edx-app-android by edx.

the class CourseOutlineAdapter method setData.

/**
 * component can be null.
 *
 * @IComponent component should be ICourse
 */
public void setData(CourseComponent component) {
    if (component != null && !component.isContainer())
        // 
        return;
    this.rootComponent = component;
    mData.clear();
    if (rootComponent != null) {
        List<IBlock> children = rootComponent.getChildren();
        for (IBlock block : children) {
            CourseComponent comp = (CourseComponent) block;
            if (isVideoMode && comp.getVideos().size() == 0)
                continue;
            if (comp.isContainer()) {
                SectionRow header = new SectionRow(SectionRow.SECTION, comp);
                mData.add(header);
                for (IBlock childBlock : comp.getChildren()) {
                    CourseComponent child = (CourseComponent) childBlock;
                    if (isVideoMode && child.getVideos().size() == 0)
                        continue;
                    SectionRow row = new SectionRow(SectionRow.ITEM, false, child);
                    mData.add(row);
                }
            } else {
                SectionRow row = new SectionRow(SectionRow.ITEM, true, comp);
                mData.add(row);
            }
        }
    }
    notifyDataSetChanged();
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 4 with IBlock

use of org.edx.mobile.model.course.IBlock in project edx-app-android by edx.

the class NewCourseOutlineAdapter method setData.

/**
 * Set the data for adapter to populate the listview.
 *
 * @param component The CourseComponent to extract data from.
 */
public void setData(@Nullable CourseComponent component) {
    if (component != null && !component.isContainer())
        // 
        return;
    this.rootComponent = component;
    clearCourseOutlineData();
    if (rootComponent != null) {
        List<IBlock> children = rootComponent.getChildren();
        for (IBlock block : children) {
            CourseComponent comp = (CourseComponent) block;
            if (isVideoMode && comp.getVideos().size() == 0)
                continue;
            if (comp.isContainer()) {
                SectionRow header = new SectionRow(SectionRow.SECTION, comp);
                adapterData.add(header);
                for (IBlock childBlock : comp.getChildren()) {
                    CourseComponent child = (CourseComponent) childBlock;
                    if (isVideoMode && child.getVideos().size() == 0)
                        continue;
                    SectionRow row = new SectionRow(SectionRow.ITEM, false, child);
                    adapterData.add(row);
                }
            } else {
                SectionRow row = new SectionRow(SectionRow.ITEM, true, comp);
                adapterData.add(row);
            }
        }
        if (isVideoMode && rootComponent.getDownloadableVideosCount() == 0) {
            // Remove bulk video download row if the course has NO downloadable videos
            if (adapterData.size() > 0 && adapterData.get(0).type == SectionRow.BULK_DOWNLOAD) {
                adapterData.remove(0);
            }
        }
    }
    notifyDataSetChanged();
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 5 with IBlock

use of org.edx.mobile.model.course.IBlock in project edx-app-android by edx.

the class DatabaseModelFactory method getModel.

/**
 * Returns an object of IVideoModel which has all the fields copied from given VideoData.
 *
 * @param vrm
 * @return
 */
public static VideoModel getModel(VideoData vrm, VideoBlockModel block) {
    DownloadEntry e = new DownloadEntry();
    // FIXME - current database schema is not suitable for arbitary level of course structure tree
    // solution - store the navigation path info in into one column field in the database,
    // rather than individual column fields.
    BlockPath path = block.getPath();
    e.chapter = path.get(1) == null ? "" : path.get(1).getDisplayName();
    e.section = path.get(2) == null ? "" : path.get(2).getDisplayName();
    IBlock root = block.getRoot();
    e.eid = root.getCourseId();
    e.duration = vrm.duration;
    final VideoInfo preferredVideoInfo = vrm.encodedVideos.getPreferredVideoInfo();
    e.size = preferredVideoInfo.fileSize;
    e.title = block.getDisplayName();
    e.url = preferredVideoInfo.url;
    e.url_high_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.mobileHigh);
    e.url_low_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.mobileLow);
    e.url_youtube = getVideoNetworkUrlOrNull(vrm.encodedVideos.youtube);
    e.videoId = block.getId();
    e.transcript = vrm.transcripts;
    e.lmsUrl = block.getBlockUrl();
    e.isVideoForWebOnly = vrm.onlyOnWeb;
    return e;
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) IBlock(org.edx.mobile.model.course.IBlock) VideoInfo(org.edx.mobile.model.course.VideoInfo) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Aggregations

IBlock (org.edx.mobile.model.course.IBlock)8 CourseComponent (org.edx.mobile.model.course.CourseComponent)6 ArrayList (java.util.ArrayList)3 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)3 BlockPath (org.edx.mobile.model.course.BlockPath)3 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)3 Test (org.junit.Test)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Fragment (android.support.v4.app.Fragment)2 BlockType (org.edx.mobile.model.course.BlockType)2 ShadowActivity (org.robolectric.shadows.ShadowActivity)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Filter (org.edx.mobile.model.Filter)1 LectureModel (org.edx.mobile.model.api.LectureModel)1 SectionEntry (org.edx.mobile.model.api.SectionEntry)1