use of org.edx.mobile.model.course.HasDownloadEntry in project edx-app-android by edx.
the class VideoDownloadHelper method startDownloadVideos.
private void startDownloadVideos(List<? extends HasDownloadEntry> model, FragmentActivity activity, DownloadManagerCallback callback) {
long downloadSize = 0;
ArrayList<DownloadEntry> downloadList = new ArrayList<>();
int downloadCount = 0;
for (HasDownloadEntry v : model) {
DownloadEntry de = v.getDownloadEntry(storage);
if (!TextUtils.isEmpty(v.getDownloadUrl())) {
// Prefer download url to download
de.url = v.getDownloadUrl();
}
if (null == de || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADING || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADED || de.isVideoForWebOnly) {
continue;
} else {
downloadSize = downloadSize + de.getSize();
downloadList.add(de);
downloadCount++;
}
}
if (downloadSize > MemoryUtil.getAvailableExternalMemory(activity)) {
((BaseFragmentActivity) activity).showInfoMessage(activity.getString(R.string.file_size_exceeded));
callback.updateListUI();
EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
} else {
if (isDownloadSizeWithinLimit(downloadSize, MemoryUtil.GB) && !downloadList.isEmpty()) {
startDownload(downloadList, activity, callback);
final DownloadEntry downloadEntry = downloadList.get(0);
analyticsRegistry.trackSubSectionBulkVideoDownload(downloadEntry.getSectionName(), downloadEntry.getChapterName(), downloadEntry.getEnrollmentId(), downloadCount);
} else {
showDownloadSizeExceedDialog(downloadList, downloadCount, activity, callback);
}
}
}
use of org.edx.mobile.model.course.HasDownloadEntry 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