Search in sources :

Example 1 with CourseDetail

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);
}
Also used : InfiniteScrollUtils(org.edx.mobile.view.adapters.InfiniteScrollUtils) Activity(android.app.Activity) Page(org.edx.mobile.model.Page) View(android.view.View) ListView(android.widget.ListView) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback) ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) CourseDetail(org.edx.mobile.course.CourseDetail) NonNull(android.support.annotation.NonNull) FindCoursesListAdapter(org.edx.mobile.view.adapters.FindCoursesListAdapter)

Example 2 with CourseDetail

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);
            }
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) CourseDetail(org.edx.mobile.course.CourseDetail) Activity(android.app.Activity) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 3 with CourseDetail

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);
    }
}
Also used : CourseDetail(org.edx.mobile.course.CourseDetail)

Aggregations

CourseDetail (org.edx.mobile.course.CourseDetail)3 Activity (android.app.Activity)2 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)2 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ListView (android.widget.ListView)1 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)1 Page (org.edx.mobile.model.Page)1 FindCoursesListAdapter (org.edx.mobile.view.adapters.FindCoursesListAdapter)1 InfiniteScrollUtils (org.edx.mobile.view.adapters.InfiniteScrollUtils)1 TaskProgressCallback (org.edx.mobile.view.common.TaskProgressCallback)1