use of org.edx.mobile.view.adapters.FindCoursesListAdapter 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);
}
Aggregations