Search in sources :

Example 16 with CourseComponent

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);
    }
}
Also used : VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 17 with CourseComponent

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);
                }
            });
        }
    }
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) List(java.util.List) ArrayList(java.util.ArrayList) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) IconImageView(com.joanzapata.iconify.widget.IconImageView) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 18 with CourseComponent

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;
    }
}
Also used : CourseComponent(org.edx.mobile.model.course.CourseComponent) Nullable(android.support.annotation.Nullable)

Example 19 with CourseComponent

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);
}
Also used : CourseComponent(org.edx.mobile.model.course.CourseComponent) Test(org.junit.Test)

Example 20 with CourseComponent

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();
        }
    }
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) BlockPath(org.edx.mobile.model.course.BlockPath) ArrayList(java.util.ArrayList) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry) Filter(org.edx.mobile.model.Filter) BlockType(org.edx.mobile.model.course.BlockType) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) Test(org.junit.Test)

Aggregations

CourseComponent (org.edx.mobile.model.course.CourseComponent)43 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)10 ArrayList (java.util.ArrayList)9 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)9 Bundle (android.os.Bundle)8 BlockPath (org.edx.mobile.model.course.BlockPath)8 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Test (org.junit.Test)7 View (android.view.View)6 IBlock (org.edx.mobile.model.course.IBlock)6 Intent (android.content.Intent)5 NonNull (android.support.annotation.NonNull)5 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)5 TextView (android.widget.TextView)4 IconImageView (com.joanzapata.iconify.widget.IconImageView)4 LinkedHashMap (java.util.LinkedHashMap)4 Fragment (android.support.v4.app.Fragment)3 HashMap (java.util.HashMap)3 CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)3