use of org.edx.mobile.model.Page 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.model.Page 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.model.Page 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;
}
});
}
use of org.edx.mobile.model.Page in project edx-app-android by edx.
the class JsonPageDeserializer method deserialize.
@Override
public Page<?> deserialize(JsonElement json, final Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final List<?> list = context.deserialize(json.getAsJsonObject().get("results"), new ParameterizedType() {
public Type getRawType() {
return List.class;
}
public Type getOwnerType() {
return null;
}
public Type[] getActualTypeArguments() {
return ((ParameterizedType) typeOfT).getActualTypeArguments();
}
});
JsonElement paginationJson = json.getAsJsonObject().get("pagination");
if (null == paginationJson || paginationJson.isJsonNull()) {
paginationJson = json;
}
final PaginationData paginationData = context.deserialize(paginationJson, PaginationData.class);
return new Page<>(paginationData, list);
}
use of org.edx.mobile.model.Page 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);
}
Aggregations