Search in sources :

Example 6 with EnrolledCoursesResponse

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

the class ApiTests method testGetAnnouncement.

// TODO: Debug and fix test failure
@Ignore
@Test
public void testGetAnnouncement() 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 updatesUrl = courses.get(0).getCourse().getCourse_updates();
    List<AnnouncementsModel> res = executeStrict(new TypeToken<List<AnnouncementsModel>>() {
    }, okHttpClient.newCall(new Request.Builder().url(updatesUrl).get().build()));
    assertTrue(res != null);
    for (AnnouncementsModel r : res) {
        print(r.getDate());
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Request(okhttp3.Request) AnnouncementsModel(org.edx.mobile.model.api.AnnouncementsModel) ArrayList(java.util.ArrayList) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with EnrolledCoursesResponse

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

the class CourseDashboardActivityTest method initializeTest.

/**
 * {@inheritDoc}
 */
@Test
public void initializeTest() {
    Intent intent = getIntent();
    Bundle data = intent.getBundleExtra(Router.EXTRA_BUNDLE);
    EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) data.getSerializable(Router.EXTRA_COURSE_DATA);
    ActivityController<? extends CourseDashboardActivity> controller = Robolectric.buildActivity(getActivityClass()).withIntent(intent);
    CourseDashboardActivity activity = controller.get();
    controller.create(null).postCreate(null);
    Fragment fragment = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    assertNotNull(fragment);
    assertThat(fragment).isInstanceOf(CourseDashboardFragment.class);
    assertTrue(fragment.getRetainInstance());
    Bundle args = fragment.getArguments();
    assertNotNull(args);
    assertEquals(courseData, args.getSerializable(CourseDashboardFragment.CourseData));
    controller.resume().postResume().visible();
    View fragmentView = fragment.getView();
    assertNotNull(fragmentView);
    // TODO: Create a separate test suite for CourseDashboardFragment views
    // Test navigation to courseware
    View rowsContainer = fragmentView.findViewById(R.id.dashboard_detail);
    assertNotNull(rowsContainer);
    assertThat(rowsContainer).isInstanceOf(ViewGroup.class);
    ViewGroup rowsContainerGroup = (ViewGroup) rowsContainer;
    int rowNum = 0;
    View coursewareRowView = rowsContainerGroup.getChildAt(rowNum++);
    assertRow(coursewareRowView, FontAwesomeIcons.fa_list_alt, R.string.courseware_title, R.string.courseware_subtitle);
    if (config.isCourseVideosEnabled()) {
        View videoRowView = rowsContainerGroup.getChildAt(rowNum++);
        assertRow(videoRowView, FontAwesomeIcons.fa_film, R.string.videos_title, R.string.videos_subtitle);
    }
    if (config.isDiscussionsEnabled()) {
        View discussionRowView = rowsContainerGroup.getChildAt(rowNum++);
        assertRow(discussionRowView, FontAwesomeIcons.fa_comments_o, R.string.discussion_title, R.string.discussion_subtitle);
    }
    View handoutsRowView = rowsContainerGroup.getChildAt(rowNum++);
    assertRow(handoutsRowView, FontAwesomeIcons.fa_file_text_o, R.string.handouts_title, R.string.handouts_subtitle);
    View announcementRowView = rowsContainerGroup.getChildAt(rowNum++);
    assertRow(announcementRowView, FontAwesomeIcons.fa_bullhorn, R.string.announcement_title, R.string.announcement_subtitle);
    assertTrue(coursewareRowView.performClick());
    Intent newIntent = assertNextStartedActivity(activity, CourseOutlineActivity.class);
    Bundle newData = newIntent.getBundleExtra(Router.EXTRA_BUNDLE);
    assertNotNull(newData);
    assertEquals(courseData, newData.getSerializable(Router.EXTRA_COURSE_DATA));
// We don't seem to have one-to-one mapping between the course list and detail ids
/*assertEquals(courseData.getCourse().getId(),
                newData.getString(Router.EXTRA_COURSE_COMPONENT_ID));*/
}
Also used : Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Intent(android.content.Intent) Fragment(android.support.v4.app.Fragment) IconImageView(com.joanzapata.iconify.widget.IconImageView) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Example 8 with EnrolledCoursesResponse

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

the class CourseUnitWebViewFragmentTest method getHtmlUnit.

/**
 * Method for iterating through the mock course response data, and
 * returning the first video block leaf.
 *
 * @return The first {@link HtmlBlockModel} leaf in the mock course data
 */
private HtmlBlockModel getHtmlUnit() throws CourseContentNotValidException {
    EnrolledCoursesResponse courseData;
    try {
        courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    String courseId = courseData.getCourse().getId();
    CourseStructureV1Model model;
    try {
        model = executeStrict(courseAPI.getCourseStructure(courseId));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
    List<CourseComponent> htmlBlockUnits = new ArrayList<>();
    courseComponent.fetchAllLeafComponents(htmlBlockUnits, EnumSet.of(BlockType.HTML));
    return (HtmlBlockModel) htmlBlockUnits.get(0);
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 9 with EnrolledCoursesResponse

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

the class OldMyCoursesListFragment method onLoadFinished.

@Override
public void onLoadFinished(Loader<AsyncTaskResult<List<EnrolledCoursesResponse>>> asyncTaskResultLoader, AsyncTaskResult<List<EnrolledCoursesResponse>> result) {
    adapter.clear();
    final Exception exception = result.getEx();
    if (exception != null) {
        if (exception instanceof AuthException) {
            loginPrefs.clear();
            getActivity().finish();
        } else if (exception instanceof HttpStatusException) {
            final HttpStatusException httpStatusException = (HttpStatusException) exception;
            switch(httpStatusException.getStatusCode()) {
                case HttpStatus.UNAUTHORIZED:
                    {
                        environment.getRouter().forceLogout(getContext(), environment.getAnalyticsRegistry(), environment.getNotificationDelegate());
                        break;
                    }
            }
        } else {
            logger.error(exception);
        }
        errorNotification.showError(getActivity(), exception, R.string.lbl_reload, new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (NetworkUtil.isConnected(getContext())) {
                    onRefresh();
                }
            }
        });
    } else if (result.getResult() != null) {
        ArrayList<EnrolledCoursesResponse> newItems = new ArrayList<EnrolledCoursesResponse>(result.getResult());
        updateDatabaseAfterDownload(newItems);
        if (result.getResult().size() > 0) {
            adapter.setItems(newItems);
            adapter.notifyDataSetChanged();
        }
        if (adapter.isEmpty() && !environment.getConfig().getCourseDiscoveryConfig().isCourseDiscoveryEnabled()) {
            errorNotification.showError(R.string.no_courses_to_display, FontAwesomeIcons.fa_exclamation_circle, 0, null);
            binding.myCourseList.setVisibility(View.GONE);
        } else {
            binding.myCourseList.setVisibility(View.VISIBLE);
            errorNotification.hideError();
        }
    }
    binding.swipeContainer.setRefreshing(false);
    binding.loadingIndicator.getRoot().setVisibility(View.GONE);
    isInitialServerCallDone = true;
    if (!(NetworkUtil.isConnected(getActivity()))) {
        onOffline();
    } else {
        onOnline();
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) AuthException(org.edx.mobile.exception.AuthException) HttpStatusException(org.edx.mobile.http.HttpStatusException) View(android.view.View) HttpStatusException(org.edx.mobile.http.HttpStatusException) AuthException(org.edx.mobile.exception.AuthException)

Example 10 with EnrolledCoursesResponse

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

the class OldMyCoursesListFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    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);
        }
    };
    EventBus.getDefault().register(this);
}
Also used : MyCoursesAdapter(org.edx.mobile.view.adapters.MyCoursesAdapter) 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