Search in sources :

Example 1 with ProgressViewController

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

the class CourseDiscussionPostsThreadFragment method populatePostList.

private void populatePostList(@NonNull final InfiniteScrollUtils.PageLoadCallback<DiscussionThread> callback) {
    if (getThreadListCall != null) {
        getThreadListCall.cancel();
    }
    final List<String> requestedFields = Collections.singletonList(DiscussionRequestFields.PROFILE_IMAGE.getQueryParamValue());
    if (!discussionTopic.isFollowingType()) {
        getThreadListCall = discussionService.getThreadList(courseData.getCourse().getId(), getAllTopicIds(), postsFilter.getQueryParamValue(), postsSort.getQueryParamValue(), nextPage, requestedFields);
    } else {
        getThreadListCall = discussionService.getFollowingThreadList(courseData.getCourse().getId(), postsFilter.getQueryParamValue(), postsSort.getQueryParamValue(), nextPage, requestedFields);
    }
    final Activity activity = getActivity();
    final boolean isRefreshingSilently = callback.isRefreshingSilently();
    getThreadListCall.enqueue(new ErrorHandlingCallback<Page<DiscussionThread>>(activity, // the ListView will start showing a footer-based loading indicator.
    nextPage > 1 || isRefreshingSilently ? null : new ProgressViewController(loadingIndicator), // We only require the error to appear if the first server call fails
    nextPage == 1 ? errorNotification : null) {

        @Override
        protected void onResponse(@NonNull final Page<DiscussionThread> threadsPage) {
            if (getView() == null)
                return;
            ++nextPage;
            callback.onPageLoaded(threadsPage);
            if (discussionPostsAdapter.getCount() == 0) {
                if (discussionTopic.isAllType()) {
                    setScreenStateUponError(EmptyQueryResultsFor.COURSE);
                } else if (discussionTopic.isFollowingType()) {
                    setScreenStateUponError(EmptyQueryResultsFor.FOLLOWING);
                } else {
                    setScreenStateUponError(EmptyQueryResultsFor.CATEGORY);
                }
            } else {
                setScreenStateUponResult();
            }
        }

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

Example 2 with ProgressViewController

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

the class CourseDiscussionPostsThreadFragment method fetchDiscussionTopic.

private void fetchDiscussionTopic() {
    String topicId = getArguments().getString(Router.EXTRA_DISCUSSION_TOPIC_ID);
    final Activity activity = getActivity();
    discussionService.getSpecificCourseTopics(courseData.getCourse().getId(), Collections.singletonList(topicId)).enqueue(new ErrorHandlingCallback<CourseTopics>(activity, new ProgressViewController(loadingIndicator), errorNotification) {

        @Override
        protected void onResponse(@NonNull final CourseTopics courseTopics) {
            discussionTopic = courseTopics.getCoursewareTopics().get(0).getChildren().get(0);
            if (activity != null && !getArguments().getBoolean(ARG_DISCUSSION_HAS_TOPIC_NAME)) {
                // We only need to set the title here when coming from a deep link
                activity.setTitle(discussionTopic.getName());
            }
            if (getView() != null) {
                if (populatePostListRunnable != null) {
                    populatePostListRunnable.run();
                }
                // Now that we have the topic data, we can allow the user to add new posts.
                setCreateNewPostBtnVisibility(View.VISIBLE);
            }
        }
    });
}
Also used : ProgressViewController(org.edx.mobile.view.common.TaskProgressCallback.ProgressViewController) Activity(android.app.Activity) CourseTopics(org.edx.mobile.discussion.CourseTopics)

Aggregations

Activity (android.app.Activity)2 ProgressViewController (org.edx.mobile.view.common.TaskProgressCallback.ProgressViewController)2 CourseTopics (org.edx.mobile.discussion.CourseTopics)1 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)1 Page (org.edx.mobile.model.Page)1