use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseOutlineFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Bundle bundle = getArguments();
courseData = (EnrolledCoursesResponse) bundle.getSerializable(Router.EXTRA_COURSE_DATA);
courseComponentId = bundle.getString(Router.EXTRA_COURSE_COMPONENT_ID);
isVideoMode = bundle.getBoolean(Router.EXTRA_IS_VIDEOS_MODE);
isOnCourseOutline = bundle.getBoolean(Router.EXTRA_IS_ON_COURSE_OUTLINE);
View view = inflater.inflate(R.layout.fragment_course_outline, container, false);
listView = (ListView) view.findViewById(R.id.outline_list);
initializeAdapter();
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (deleteMode != null) {
deleteMode.finish();
}
listView.clearChoices();
CourseOutlineAdapter.SectionRow row = adapter.getItem(position);
CourseComponent comp = row.component;
if (comp.isContainer()) {
environment.getRouter().showCourseContainerOutline(CourseOutlineFragment.this, REQUEST_SHOW_COURSE_UNIT_DETAIL, courseData, comp.getId(), null, isVideoMode);
} else {
environment.getRouter().showCourseUnitDetail(CourseOutlineFragment.this, REQUEST_SHOW_COURSE_UNIT_DETAIL, courseData, comp.getId(), isVideoMode);
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (((IconImageView) view.findViewById(R.id.bulk_download)).getIcon() == FontAwesomeIcons.fa_check) {
((AppCompatActivity) getActivity()).startSupportActionMode(deleteModelCallback);
listView.setItemChecked(position, true);
return true;
}
return false;
}
});
return view;
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class CourseOutlineAdapter method getRowViewForContainer.
private void getRowViewForContainer(ViewHolder holder, final SectionRow row) {
final CourseComponent component = row.component;
String courseId = component.getCourseId();
BlockPath path = component.getPath();
// FIXME - we should add a new column in database - pathinfo.
// then do the string match to get the record
String chapterId = path.get(1) == null ? "" : path.get(1).getDisplayName();
String sequentialId = path.get(2) == null ? "" : path.get(2).getDisplayName();
holder.rowTitle.setText(component.getDisplayName());
holder.numOfVideoAndDownloadArea.setVisibility(View.VISIBLE);
if (component.isGraded()) {
holder.bulkDownload.setVisibility(View.INVISIBLE);
holder.rowSubtitlePanel.setVisibility(View.VISIBLE);
holder.rowSubtitleIcon.setVisibility(View.VISIBLE);
holder.rowSubtitle.setVisibility(View.VISIBLE);
holder.rowSubtitle.setText(component.getFormat());
holder.rowSubtitle.setTypeface(holder.rowSubtitle.getTypeface(), Typeface.BOLD);
holder.rowSubtitle.setTextColor(ContextCompat.getColor(context, R.color.edx_brand_gray_dark));
if (!TextUtils.isEmpty(component.getDueDate())) {
try {
holder.rowSubtitleDueDate.setText(getFormattedDueDate(component.getDueDate()));
holder.rowSubtitleDueDate.setVisibility(View.VISIBLE);
} catch (IllegalArgumentException e) {
logger.error(e);
}
}
}
final int totalDownloadableVideos = component.getDownloadableVideosCount();
// support video download for video type excluding the ones only viewable on web
if (totalDownloadableVideos == 0) {
holder.numOfVideoAndDownloadArea.setVisibility(View.GONE);
} else {
holder.bulkDownload.setVisibility(View.VISIBLE);
holder.noOfVideos.setVisibility(View.VISIBLE);
holder.noOfVideos.setText("" + totalDownloadableVideos);
Integer downloadedCount = dbStore.getDownloadedVideosCountForSection(courseId, chapterId, sequentialId, null);
if (downloadedCount == totalDownloadableVideos) {
holder.noOfVideos.setVisibility(View.VISIBLE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADED, null);
} else if (dbStore.getDownloadingVideosCountForSection(courseId, chapterId, sequentialId, null) + downloadedCount == totalDownloadableVideos) {
holder.noOfVideos.setVisibility(View.GONE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.DOWNLOADING, new View.OnClickListener() {
@Override
public void onClick(View downloadView) {
mDownloadListener.viewDownloadsStatus();
}
});
} else {
holder.noOfVideos.setVisibility(View.VISIBLE);
setRowStateOnDownload(holder, DownloadEntry.DownloadedState.ONLINE, new View.OnClickListener() {
@Override
public void onClick(View downloadView) {
mDownloadListener.download(component.getVideos());
}
});
}
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class NewCourseOutlineFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<AsyncTaskResult<CourseComponent>> loader, AsyncTaskResult<CourseComponent> result) {
final CourseComponent courseComponent = result.getResult();
if (courseComponent != null) {
// Course data exist in persistable cache
loadData(validateCourseComponent(courseComponent));
loadingIndicator.setVisibility(View.GONE);
// Send a server call in background for refreshed data
getCourseComponentFromServer(false);
} else {
// Course data is neither available in app session cache nor available in persistable cache
getCourseComponentFromServer(true);
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class NewCourseOutlineFragment method showLastAccessedView.
@Override
public void showLastAccessedView(String lastAccessedSubSectionId, String courseId, View view) {
if (getActivity() == null)
return;
if (NetworkUtil.isConnected(getContext())) {
if (courseId != null && lastAccessedSubSectionId != null) {
CourseComponent lastAccessComponent = courseManager.getComponentByIdFromAppLevelCache(courseId, lastAccessedSubSectionId);
if (lastAccessComponent != null) {
if (!lastAccessComponent.isContainer()) {
// getting subsection
if (lastAccessComponent.getParent() != null)
lastAccessComponent = lastAccessComponent.getParent();
// now getting section
if (lastAccessComponent.getParent() != null) {
lastAccessComponent = lastAccessComponent.getParent();
}
}
// to be the course root component itself, then we don't need to show it
if (!lastAccessComponent.getId().equals(courseId)) {
final CourseComponent finalLastAccessComponent = lastAccessComponent;
adapter.addLastAccessedView(finalLastAccessComponent, new View.OnClickListener() {
long lastClickTime = 0;
@Override
public void onClick(View v) {
// This has been used so that if user clicks continuously on the screen,
// two activities should not be opened
long currentTime = SystemClock.elapsedRealtime();
if (currentTime - lastClickTime > 1000) {
lastClickTime = currentTime;
environment.getRouter().showCourseContainerOutline(getActivity(), courseData, finalLastAccessComponent.getId());
}
}
});
}
}
}
}
}
use of org.edx.mobile.model.course.CourseComponent in project edx-app-android by edx.
the class NewCourseOutlineFragment method getCourseComponentFromServer.
public void getCourseComponentFromServer(boolean showProgress) {
final TaskProgressCallback progressCallback = showProgress ? new TaskProgressCallback.ProgressViewController(loadingIndicator) : null;
final String courseId = courseData.getCourse().getId();
getHierarchyCall = courseApi.getCourseStructureWithoutStale(courseId);
getHierarchyCall.enqueue(new CourseAPI.GetCourseStructureCallback(getActivity(), courseId, progressCallback, errorNotification, null, this) {
@Override
protected void onResponse(@NonNull final CourseComponent courseComponent) {
courseManager.addCourseDataInAppLevelCache(courseId, courseComponent);
loadData(validateCourseComponent(courseComponent));
}
@Override
protected void onFailure(@NonNull Throwable error) {
super.onFailure(error);
if (error instanceof CourseContentNotValidException) {
errorNotification.showError(getContext(), error);
logger.error(error, true);
}
}
@Override
protected void onFinish() {
if (!EventBus.getDefault().isRegistered(NewCourseOutlineFragment.this)) {
EventBus.getDefault().registerSticky(NewCourseOutlineFragment.this);
}
}
});
}
Aggregations