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();
}
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;
}
});
}
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;
}
});
}
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);
}
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));
}
Aggregations