Search in sources :

Example 21 with EnrolledCoursesResponse

use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.

the class CourseOutlineActivityTest method unitNavigationTest.

/**
 * Testing navigation to a unit
 */
@Test
public void unitNavigationTest() {
    Intent intent = getIntent();
    Bundle extras = intent.getBundleExtra(Router.EXTRA_BUNDLE);
    EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) extras.getSerializable(Router.EXTRA_COURSE_DATA);
    assertNotNull(courseData);
    String courseId = courseData.getCourse().getId();
    CourseStructureV1Model model;
    CourseComponent courseComponent;
    try {
        model = executeStrict(courseAPI.getCourseStructure(courseId));
        courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    List<CourseComponent> leafComponents = new ArrayList<>();
    courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
    CourseComponent courseUnit = leafComponents.get(0);
    CourseComponent lastUnit = leafComponents.get(leafComponents.size() - 1);
    assertNotEquals(lastUnit, courseUnit);
    courseComponent = courseUnit.getParent();
    if (courseUnit.getPath().getPath().size() % 2 > 0) {
        courseComponent = courseComponent.getParent();
    }
    int subsectionRowIndex = -1;
    List<IBlock> sections = courseComponent.getChildren();
    sectionIteration: for (@SuppressWarnings("unused") IBlock section : sections) {
        subsectionRowIndex++;
        if (courseUnit.equals(section)) {
            break;
        }
        for (@SuppressWarnings("unused") IBlock subsection : section.getChildren()) {
            subsectionRowIndex++;
            if (courseUnit.equals(subsection)) {
                break sectionIteration;
            }
        }
    }
    extras.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseComponent.getId());
    ActivityController<? extends CourseOutlineActivity> controller = initialize(intent);
    CourseOutlineActivity activity = controller.get();
    Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(CourseOutlineFragment.TAG);
    assertThat(fragment).isInstanceOf(CourseOutlineFragment.class);
    CourseOutlineFragment courseOutlineFragment = (CourseOutlineFragment) fragment;
    clickRow(controller, courseOutlineFragment, subsectionRowIndex);
    Intent newIntent = assertNextStartedActivity(activity, CourseUnitNavigationActivity.class);
    Bundle newData = newIntent.getBundleExtra(Router.EXTRA_BUNDLE);
    assertNotNull(newData);
    assertEquals(courseData, newData.getSerializable(Router.EXTRA_COURSE_DATA));
    assertEquals(courseUnit.getId(), newData.getSerializable(Router.EXTRA_COURSE_COMPONENT_ID));
    // Test the back stack reconstruction upon receiving a specific path
    // Should not perform any action if it receives a unit selection from itself
    Intent resultData = new Intent();
    resultData.putExtra(Router.EXTRA_COURSE_COMPONENT_ID, courseUnit.getId());
    courseOutlineFragment.onActivityResult(CourseOutlineFragment.REQUEST_SHOW_COURSE_UNIT_DETAIL, Activity.RESULT_OK, resultData);
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    assertNull(shadowActivity.getNextStartedActivity());
    assertFalse(shadowActivity.isFinishing());
    // Should finish itself to start the new navigation back stack if it receives
    // a unit selection from another section
    resultData.putExtra(Router.EXTRA_COURSE_COMPONENT_ID, lastUnit.getId());
    courseOutlineFragment.onActivityResult(CourseOutlineFragment.REQUEST_SHOW_COURSE_UNIT_DETAIL, Activity.RESULT_OK, resultData);
    assertNull(shadowActivity.getNextStartedActivity());
    assertTrue(shadowActivity.isFinishing());
}
Also used : IBlock(org.edx.mobile.model.course.IBlock) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Fragment(android.support.v4.app.Fragment) CourseComponent(org.edx.mobile.model.course.CourseComponent) BlockType(org.edx.mobile.model.course.BlockType) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ShadowActivity(org.robolectric.shadows.ShadowActivity) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) Test(org.junit.Test)

Example 22 with EnrolledCoursesResponse

use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.

the class ApiTests method testHandouts.

// TODO: Debug and fix test failure
@Ignore
@Test
public void testHandouts() throws Exception {
    login();
    // get a course id for this test
    List<EnrolledCoursesResponse> courses = executeStrict(courseAPI.getEnrolledCourses());
    assertTrue("Must have enrolled to at least one course", courses != null && courses.size() > 0);
    String handoutURL = courses.get(0).getCourse().getCourse_handouts();
    HandoutModel model = executeStrict(HandoutModel.class, okHttpClient.newCall(new Request.Builder().url(handoutURL).get().build()));
    assertTrue(model != null);
    print(model.handouts_html);
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Request(okhttp3.Request) HandoutModel(org.edx.mobile.model.api.HandoutModel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with EnrolledCoursesResponse

use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.

the class MyCoursesListFragment method onCreate.

// TODO: All these callbacks aren't essentially part of MyCoursesListFragment and should move in
// the Tabs container fragment that's going to be implemented in LEARNER-3251
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adapter = new MyCoursesAdapter(getActivity(), environment) {

        @Override
        public void onItemClicked(EnrolledCoursesResponse model) {
            environment.getRouter().showCourseDashboardTabs(getActivity(), environment.getConfig(), model, false);
        }

        @Override
        public void onAnnouncementClicked(EnrolledCoursesResponse model) {
            environment.getRouter().showCourseDashboardTabs(getActivity(), environment.getConfig(), model, true);
        }
    };
}
Also used : MyCoursesAdapter(org.edx.mobile.view.adapters.MyCoursesAdapter) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse)

Example 24 with EnrolledCoursesResponse

use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.

the class MyCoursesAdapter method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View arg1, int position, long arg3) {
    // This time is checked to avoid taps in quick succession
    final long currentTime = SystemClock.elapsedRealtime();
    if (currentTime - lastClickTime > MIN_CLICK_INTERVAL) {
        lastClickTime = currentTime;
        EnrolledCoursesResponse model = (EnrolledCoursesResponse) adapterView.getItemAtPosition(position);
        if (model != null)
            onItemClicked(model);
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse)

Aggregations

EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)24 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 CourseComponent (org.edx.mobile.model.course.CourseComponent)9 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Intent (android.content.Intent)7 Bundle (android.os.Bundle)7 Ignore (org.junit.Ignore)6 View (android.view.View)4 Fragment (android.support.v4.app.Fragment)3 BlockType (org.edx.mobile.model.course.BlockType)3 IBlock (org.edx.mobile.model.course.IBlock)3 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)3 TextView (android.widget.TextView)2 IOException (java.io.IOException)2 List (java.util.List)2 Request (okhttp3.Request)2 AuthException (org.edx.mobile.exception.AuthException)2 HttpStatusException (org.edx.mobile.http.HttpStatusException)2 SectionEntry (org.edx.mobile.model.api.SectionEntry)2