use of org.edx.mobile.discussion.DiscussionService.FlagBody in project edx-app-android by edx.
the class CourseDiscussionResponsesAdapter method bindViewHolderToResponseRow.
private void bindViewHolderToResponseRow(DiscussionResponseViewHolder holder, final int position) {
// Subtract 1 for the discussion thread row at position 0
final DiscussionComment comment = discussionResponses.get(position - 1);
holder.authorLayoutViewHolder.populateViewHolder(config, comment, comment, initialTimeStampMs, new Runnable() {
@Override
public void run() {
listener.onClickAuthor(comment.getAuthor());
}
});
if (comment.isEndorsed()) {
holder.authorLayoutViewHolder.answerTextView.setVisibility(View.VISIBLE);
holder.responseAnswerAuthorTextView.setVisibility(View.VISIBLE);
DiscussionThread.ThreadType threadType = discussionThread.getType();
DiscussionTextUtils.AuthorAttributionLabel authorAttributionLabel;
@StringRes int endorsementTypeStringRes;
switch(threadType) {
case QUESTION:
authorAttributionLabel = DiscussionTextUtils.AuthorAttributionLabel.ANSWER;
endorsementTypeStringRes = R.string.discussion_responses_answer;
break;
case DISCUSSION:
default:
authorAttributionLabel = DiscussionTextUtils.AuthorAttributionLabel.ENDORSEMENT;
endorsementTypeStringRes = R.string.discussion_responses_endorsed;
break;
}
holder.authorLayoutViewHolder.answerTextView.setText(endorsementTypeStringRes);
DiscussionTextUtils.setAuthorAttributionText(holder.responseAnswerAuthorTextView, authorAttributionLabel, comment.getEndorserData(), initialTimeStampMs, new Runnable() {
@Override
public void run() {
listener.onClickAuthor(comment.getEndorsedBy());
}
});
} else {
holder.authorLayoutViewHolder.answerTextView.setVisibility(View.GONE);
holder.responseAnswerAuthorTextView.setVisibility(View.GONE);
}
DiscussionTextUtils.renderHtml(holder.responseCommentBodyTextView, comment.getRenderedBody());
if (discussionThread.isClosed() && comment.getChildCount() == 0) {
holder.addCommentLayout.setEnabled(false);
} else if (courseData.isDiscussionBlackedOut() && comment.getChildCount() == 0) {
holder.addCommentLayout.setEnabled(false);
} else {
holder.addCommentLayout.setEnabled(true);
holder.addCommentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (comment.getChildCount() > 0) {
listener.onClickViewComments(comment);
} else {
listener.onClickAddComment(comment);
}
}
});
}
bindNumberCommentsView(holder.numberResponsesViewHolder, comment);
if (TextUtils.equals(loginPrefs.getUsername(), comment.getAuthor())) {
holder.actionsBar.setVisibility(View.GONE);
} else {
holder.actionsBar.setVisibility(View.VISIBLE);
bindSocialView(holder.socialLayoutViewHolder, position, comment);
holder.discussionReportViewHolder.reportLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
discussionService.setCommentFlagged(comment.getIdentifier(), new FlagBody(!comment.isAbuseFlagged())).enqueue(new ErrorHandlingCallback<DiscussionComment>(context, null, new DialogErrorNotification(baseFragment)) {
@Override
protected void onResponse(@NonNull final DiscussionComment comment) {
discussionResponses.get(position - 1).patchObject(comment);
discussionResponses.set(position - 1, comment);
notifyItemChanged(position);
}
});
}
});
holder.discussionReportViewHolder.setReported(comment.isAbuseFlagged());
holder.socialLayoutViewHolder.threadFollowContainer.setVisibility(View.INVISIBLE);
}
}
use of org.edx.mobile.discussion.DiscussionService.FlagBody 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());
}
}
Aggregations