use of org.edx.mobile.course.CourseDetail in project edx-app-android by edx.
the class NativeFindCoursesFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Activity activity = getActivity();
this.viewHolder = new ViewHolder(view);
viewHolder.listView.setVisibility(View.GONE);
viewHolder.loadingIndicator.setVisibility(View.VISIBLE);
final FindCoursesListAdapter adapter = new FindCoursesListAdapter(activity, environment) {
@Override
public void onItemClicked(CourseDetail model) {
environment.getRouter().showCourseDetail(activity, model);
}
};
// Add empty views to cause a dividers to render at the top and bottom of the list
viewHolder.listView.addHeaderView(new View(getContext()), null, false);
viewHolder.listView.addFooterView(new View(getContext()), null, false);
InfiniteScrollUtils.configureListViewWithInfiniteList(viewHolder.listView, adapter, new InfiniteScrollUtils.PageLoader<CourseDetail>() {
@Override
public void loadNextPage(@NonNull final InfiniteScrollUtils.PageLoadCallback<CourseDetail> callback) {
if (null != call) {
call.cancel();
}
call = courseAPI.getCourseList(nextPage);
final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
call.enqueue(new ErrorHandlingCallback<Page<CourseDetail>>(activity, null, mCallback, CallTrigger.LOADING_UNCACHED) {
@Override
protected void onResponse(@NonNull final Page<CourseDetail> coursesPage) {
callback.onPageLoaded(coursesPage);
++nextPage;
if (null != viewHolder) {
viewHolder.listView.setVisibility(View.VISIBLE);
viewHolder.loadingIndicator.setVisibility(View.GONE);
}
}
@Override
protected void onFailure(@NonNull final Throwable error) {
callback.onError();
nextPage = 1;
if (null != viewHolder) {
viewHolder.loadingIndicator.setVisibility(View.GONE);
}
}
});
}
});
viewHolder.listView.setOnItemClickListener(adapter);
}
use of org.edx.mobile.course.CourseDetail in project edx-app-android by edx.
the class CourseDetailFragment method populateAboutThisCourse.
/**
* Makes a call the the course details api and sets the overview if given. If there is no
* overview, remove the courseAbout view.
*/
private void populateAboutThisCourse() {
getCourseDetailCall = courseApi.getCourseDetail(courseDetail.course_id);
final Activity activity = getActivity();
final TaskProgressCallback pCallback = activity instanceof TaskProgressCallback ? (TaskProgressCallback) activity : null;
final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
getCourseDetailCall.enqueue(new ErrorHandlingCallback<CourseDetail>(getActivity(), pCallback, mCallback, CallTrigger.LOADING_CACHED) {
@Override
protected void onResponse(@NonNull final CourseDetail courseDetail) {
if (courseDetail.overview != null && !courseDetail.overview.isEmpty()) {
populateAboutThisCourse(courseDetail.overview);
} else {
courseAbout.setVisibility(View.GONE);
}
}
});
}
use of org.edx.mobile.course.CourseDetail in project edx-app-android by edx.
the class FindCoursesListAdapter method onItemClick.
@Override
public void onItemClick(AdapterView<?> adapterView, View arg1, int position, long arg3) {
// This time is checked to avoid taps in quick succession
final long currentTime = SystemClock.elapsedRealtime();
if (currentTime - lastClickTime > MIN_CLICK_INTERVAL) {
lastClickTime = currentTime;
CourseDetail model = (CourseDetail) adapterView.getItemAtPosition(position);
if (model != null)
onItemClicked(model);
}
}
Aggregations