Search in sources :

Example 31 with CourseComponent

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

the class CourseAPI method normalizeCourseStructure.

/**
 * Mapping from raw data structure from getCourseStructure() API
 * @param courseStructureV1Model
 * @return
 */
@NonNull
public static IBlock normalizeCourseStructure(@NonNull final CourseStructureV1Model courseStructureV1Model, @NonNull final String courseId) throws CourseContentNotValidException {
    BlockModel topBlock = courseStructureV1Model.getBlockById(courseStructureV1Model.root);
    if (topBlock == null) {
        throw new CourseContentNotValidException("Server didn't send a proper response for this course: " + courseStructureV1Model.root);
    }
    CourseComponent course = new CourseComponent(topBlock, null);
    course.setCourseId(courseId);
    for (BlockModel m : courseStructureV1Model.getDescendants(topBlock)) {
        normalizeCourseStructure(courseStructureV1Model, m, course);
    }
    return course;
}
Also used : BlockModel(org.edx.mobile.model.course.BlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent) NonNull(android.support.annotation.NonNull)

Example 32 with CourseComponent

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

the class CourseAPI method getVideoById.

@Nullable
public VideoResponseModel getVideoById(@NonNull final String courseId, @NonNull final String videoId) throws Exception {
    CourseComponent course = this.getCourseStructureFromCache(courseId);
    if (course == null) {
        return getVideoById(course, videoId);
    }
    Map<String, SectionEntry> map = getCourseHierarchy(courseId);
    // iterate chapters
    for (Map.Entry<String, SectionEntry> chapterentry : map.entrySet()) {
        // iterate lectures
        for (Map.Entry<String, ArrayList<VideoResponseModel>> entry : chapterentry.getValue().sections.entrySet()) {
            // iterate videos
            for (VideoResponseModel v : entry.getValue()) {
                // identify the video
                if (videoId.equals(v.getSummary().getId())) {
                    return v;
                }
            }
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) VideoResponseModel(org.edx.mobile.model.api.VideoResponseModel) SectionEntry(org.edx.mobile.model.api.SectionEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CourseComponent(org.edx.mobile.model.course.CourseComponent) Nullable(android.support.annotation.Nullable)

Example 33 with CourseComponent

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

the class CourseOutlineActivity method onLoadData.

@Override
protected void onLoadData() {
    CourseComponent courseComponent = courseManager.getComponentById(courseData.getCourse().getId(), courseComponentId);
    setTitle(courseComponent.getDisplayName());
    if (fragment == null) {
        fragment = new CourseOutlineFragment();
        fragment.setTaskProcessCallback(this);
        Bundle bundle = new Bundle();
        bundle.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
        bundle.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseComponentId);
        bundle.putString(Router.EXTRA_LAST_ACCESSED_ID, getIntent().getStringExtra(Router.EXTRA_LAST_ACCESSED_ID));
        bundle.putBoolean(Router.EXTRA_IS_VIDEOS_MODE, isVideoMode);
        bundle.putBoolean(Router.EXTRA_IS_ON_COURSE_OUTLINE, isOnCourseOutline);
        fragment.setArguments(bundle);
        // this activity will only ever hold this lone fragment, so we
        // can afford to retain the instance during activity recreation
        fragment.setRetainInstance(true);
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.fragment_container, fragment, CourseOutlineFragment.TAG);
        fragmentTransaction.disallowAddToBackStack();
        fragmentTransaction.commitAllowingStateLoss();
    }
    if (isOnCourseOutline) {
        if (!isVideoMode) {
            lastAccessManager.fetchLastAccessed(this, courseData.getCourse().getId());
        }
    } else {
        environment.getAnalyticsRegistry().trackScreenView(Analytics.Screens.SECTION_OUTLINE, courseData.getCourse().getId(), courseComponent.getInternalName());
        // Update the last accessed item reference if we are in the course subsection view
        lastAccessManager.setLastAccessed(courseComponent.getCourseId(), courseComponent.getId());
    }
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Bundle(android.os.Bundle) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 34 with CourseComponent

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

the class CourseOutlineFragment 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:
                        {
                            CourseComponent outlineComp = courseManager.getComponentById(courseData.getCourse().getId(), courseComponentId);
                            String leafCompId = (String) data.getSerializableExtra(Router.EXTRA_COURSE_COMPONENT_ID);
                            CourseComponent leafComp = courseManager.getComponentById(courseData.getCourse().getId(), leafCompId);
                            BlockPath outlinePath = outlineComp.getPath();
                            BlockPath leafPath = leafComp.getPath();
                            int outlinePathSize = outlinePath.getPath().size();
                            if (!outlineComp.equals(leafPath.get(outlinePathSize - 1))) {
                                getActivity().setResult(Activity.RESULT_OK, data);
                                getActivity().finish();
                            } else {
                                int leafPathSize = leafPath.getPath().size();
                                if (outlinePathSize == leafPathSize - 2) {
                                    updateRowSelection(leafCompId);
                                } else {
                                    for (int i = outlinePathSize + 1; i < leafPathSize - 1; i += 2) {
                                        CourseComponent nextComp = leafPath.get(i);
                                        environment.getRouter().showCourseContainerOutline(CourseOutlineFragment.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 35 with CourseComponent

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

the class CourseOutlineFragment method loadData.

// Loading data to the Adapter
private void loadData(final View view) {
    if (courseData == null)
        return;
    CourseComponent courseComponent = getCourseComponent();
    adapter.setData(courseComponent);
    updateMessageView(view);
}
Also used : 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