Search in sources :

Example 6 with VideoBlockModel

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

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

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

Example 9 with VideoBlockModel

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

the class CourseUnitNavigationActivityTest method testUnitFragmentCreation.

/**
 * Testing creation of various fragments in the {@link CourseUnitNavigationActivity}'s
 * ViewPager, by supplying its {@link CourseUnitPagerAdapter} with all possible
 * {@link CourseComponent} models.
 */
@Test
public void testUnitFragmentCreation() {
    FragmentManager fragmentManager = Mockito.mock(FragmentManager.class);
    EnrolledCoursesResponse courseData = Mockito.mock(EnrolledCoursesResponse.class);
    CourseUnitFragment.HasComponent hasComponent = Mockito.mock(CourseUnitFragment.HasComponent.class);
    List<CourseComponent> unitList = new ArrayList<>();
    List<Class<? extends CourseUnitFragment>> classesList = new ArrayList<>();
    VideoBlockModel encodeVideosModel = Mockito.mock(VideoBlockModel.class);
    VideoData videoData = Mockito.mock(VideoData.class);
    videoData.encodedVideos = Mockito.mock(EncodedVideos.class);
    when(videoData.encodedVideos.getPreferredVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
    when(encodeVideosModel.getData()).thenReturn(videoData);
    unitList.add(encodeVideosModel);
    classesList.add(CourseUnitVideoFragment.class);
    VideoBlockModel youtubeVideosModel = Mockito.mock(VideoBlockModel.class);
    VideoData videoData2 = Mockito.mock(VideoData.class);
    videoData2.encodedVideos = Mockito.mock(EncodedVideos.class);
    when(videoData2.encodedVideos.getYoutubeVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
    when(youtubeVideosModel.getData()).thenReturn(videoData2);
    unitList.add(youtubeVideosModel);
    classesList.add(CourseUnitOnlyOnYoutubeFragment.class);
    DiscussionBlockModel discussionModel = Mockito.mock(DiscussionBlockModel.class);
    unitList.add(discussionModel);
    if (config.isDiscussionsEnabled()) {
        classesList.add(CourseUnitDiscussionFragment.class);
    } else {
        classesList.add(CourseUnitMobileNotSupportedFragment.class);
    }
    CourseComponent nonMultiDeviceModel = Mockito.mock(CourseComponent.class);
    when(nonMultiDeviceModel.isMultiDevice()).thenReturn(false);
    unitList.add(nonMultiDeviceModel);
    classesList.add(CourseUnitMobileNotSupportedFragment.class);
    HtmlBlockModel htmlModel = Mockito.mock(HtmlBlockModel.class);
    when(htmlModel.isMultiDevice()).thenReturn(true);
    when(htmlModel.getType()).thenReturn(BlockType.HTML);
    unitList.add(htmlModel);
    classesList.add(CourseUnitWebViewFragment.class);
    CourseComponent unknownModel = Mockito.mock(CourseComponent.class);
    when(unknownModel.isMultiDevice()).thenReturn(true);
    when(unknownModel.getType()).thenReturn(BlockType.COURSE);
    unitList.add(unknownModel);
    classesList.add(CourseUnitEmptyFragment.class);
    CourseComponent problemModel = Mockito.mock(CourseComponent.class);
    when(problemModel.isMultiDevice()).thenReturn(true);
    when(problemModel.getType()).thenReturn(BlockType.PROBLEM);
    unitList.add(problemModel);
    classesList.add(CourseUnitMobileNotSupportedFragment.class);
    CourseComponent othersModel = Mockito.mock(CourseComponent.class);
    when(othersModel.isMultiDevice()).thenReturn(true);
    when(othersModel.getType()).thenReturn(BlockType.OTHERS);
    unitList.add(othersModel);
    classesList.add(CourseUnitMobileNotSupportedFragment.class);
    CourseUnitPagerAdapter adapter = new CourseUnitPagerAdapter(fragmentManager, config, unitList, courseData, hasComponent);
    for (int size = unitList.size(), i = 0; i < size; i++) {
        assertThat(adapter.getItem(i)).isInstanceOf(classesList.get(i));
    }
}
Also used : EncodedVideos(org.edx.mobile.model.course.EncodedVideos) ArrayList(java.util.ArrayList) VideoInfo(org.edx.mobile.model.course.VideoInfo) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent) CourseUnitPagerAdapter(org.edx.mobile.view.adapters.CourseUnitPagerAdapter) FragmentManager(android.support.v4.app.FragmentManager) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) VideoData(org.edx.mobile.model.course.VideoData) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel) Test(org.junit.Test)

Example 10 with VideoBlockModel

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

the class CourseUnitNavigationActivityTest method verifyState.

/**
 * Testing download progress menu visibility states and click behaviour
 * (starting DownloadActivity). Only when both AppConstants.offline_flag
 * is true and there is a downloading entry in the database, should the
 * progress bar be visible.
 */
/**
 * Generic method for verifying the state of the CourseUnitNavigationActivity
 * at a specific unit.
 *
 * @param activity An instance of CourseUnitNavigationActivity that has been
 *                 initialized
 * @param unitIndex The index of the unit among all the leaves for the course
 * @param currentUnit The selected course unit
 * @param prevUnit The unit previous to the current selection
 * @param nextUnit The unit next to the current selection
 * @param viewPager The ViewPager instance containing the CourseUnitFragment
 *                  instances
 * @param pagerAdapter The PagerAdapter associated with the ViewPager
 * @param prevButton The button for going to the previous unit
 * @param nextButton The button for going to the next unit
 * @param prevUnitLabel The label for the previous unit
 * @param nextUnitLabel The label for the next unit
 */
private void verifyState(CourseUnitNavigationActivity activity, int unitIndex, CourseComponent currentUnit, CourseComponent prevUnit, CourseComponent nextUnit, ViewPager viewPager, PagerAdapter pagerAdapter, TextView prevButton, TextView nextButton, TextView prevUnitLabel, TextView nextUnitLabel) {
    assertTitle(activity, currentUnit.getDisplayName());
    Class<? extends CourseUnitFragment> fragmentClass;
    if (currentUnit instanceof VideoBlockModel) {
        fragmentClass = CourseUnitVideoFragment.class;
    } else if (!currentUnit.isMultiDevice()) {
        fragmentClass = CourseUnitMobileNotSupportedFragment.class;
    } else if (currentUnit.getType() != BlockType.VIDEO && currentUnit.getType() != BlockType.HTML && currentUnit.getType() != BlockType.OTHERS && currentUnit.getType() != BlockType.DISCUSSION && currentUnit.getType() != BlockType.PROBLEM) {
        fragmentClass = CourseUnitEmptyFragment.class;
    } else if (currentUnit instanceof HtmlBlockModel) {
        fragmentClass = CourseUnitWebViewFragment.class;
    } else {
        fragmentClass = CourseUnitMobileNotSupportedFragment.class;
    }
    Object item = pagerAdapter.instantiateItem(viewPager, unitIndex);
    assertNotNull(item);
    assertThat(item).isInstanceOf(fragmentClass);
    Bundle args = ((Fragment) item).getArguments();
    assertNotNull(args);
    assertEquals(currentUnit, args.getSerializable(Router.EXTRA_COURSE_UNIT));
    assertEquals(prevUnit != null, prevButton.isEnabled());
    assertEquals(nextUnit != null, nextButton.isEnabled());
    CourseComponent prevSection = prevUnit == null ? null : prevUnit.getParent();
    CourseComponent nextSection = nextUnit == null ? null : nextUnit.getParent();
    if (prevSection == null || currentUnit.getParent().equals(prevSection)) {
        assertThat(prevUnitLabel).isNotVisible();
        assertThat(prevButton).hasText(R.string.assessment_previous);
    } else {
        assertThat(prevUnitLabel).isVisible();
        assertThat(prevUnitLabel).hasText(prevSection.getDisplayName());
    }
    if (nextSection == null || currentUnit.getParent().equals(nextSection)) {
        assertThat(nextUnitLabel).isNotVisible();
        assertThat(nextButton).hasText(R.string.assessment_next);
    } else {
        assertThat(nextUnitLabel).isVisible();
        assertThat(nextUnitLabel).hasText(nextSection.getDisplayName());
    }
}
Also used : Bundle(android.os.Bundle) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) JsonObject(com.google.gson.JsonObject) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) Fragment(android.support.v4.app.Fragment) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Aggregations

VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)11 CourseComponent (org.edx.mobile.model.course.CourseComponent)9 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 ArrayList (java.util.ArrayList)3 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)3 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)3 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)3 View (android.view.View)2 TextView (android.widget.TextView)2 BlockPath (org.edx.mobile.model.course.BlockPath)2 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)2 VideoData (org.edx.mobile.model.course.VideoData)2 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 ImageView (android.widget.ImageView)1 Gson (com.google.gson.Gson)1