Search in sources :

Example 1 with EnrolledCoursesResponse

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

the class MyCoursesListFragment 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);
    if (!EventBus.getDefault().isRegistered(MyCoursesListFragment.this)) {
        EventBus.getDefault().registerSticky(MyCoursesListFragment.this);
    }
}
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 2 with EnrolledCoursesResponse

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

the class NewCourseOutlineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // We don't need the drawer here
    blockDrawerFromOpening();
    if (courseComponentId == null) {
        EnrolledCoursesResponse courseData = (EnrolledCoursesResponse) courseBundle.getSerializable(Router.EXTRA_COURSE_DATA);
        environment.getAnalyticsRegistry().trackScreenView(isVideoMode ? Analytics.Screens.VIDEOS_COURSE_VIDEOS : Analytics.Screens.COURSE_OUTLINE, courseData.getCourse().getId(), null);
        setTitle(courseData.getCourse().getName());
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse)

Example 3 with EnrolledCoursesResponse

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

the class ApiTests method testSyncLastSubsection.

// TODO: Debug and fix test failure
@Ignore
@Test
public void testSyncLastSubsection() throws Exception {
    login();
    EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
    Map<String, SectionEntry> map = courseAPI.getCourseHierarchy(e.getCourse().getId());
    Entry<String, SectionEntry> entry = map.entrySet().iterator().next();
    Entry<String, ArrayList<VideoResponseModel>> subsection = entry.getValue().sections.entrySet().iterator().next();
    String courseId = e.getCourse().getId();
    String lastVisitedModuleId = subsection.getValue().get(0).getSection().getId();
    assertNotNull(courseId);
    assertNotNull(lastVisitedModuleId);
    print(String.format("course= %s ; sub-section= %s", courseId, lastVisitedModuleId));
    // TODO: lastVisitedModuleId must be section.id (id is now available)
    SyncLastAccessedSubsectionResponse model = executeStrict(courseAPI.syncLastAccessedSubsection(courseId, lastVisitedModuleId));
    assertNotNull(model);
    print("sync returned: " + model.last_visited_module_id);
}
Also used : SyncLastAccessedSubsectionResponse(org.edx.mobile.model.api.SyncLastAccessedSubsectionResponse) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) SectionEntry(org.edx.mobile.model.api.SectionEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with EnrolledCoursesResponse

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

the class ApiTests method testGetLastAccessedModule.

// TODO: Debug and fix test failure
@Ignore
@Test
public void testGetLastAccessedModule() throws Exception {
    login();
    EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
    String courseId = e.getCourse().getId();
    assertNotNull(courseId);
    print(String.format("course= %s", courseId));
    SyncLastAccessedSubsectionResponse model = executeStrict(courseAPI.getLastAccessedSubsection(courseId));
    assertNotNull(model);
// print(model.json);
}
Also used : SyncLastAccessedSubsectionResponse(org.edx.mobile.model.api.SyncLastAccessedSubsectionResponse) EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with EnrolledCoursesResponse

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

the class ApiTests method testCourseStructure.

// TODO: Debug and fix test failure
@Ignore
@Test
public void testCourseStructure() 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 courseId = courses.get(0).getCourse().getId();
    Map<String, SectionEntry> chapters = courseAPI.getCourseHierarchy(courseId);
    for (Entry<String, SectionEntry> entry : chapters.entrySet()) {
        print("---------------" + entry.getKey() + "---------------");
        for (Entry<String, ArrayList<VideoResponseModel>> se : entry.getValue().sections.entrySet()) {
            print("------------" + se.getKey() + "------------");
            for (VideoResponseModel v : se.getValue()) {
                print(v.getSummary().getDisplayName());
            }
        }
    }
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionEntry(org.edx.mobile.model.api.SectionEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

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