Search in sources :

Example 1 with CourseComponent

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

the class NewCourseOutlineFragment method isOnCourseOutline.

protected boolean isOnCourseOutline() {
    if (courseComponentId == null)
        return true;
    final CourseComponent outlineComp = courseManager.getComponentByIdFromAppLevelCache(courseData.getCourse().getId(), courseComponentId);
    final BlockPath outlinePath = outlineComp.getPath();
    final int outlinePathSize = outlinePath.getPath().size();
    return outlinePathSize <= 1;
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 2 with CourseComponent

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

the class NewCourseOutlineFragment method fetchCourseComponent.

private void fetchCourseComponent() {
    final String courseId = courseData.getCourse().getId();
    if (courseComponentId != null) {
        final CourseComponent courseComponent = courseManager.getComponentByIdFromAppLevelCache(courseId, courseComponentId);
        if (courseComponent != null) {
            // Course data exist in app session cache
            loadData(courseComponent);
            return;
        }
    }
    // Check if course data is available in app session cache
    final CourseComponent courseComponent = courseManager.getCourseDataFromAppLevelCache(courseId);
    if (courseComponent != null) {
        // Course data exist in app session cache
        loadData(courseComponent);
        return;
    }
    // Check if course data is available in persistable cache
    loadingIndicator.setVisibility(View.VISIBLE);
    // Prepare the loader. Either re-connect with an existing one or start a new one.
    getLoaderManager().initLoader(0, null, this);
}
Also used : CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 3 with CourseComponent

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

the class NewCourseOutlineFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
        // the activity stack to point to it.
        case REQUEST_SHOW_COURSE_UNIT_DETAIL:
            {
                switch(resultCode) {
                    case Activity.RESULT_OK:
                        {
                            final CourseComponent outlineComp = courseManager.getComponentByIdFromAppLevelCache(courseData.getCourse().getId(), courseComponentId);
                            final String leafCompId = (String) data.getSerializableExtra(Router.EXTRA_COURSE_COMPONENT_ID);
                            final CourseComponent leafComp = courseManager.getComponentByIdFromAppLevelCache(courseData.getCourse().getId(), leafCompId);
                            final BlockPath outlinePath = outlineComp.getPath();
                            final BlockPath leafPath = leafComp.getPath();
                            final int outlinePathSize = outlinePath.getPath().size();
                            if (!outlineComp.equals(leafPath.get(outlinePathSize - 1))) {
                                getActivity().setResult(Activity.RESULT_OK, data);
                                getActivity().finish();
                            } else {
                                final int leafPathSize = leafPath.getPath().size();
                                if (outlinePathSize == leafPathSize - 2) {
                                    updateRowSelection(leafCompId);
                                } else {
                                    for (int i = outlinePathSize + 1; i < leafPathSize - 1; i += 2) {
                                        final CourseComponent nextComp = leafPath.get(i);
                                        environment.getRouter().showCourseContainerOutline(NewCourseOutlineFragment.this, REQUEST_SHOW_COURSE_UNIT_DETAIL, courseData, nextComp.getId(), leafCompId, isVideoMode);
                                    }
                                }
                            }
                        }
                }
                break;
            }
    }
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 4 with CourseComponent

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

the class NewCourseOutlineFragment method validateCourseComponent.

/**
 * Validates the course component that we should load on screen i.e. based on
 * {@link #isOnCourseOutline} validates that the CourseComponent we are about to load on screen
 * has the same ID as {@link #courseComponentId}.
 *
 * @param courseComponent The course component to validate.
 * @return Validated course component having the same ID as {@link #courseComponentId}.
 */
@NonNull
private CourseComponent validateCourseComponent(@NonNull CourseComponent courseComponent) {
    if (!isOnCourseOutline) {
        final CourseComponent cached = courseManager.getComponentByIdFromAppLevelCache(courseData.getCourse().getId(), courseComponentId);
        courseComponent = cached != null ? cached : courseComponent;
    }
    return courseComponent;
}
Also used : CourseComponent(org.edx.mobile.model.course.CourseComponent) NonNull(android.support.annotation.NonNull)

Example 5 with CourseComponent

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

the class CourseBaseActivity method isOnCourseOutline.

protected boolean isOnCourseOutline() {
    if (courseComponentId == null)
        return true;
    CourseComponent outlineComp = courseManager.getComponentById(courseData.getCourse().getId(), courseComponentId);
    BlockPath outlinePath = outlineComp.getPath();
    int outlinePathSize = outlinePath.getPath().size();
    return outlinePathSize <= 1;
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Aggregations

CourseComponent (org.edx.mobile.model.course.CourseComponent)43 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)10 ArrayList (java.util.ArrayList)9 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)9 Bundle (android.os.Bundle)8 BlockPath (org.edx.mobile.model.course.BlockPath)8 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)8 Test (org.junit.Test)7 View (android.view.View)6 IBlock (org.edx.mobile.model.course.IBlock)6 Intent (android.content.Intent)5 NonNull (android.support.annotation.NonNull)5 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)5 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)5 TextView (android.widget.TextView)4 IconImageView (com.joanzapata.iconify.widget.IconImageView)4 LinkedHashMap (java.util.LinkedHashMap)4 Fragment (android.support.v4.app.Fragment)3 HashMap (java.util.HashMap)3 CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)3