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