Search in sources :

Example 1 with LectureModel

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

the class CourseAPI method getLecture.

/**
 * we handle both name and id for backward compatibility. legacy code use name, it is not a good idea as name is not
 * grantee to be unique.
 */
@Nullable
public LectureModel getLecture(@NonNull final CourseComponent courseComponent, @NonNull final String chapterName, @NonNull final String chapterId, @NonNull final String lectureName, @NonNull final String lectureId) throws Exception {
    // TODO - we may use a generic filter to fetch the data?
    for (IBlock chapter : courseComponent.getChildren()) {
        if (chapter.getId().equals(chapterId)) {
            for (IBlock lecture : chapter.getChildren()) {
                // TODO - check to see if need to compare id or not
                if (lecture.getId().equals(lectureId)) {
                    LectureModel lm = new LectureModel();
                    lm.name = lecture.getDisplayName();
                    lm.videos = (ArrayList) mappingAllVideoResponseModelFrom((CourseComponent) lecture, null);
                    return lm;
                }
            }
        }
    }
    // if we can not find object by id, try to get by name.
    for (IBlock chapter : courseComponent.getChildren()) {
        if (chapter.getDisplayName().equals(chapterName)) {
            for (IBlock lecture : chapter.getChildren()) {
                // TODO - check to see if need to compare id or not
                if (lecture.getDisplayName().equals(lectureName)) {
                    LectureModel lm = new LectureModel();
                    lm.name = lecture.getDisplayName();
                    lm.videos = (ArrayList) mappingAllVideoResponseModelFrom((CourseComponent) lecture, null);
                    return lm;
                }
            }
        }
    }
    return null;
}
Also used : LectureModel(org.edx.mobile.model.api.LectureModel) IBlock(org.edx.mobile.model.course.IBlock) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)1 LectureModel (org.edx.mobile.model.api.LectureModel)1 IBlock (org.edx.mobile.model.course.IBlock)1