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;
}
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;
}
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());
}
}
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;
}
}
}
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);
}
Aggregations