Search in sources :

Example 1 with TaskProgressCallback

use of org.edx.mobile.view.common.TaskProgressCallback in project edx-app-android by edx.

the class CourseDiscussionPostsSearchFragment method loadNextPage.

@Override
public void loadNextPage(@NonNull final InfiniteScrollUtils.PageLoadCallback<DiscussionThread> callback) {
    final Activity activity = getActivity();
    final TaskProgressCallback progressCallback = activity instanceof TaskProgressCallback ? (TaskProgressCallback) activity : null;
    final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
    if (mCallback != null) {
        mCallback.onMessage(MessageType.EMPTY, "");
    }
    if (searchThreadListCall != null) {
        searchThreadListCall.cancel();
    }
    final List<String> requestedFields = Collections.singletonList(DiscussionRequestFields.PROFILE_IMAGE.getQueryParamValue());
    searchThreadListCall = discussionService.searchThreadList(courseData.getCourse().getId(), searchQuery, nextPage, requestedFields);
    final boolean isRefreshingSilently = callback.isRefreshingSilently();
    searchThreadListCall.enqueue(new ErrorHandlingCallback<Page<DiscussionThread>>(activity, // the ListView will start showing a footer-based loading indicator.
    nextPage > 1 || isRefreshingSilently ? null : progressCallback, mCallback, CallTrigger.LOADING_UNCACHED) {

        @Override
        protected void onResponse(@NonNull final Page<DiscussionThread> threadsPage) {
            ++nextPage;
            callback.onPageLoaded(threadsPage);
            if (activity instanceof TaskProcessCallback) {
                if (discussionPostsAdapter.getCount() == 0) {
                    String escapedTitle = TextUtils.htmlEncode(searchQuery);
                    String resultsText = ResourceUtil.getFormattedString(getContext().getResources(), R.string.forum_no_results_for_search_query, "search_query", escapedTitle).toString();
                    // CharSequence styledResults = Html.fromHtml(resultsText);
                    ((TaskProcessCallback) activity).onMessage(MessageType.ERROR, resultsText);
                } else {
                    ((TaskProcessCallback) activity).onMessage(MessageType.EMPTY, "");
                    discussionPostsListView.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void onFailure(@NonNull Call<Page<DiscussionThread>> call, @NonNull Throwable error) {
            // refresh, as that would be confusing to the user.
            if (!callback.isRefreshingSilently()) {
                super.onFailure(call, error);
            }
            callback.onError();
            nextPage = 1;
        }
    });
}
Also used : Activity(android.app.Activity) Page(org.edx.mobile.model.Page) DiscussionThread(org.edx.mobile.discussion.DiscussionThread) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback) TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) TaskProcessCallback(org.edx.mobile.view.common.TaskProcessCallback)

Example 2 with TaskProgressCallback

use of org.edx.mobile.view.common.TaskProgressCallback 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 TaskProgressCallback

use of org.edx.mobile.view.common.TaskProgressCallback in project edx-app-android by edx.

the class CourseDiscussionPostsThreadFragment method checkIfDiscussionsBlackedOut.

/**
 * Query server to check if discussions on this course are blacked out.
 */
private void checkIfDiscussionsBlackedOut() {
    setCreateNewPostBtnVisibility(View.GONE);
    discussionService.getCourseDiscussionInfo(courseData.getCourse().getId()).enqueue(new ErrorHandlingCallback<CourseDiscussionInfo>(getContext(), (TaskProgressCallback) null) {

        @Override
        public void onFailure(@NonNull Call<CourseDiscussionInfo> call, @NonNull Throwable t) {
            markAsBlackedOut(false);
        }

        @Override
        protected void onResponse(@NonNull CourseDiscussionInfo discussionInfo) {
            final Date today = new Date();
            final List<TimePeriod> blackoutTimesList = discussionInfo.getBlackoutList();
            for (TimePeriod timePeriod : blackoutTimesList) {
                if (today.after(timePeriod.getStart()) && today.before(timePeriod.getEnd())) {
                    markAsBlackedOut(true);
                    return;
                }
            }
            markAsBlackedOut(false);
        }

        private void markAsBlackedOut(boolean isBlackedOut) {
            courseData.setDiscussionBlackedOut(isBlackedOut);
            createNewPostLayout.setEnabled(!isBlackedOut);
            setCreateNewPostBtnVisibility(View.VISIBLE);
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) TimePeriod(org.edx.mobile.discussion.TimePeriod) CourseDiscussionInfo(org.edx.mobile.discussion.CourseDiscussionInfo) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with TaskProgressCallback

use of org.edx.mobile.view.common.TaskProgressCallback 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);
            }
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent) CourseAPI(org.edx.mobile.course.CourseAPI)

Aggregations

TaskProgressCallback (org.edx.mobile.view.common.TaskProgressCallback)4 Activity (android.app.Activity)2 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 CourseAPI (org.edx.mobile.course.CourseAPI)1 CourseDetail (org.edx.mobile.course.CourseDetail)1 CourseDiscussionInfo (org.edx.mobile.discussion.CourseDiscussionInfo)1 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)1 TimePeriod (org.edx.mobile.discussion.TimePeriod)1 CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)1 Page (org.edx.mobile.model.Page)1 CourseComponent (org.edx.mobile.model.course.CourseComponent)1 TaskProcessCallback (org.edx.mobile.view.common.TaskProcessCallback)1