use of org.edx.mobile.discussion.DiscussionThreadUpdatedEvent in project edx-app-android by edx.
the class CourseDiscussionResponsesFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Activity activity = getActivity();
responsesLoader = new ResponsesLoader(activity, discussionThread.getIdentifier(), discussionThread.getType() == DiscussionThread.ThreadType.QUESTION);
courseDiscussionResponsesAdapter = new CourseDiscussionResponsesAdapter(activity, this, this, discussionThread, courseData);
controller = InfiniteScrollUtils.configureRecyclerViewWithInfiniteList(discussionResponsesRecyclerView, courseDiscussionResponsesAdapter, responsesLoader);
discussionResponsesRecyclerView.setAdapter(courseDiscussionResponsesAdapter);
responsesLoader.freeze();
if (getAndReadThreadCall != null) {
getAndReadThreadCall.cancel();
}
final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
getAndReadThreadCall = discussionService.setThreadRead(discussionThread.getIdentifier(), new ReadBody(true));
// Setting a thread's "read" state gives us back the updated Thread object.
getAndReadThreadCall.enqueue(new ErrorHandlingCallback<DiscussionThread>(activity, null, mCallback, CallTrigger.LOADING_UNCACHED) {
@Override
protected void onResponse(@NonNull final DiscussionThread discussionThread) {
courseDiscussionResponsesAdapter.updateDiscussionThread(discussionThread);
responsesLoader.unfreeze();
EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
}
});
DiscussionUtils.setStateOnTopicClosed(discussionThread.isClosed(), addResponseTextView, R.string.discussion_responses_add_response_button, R.string.discussion_add_response_disabled_title, addResponseLayout, new View.OnClickListener() {
@Override
public void onClick(View v) {
router.showCourseDiscussionAddResponse(activity, discussionThread);
}
});
addResponseLayout.setEnabled(!courseData.isDiscussionBlackedOut());
}
use of org.edx.mobile.discussion.DiscussionThreadUpdatedEvent in project edx-app-android by edx.
the class CourseDiscussionResponsesAdapter method bindViewHolderToThreadRow.
private void bindViewHolderToThreadRow(DiscussionThreadViewHolder holder) {
holder.authorLayoutViewHolder.populateViewHolder(config, discussionThread, discussionThread, initialTimeStampMs, new Runnable() {
@Override
public void run() {
listener.onClickAuthor(discussionThread.getAuthor());
}
});
holder.threadTitleTextView.setText(discussionThread.getTitle());
DiscussionTextUtils.renderHtml(holder.threadBodyTextView, discussionThread.getRenderedBody());
String groupName = discussionThread.getGroupName();
if (groupName == null) {
holder.threadVisibilityTextView.setText(R.string.discussion_post_visibility_everyone);
} else {
holder.threadVisibilityTextView.setText(ResourceUtil.getFormattedString(context.getResources(), R.string.discussion_post_visibility_cohort, "cohort", groupName));
}
bindNumberResponsesView(holder.numberResponsesViewHolder);
if (TextUtils.equals(loginPrefs.getUsername(), discussionThread.getAuthor())) {
holder.actionsBar.setVisibility(View.GONE);
} else {
holder.actionsBar.setVisibility(View.VISIBLE);
bindSocialView(holder.socialLayoutViewHolder, discussionThread);
holder.discussionReportViewHolder.reportLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
discussionService.setThreadFlagged(discussionThread.getIdentifier(), new FlagBody(!discussionThread.isAbuseFlagged())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {
@Override
protected void onResponse(@NonNull final DiscussionThread topicThread) {
discussionThread = discussionThread.patchObject(topicThread);
notifyItemChanged(0);
EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
}
});
}
});
holder.discussionReportViewHolder.setReported(discussionThread.isAbuseFlagged());
}
}
use of org.edx.mobile.discussion.DiscussionThreadUpdatedEvent in project edx-app-android by edx.
the class CourseDiscussionResponsesAdapter method bindSocialView.
private void bindSocialView(DiscussionSocialLayoutViewHolder holder, DiscussionThread thread) {
holder.setDiscussionThread(thread);
holder.voteViewContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
discussionService.setThreadVoted(discussionThread.getIdentifier(), new VoteBody(!discussionThread.isVoted())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {
@Override
protected void onResponse(@NonNull final DiscussionThread updatedDiscussionThread) {
discussionThread = discussionThread.patchObject(updatedDiscussionThread);
notifyItemChanged(0);
EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
}
});
}
});
holder.threadFollowContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
discussionService.setThreadFollowed(discussionThread.getIdentifier(), new FollowBody(!discussionThread.isFollowing())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {
@Override
protected void onResponse(@NonNull final DiscussionThread updatedDiscussionThread) {
discussionThread = discussionThread.patchObject(updatedDiscussionThread);
notifyItemChanged(0);
EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
}
});
}
});
}
Aggregations