Search in sources :

Example 1 with CourseUnitPagerAdapter

use of org.edx.mobile.view.adapters.CourseUnitPagerAdapter in project edx-app-android by edx.

the class CourseUnitNavigationActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RelativeLayout insertPoint = (RelativeLayout) findViewById(R.id.fragment_container);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.view_course_unit_pager, null);
    insertPoint.addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    pager = (DisableableViewPager) findViewById(R.id.pager);
    pagerAdapter = new CourseUnitPagerAdapter(getSupportFragmentManager(), environment.getConfig(), unitList, courseData, this);
    pager.setAdapter(pagerAdapter);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == ViewPager.SCROLL_STATE_DRAGGING) {
                int curIndex = pager.getCurrentItem();
                PageViewStateCallback curView = (PageViewStateCallback) pagerAdapter.instantiateItem(pager, curIndex);
                if (curView != null)
                    curView.onPageDisappear();
            }
            if (state == ViewPager.SCROLL_STATE_IDLE) {
                int curIndex = pager.getCurrentItem();
                PageViewStateCallback curView = (PageViewStateCallback) pagerAdapter.instantiateItem(pager, curIndex);
                if (curView != null)
                    curView.onPageShow();
                tryToUpdateForEndOfSequential();
            }
        }
    });
    findViewById(R.id.course_unit_nav_bar).setVisibility(View.VISIBLE);
    mPreviousBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            navigatePreviousComponent();
        }
    });
    mNextBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            navigateNextComponent();
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PageViewStateCallback(org.edx.mobile.view.common.PageViewStateCallback) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) DisableableViewPager(org.edx.mobile.view.custom.DisableableViewPager) ViewPager(android.support.v4.view.ViewPager) CourseUnitPagerAdapter(org.edx.mobile.view.adapters.CourseUnitPagerAdapter) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout)

Example 2 with CourseUnitPagerAdapter

use of org.edx.mobile.view.adapters.CourseUnitPagerAdapter 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

CourseUnitPagerAdapter (org.edx.mobile.view.adapters.CourseUnitPagerAdapter)2 FragmentManager (android.support.v4.app.FragmentManager)1 ViewPager (android.support.v4.view.ViewPager)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)1 CourseComponent (org.edx.mobile.model.course.CourseComponent)1 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)1 EncodedVideos (org.edx.mobile.model.course.EncodedVideos)1 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)1 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)1 VideoData (org.edx.mobile.model.course.VideoData)1 VideoInfo (org.edx.mobile.model.course.VideoInfo)1 PageViewStateCallback (org.edx.mobile.view.common.PageViewStateCallback)1 DisableableViewPager (org.edx.mobile.view.custom.DisableableViewPager)1 Test (org.junit.Test)1