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