Search in sources :

Example 1 with DiscussionBlockModel

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

the class ApiTests method verifyModelParsing.

/**
 * Verifies the parsing of course structure json to {@link CourseComponent} model class.
 *
 * @param component Parsed {@link CourseComponent} model.
 */
private void verifyModelParsing(CourseComponent component) throws IOException, JSONException {
    JSONObject jsonObj;
    jsonObj = new JSONObject(MockDataUtil.getMockResponse("get_course_structure"));
    jsonObj = jsonObj.getJSONObject("blocks");
    jsonObj = jsonObj.getJSONObject(component.getId());
    assertNotNull(jsonObj);
    // Not using the getDisplayName function below, because it returns a placeholder text
    // when the display_name field's value is empty.
    assertEquals(jsonObj.getString("display_name"), component.getInternalName());
    assertEquals(jsonObj.getBoolean("graded"), component.isGraded());
    assertEquals(jsonObj.getString("student_view_url"), component.getBlockUrl());
    assertEquals(jsonObj.getBoolean("student_view_multi_device"), component.isMultiDevice());
    assertEquals(jsonObj.getString("lms_web_url"), component.getWebUrl());
    // Type specific validations
    Gson gson = new Gson();
    switch(component.getType()) {
        case VIDEO:
            {
                JSONObject dataObj = jsonObj.getJSONObject("student_view_data");
                // Our current parser checks the existence of these fields to determine the type to convert into
                assertTrue(dataObj.has("encoded_videos") || dataObj.has("transcripts"));
                String dataRawJson = dataObj.toString();
                assertTrue(component instanceof VideoBlockModel);
                VideoBlockModel model = (VideoBlockModel) component;
                VideoData expected = gson.fromJson(dataRawJson, VideoData.class);
                assertEquals(expected, model.getData());
                break;
            }
        case DISCUSSION:
            {
                JSONObject dataObj = jsonObj.getJSONObject("student_view_data");
                // Our current parser checks the existence of these fields to determine the type to convert into
                assertTrue(dataObj.has("topic_id"));
                String dataRawJson = dataObj.toString();
                assertTrue(component instanceof DiscussionBlockModel);
                DiscussionBlockModel model = (DiscussionBlockModel) component;
                DiscussionData expected = gson.fromJson(dataRawJson, DiscussionData.class);
                assertEquals(expected, model.getData());
                break;
            }
    }
}
Also used : DiscussionData(org.edx.mobile.model.course.DiscussionData) JSONObject(org.json.JSONObject) VideoData(org.edx.mobile.model.course.VideoData) Gson(com.google.gson.Gson) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel)

Example 2 with DiscussionBlockModel

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

the class CourseOutlineAdapter 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 3 with DiscussionBlockModel

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

the class CourseUnitPagerAdapter method getItem.

@Override
public Fragment getItem(int pos) {
    CourseComponent unit = getUnit(pos);
    CourseUnitFragment unitFragment;
    // FIXME - for the video, let's ignore studentViewMultiDevice for now
    if (isCourseUnitVideo(unit)) {
        unitFragment = CourseUnitVideoFragment.newInstance((VideoBlockModel) unit, (pos < unitList.size()), (pos > 0));
    } else if (unit instanceof VideoBlockModel && ((VideoBlockModel) unit).getData().encodedVideos.getYoutubeVideoInfo() != null) {
        unitFragment = CourseUnitOnlyOnYoutubeFragment.newInstance(unit);
    } else if (config.isDiscussionsEnabled() && unit instanceof DiscussionBlockModel) {
        unitFragment = CourseUnitDiscussionFragment.newInstance(unit, courseData);
    } else if (!unit.isMultiDevice()) {
        unitFragment = CourseUnitMobileNotSupportedFragment.newInstance(unit);
    } else if (unit.getType() != BlockType.VIDEO && unit.getType() != BlockType.HTML && unit.getType() != BlockType.OTHERS && unit.getType() != BlockType.DISCUSSION && unit.getType() != BlockType.PROBLEM) {
        unitFragment = CourseUnitEmptyFragment.newInstance(unit);
    } else if (unit instanceof HtmlBlockModel) {
        unitFragment = CourseUnitWebViewFragment.newInstance((HtmlBlockModel) unit);
    } else // fallback
    {
        unitFragment = CourseUnitMobileNotSupportedFragment.newInstance(unit);
    }
    unitFragment.setHasComponentCallback(callback);
    return unitFragment;
}
Also used : CourseUnitFragment(org.edx.mobile.view.CourseUnitFragment) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 4 with DiscussionBlockModel

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

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

Aggregations

DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)5 CourseComponent (org.edx.mobile.model.course.CourseComponent)4 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)2 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)2 VideoData (org.edx.mobile.model.course.VideoData)2 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)2 FragmentManager (android.support.v4.app.FragmentManager)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)1 DiscussionData (org.edx.mobile.model.course.DiscussionData)1 EncodedVideos (org.edx.mobile.model.course.EncodedVideos)1 VideoInfo (org.edx.mobile.model.course.VideoInfo)1 CourseUnitFragment (org.edx.mobile.view.CourseUnitFragment)1 CourseUnitPagerAdapter (org.edx.mobile.view.adapters.CourseUnitPagerAdapter)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1