use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class NewCourseOutlineAdapter method getRowViewForLeaf.
private void getRowViewForLeaf(ViewHolder viewHolder, final SectionRow row) {
final CourseComponent unit = row.component;
viewHolder.rowType.setVisibility(View.VISIBLE);
viewHolder.rowSubtitleIcon.setVisibility(View.GONE);
viewHolder.rowSubtitleDueDate.setVisibility(View.GONE);
viewHolder.rowSubtitle.setVisibility(View.GONE);
viewHolder.rowSubtitlePanel.setVisibility(View.GONE);
viewHolder.bulkDownload.setVisibility(View.INVISIBLE);
viewHolder.rowTitle.setText(unit.getDisplayName());
if (row.component instanceof VideoBlockModel) {
final VideoBlockModel videoBlockModel = (VideoBlockModel) row.component;
final DownloadEntry videoData = videoBlockModel.getDownloadEntry(storage);
if (null != videoData) {
updateUIForVideo(viewHolder, videoData, videoBlockModel);
return;
}
}
if (config.isDiscussionsEnabled() && row.component instanceof DiscussionBlockModel) {
viewHolder.rowType.setIcon(FontAwesomeIcons.fa_comments_o);
checkAccessStatus(viewHolder, unit);
} else if (!unit.isMultiDevice()) {
// If we reach here & the type is VIDEO, it means the video is webOnly
viewHolder.bulkDownload.setVisibility(View.INVISIBLE);
viewHolder.rowType.setIcon(FontAwesomeIcons.fa_laptop);
viewHolder.rowType.setIconColorResource(R.color.edx_brand_gray_accent);
} else {
viewHolder.bulkDownload.setVisibility(View.INVISIBLE);
if (unit.getType() == BlockType.PROBLEM) {
viewHolder.rowType.setIcon(FontAwesomeIcons.fa_list);
} else {
viewHolder.rowType.setIcon(FontAwesomeIcons.fa_file_o);
}
checkAccessStatus(viewHolder, unit);
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class NewCourseOutlineAdapter method getRowViewForContainer.
private void getRowViewForContainer(ViewHolder holder, final SectionRow row) {
final CourseComponent component = row.component;
String courseId = component.getCourseId();
BlockPath path = component.getPath();
// FIXME - we should add a new column in database - pathinfo.
// then do the string match to get the record
String chapterId = path.get(1) == null ? "" : path.get(1).getDisplayName();
String sequentialId = path.get(2) == null ? "" : path.get(2).getDisplayName();
holder.rowTitle.setText(component.getDisplayName());
holder.numOfVideoAndDownloadArea.setVisibility(View.VISIBLE);
if (component.isGraded()) {
holder.bulkDownload.setVisibility(View.INVISIBLE);
holder.rowSubtitlePanel.setVisibility(View.VISIBLE);
holder.rowSubtitleIcon.setVisibility(View.VISIBLE);
holder.rowSubtitle.setVisibility(View.VISIBLE);
holder.rowSubtitle.setText(component.getFormat());
holder.rowSubtitle.setTypeface(holder.rowSubtitle.getTypeface(), Typeface.BOLD);
holder.rowSubtitle.setTextColor(ContextCompat.getColor(context, R.color.edx_brand_gray_dark));
if (!TextUtils.isEmpty(component.getDueDate())) {
try {
holder.rowSubtitleDueDate.setText(getFormattedDueDate(component.getDueDate()));
holder.rowSubtitleDueDate.setVisibility(View.VISIBLE);
} catch (IllegalArgumentException e) {
logger.error(e);
}
}
}
final int totalDownloadableVideos = component.getDownloadableVideosCount();
// support video download for video type excluding the ones only viewable on web
if (totalDownloadableVideos == 0) {
holder.numOfVideoAndDownloadArea.setVisibility(View.GONE);
} else {
holder.bulkDownload.setVisibility(View.VISIBLE);
holder.noOfVideos.setVisibility(View.VISIBLE);
holder.noOfVideos.setText("" + totalDownloadableVideos);
Integer downloadedCount = dbStore.getDownloadedVideosCountForSection(courseId, chapterId, sequentialId, null);
if (downloadedCount == totalDownloadableVideos) {
holder.noOfVideos.setVisibility(View.VISIBLE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADED, null);
} else if (dbStore.getDownloadingVideosCountForSection(courseId, chapterId, sequentialId, null) + downloadedCount == totalDownloadableVideos) {
holder.noOfVideos.setVisibility(View.GONE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADING, new View.OnClickListener() {
@Override
public void onClick(View downloadView) {
downloadListener.viewDownloadsStatus();
}
});
} else {
holder.noOfVideos.setVisibility(View.VISIBLE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.ONLINE, new View.OnClickListener() {
@Override
public void onClick(View downloadView) {
final List<VideoBlockModel> downloadableVideos = (List<VideoBlockModel>) (List) component.getVideos(true);
for (VideoBlockModel videoBlockModel : downloadableVideos) {
/**
* Assign preferred downloadable url to {@link VideoBlockModel#downloadUrl},
* to use this url to download. After downloading only downloaded
* video path will be used for streaming.
*/
videoBlockModel.setDownloadUrl(VideoUtil.getPreferredVideoUrlForDownloading(videoBlockModel.getData()));
}
downloadListener.download(downloadableVideos);
}
});
}
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseManager method getCourseDataFromPersistableCache.
/**
* Obtain the course data from persistable cache.
* <p>
* <b>WARNING:</b> This function takes time and should call asynchronously.
* {@link CourseManager#getCourseDataFromAppLevelCache} can be used as an alternate, specially
* if its sure course data will be available in app level cache.
*
* @param courseId Id of the course.
* @return Cached course data. In case course data is not present in cache it will return null.
*/
@Nullable
public CourseComponent getCourseDataFromPersistableCache(@NonNull final String courseId) {
try {
final CourseComponent component = courseApi.getCourseStructureFromCache(courseId);
addCourseDataInAppLevelCache(courseId, component);
return component;
} catch (Exception e) {
// Course data doesn't exist in cache
return null;
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseComponentTest method testGetCommonAncestor.
@Test
public void testGetCommonAncestor() throws Exception {
CourseComponent common = CourseComponent.getCommonAncestor(unit1, unit2);
assertTrue("testGetCommonAncestor failed", common == vertical1);
common = CourseComponent.getCommonAncestor(unit2, unit3);
assertTrue("testGetCommonAncestor failed", common == course);
common = CourseComponent.getCommonAncestor(unit1, sequential1);
assertTrue("testGetCommonAncestor failed", common == sequential1);
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class ApiTests method testGetCourseStructure.
@Test
public void testGetCourseStructure() throws Exception {
login();
// General overall testing of CourseComponent API without recursion
EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
final String courseId = e.getCourse().getId();
final CourseStructureV1Model model = executeStrict(courseAPI.getCourseStructure(courseId));
final CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
assertNotNull(courseComponent);
assertNotNull(courseComponent.getRoot());
assertEquals(courseId, courseComponent.getCourseId());
List<IBlock> children = courseComponent.getChildren();
assertNotNull(children);
List<CourseComponent> childContainers = new ArrayList<>();
List<CourseComponent> childLeafs = new ArrayList<>();
for (IBlock c : children) {
assertTrue(c instanceof CourseComponent);
final CourseComponent child = (CourseComponent) c;
assertEquals(child, courseComponent.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return child.getId().equals(component.getId());
}
}));
List<IBlock> grandchildren = child.getChildren();
for (IBlock gc : grandchildren) {
assertTrue(gc instanceof CourseComponent);
final CourseComponent grandchild = (CourseComponent) c;
assertEquals(grandchild, courseComponent.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return grandchild.getId().equals(component.getId());
}
}));
}
assertNull(child.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return courseComponent.getId().equals(component.getId());
}
}));
if (child.isContainer()) {
childContainers.add(child);
} else {
childLeafs.add(child);
}
}
assertEquals(childContainers, courseComponent.getChildContainers());
assertEquals(childLeafs, courseComponent.getChildLeafs());
assertTrue(courseComponent.isLastChild());
int childrenSize = children.size();
assertTrue(childrenSize > 0);
assertTrue(((CourseComponent) children.get(childrenSize - 1)).isLastChild());
BlockType blockType = courseComponent.getType();
assertSame(courseComponent, courseComponent.getAncestor(Integer.MAX_VALUE));
assertSame(courseComponent, courseComponent.getAncestor(EnumSet.of(blockType)));
List<VideoBlockModel> videos = courseComponent.getVideos();
assertNotNull(videos);
for (HasDownloadEntry video : videos) {
assertNotNull(video);
assertTrue(video instanceof CourseComponent);
CourseComponent videoComponent = (CourseComponent) video;
assertFalse(videoComponent.isContainer());
assertEquals(BlockType.VIDEO, videoComponent.getType());
}
for (BlockType type : BlockType.values()) {
EnumSet<BlockType> typeSet = EnumSet.of(type);
List<CourseComponent> typeComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(typeComponents, typeSet);
for (CourseComponent typeComponent : typeComponents) {
assertEquals(type, typeComponent.getType());
verifyModelParsing(typeComponent);
}
if (type != blockType) {
assertNotSame(courseComponent, courseComponent.getAncestor(EnumSet.of(type)));
}
}
BlockPath path = courseComponent.getPath();
assertNotNull(path);
assertEquals(1, path.getPath().size());
assertSame(courseComponent, path.get(0));
List<CourseComponent> leafComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
for (CourseComponent leafComponent : leafComponents) {
BlockPath leafPath = leafComponent.getPath();
assertNotNull(leafPath);
int pathSize = leafPath.getPath().size();
assertTrue(pathSize > 1);
CourseComponent component = leafComponent;
for (int i = pathSize - 1; i >= 0; i--) {
assertSame(component, leafPath.get(i));
component = component.getParent();
}
}
}
Aggregations