Search in sources :

Example 1 with TaskMessageCallback

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

the class EditUserProfileFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    setHasOptionsMenu(true);
    EventBus.getDefault().register(this);
    final Activity activity = getActivity();
    final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
    getAccountCall = userService.getAccount(username);
    getAccountCall.enqueue(new AccountDataUpdatedCallback(activity, username, // Disable default loading indicator, we have our own
    null, mCallback, CallTrigger.LOADING_CACHED));
    getProfileFormDescriptionTask = new GetProfileFormDescriptionTask(activity) {

        @Override
        protected void onSuccess(@NonNull FormDescription formDescription) throws Exception {
            EditUserProfileFragment.this.formDescription = formDescription;
            if (null != viewHolder) {
                setData(account, formDescription);
            }
        }
    };
    getProfileFormDescriptionTask.setTaskProcessCallback(null);
    getProfileFormDescriptionTask.execute();
}
Also used : AccountDataUpdatedCallback(org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback) Activity(android.app.Activity) GetProfileFormDescriptionTask(org.edx.mobile.user.GetProfileFormDescriptionTask) FormDescription(org.edx.mobile.user.FormDescription) InvalidLocaleException(org.edx.mobile.util.InvalidLocaleException) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 2 with TaskMessageCallback

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

the class CourseDiscussionCommentsFragment method getCommentsList.

protected void getCommentsList(@NonNull final InfiniteScrollUtils.PageLoadCallback<DiscussionComment> callback) {
    if (getCommentsListCall != null) {
        getCommentsListCall.cancel();
    }
    final List<String> requestedFields = Collections.singletonList(DiscussionRequestFields.PROFILE_IMAGE.getQueryParamValue());
    getCommentsListCall = discussionService.getCommentsList(discussionResponse.getIdentifier(), nextPage, requestedFields);
    final Activity activity = getActivity();
    final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
    getCommentsListCall.enqueue(new ErrorHandlingCallback<Page<DiscussionComment>>(activity, null, mCallback, CallTrigger.LOADING_UNCACHED) {

        @Override
        protected void onResponse(@NonNull final Page<DiscussionComment> threadCommentsPage) {
            ++nextPage;
            callback.onPageLoaded(threadCommentsPage);
            discussionCommentsAdapter.notifyDataSetChanged();
            hasMorePages = threadCommentsPage.hasNext();
        }

        @Override
        protected void onFailure(@NonNull final Throwable error) {
            callback.onError();
            nextPage = 1;
            hasMorePages = false;
        }
    });
}
Also used : DiscussionComment(org.edx.mobile.discussion.DiscussionComment) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Activity(android.app.Activity) Page(org.edx.mobile.model.Page) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 3 with TaskMessageCallback

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

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

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

the class Task method onException.

@Override
protected void onException(Exception ex) {
    final TaskMessageCallback callback = getMessageCallback();
    if (callback == null) {
        return;
    }
    callback.onMessage(getMessageType(), ErrorUtils.getErrorMessage(ex, callTrigger, context));
}
Also used : TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Aggregations

TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)7 Activity (android.app.Activity)6 Page (org.edx.mobile.model.Page)3 View (android.view.View)2 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)2 CourseDetail (org.edx.mobile.course.CourseDetail)2 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)2 TaskProgressCallback (org.edx.mobile.view.common.TaskProgressCallback)2 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 DiscussionComment (org.edx.mobile.discussion.DiscussionComment)1 ReadBody (org.edx.mobile.discussion.DiscussionService.ReadBody)1 DiscussionThreadUpdatedEvent (org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)1 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)1 FormDescription (org.edx.mobile.user.FormDescription)1 GetProfileFormDescriptionTask (org.edx.mobile.user.GetProfileFormDescriptionTask)1 AccountDataUpdatedCallback (org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback)1 InvalidLocaleException (org.edx.mobile.util.InvalidLocaleException)1