Search in sources :

Example 1 with DiscussionComment

use of org.edx.mobile.discussion.DiscussionComment 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;
        }
    });
}
Also used : DiscussionComment(org.edx.mobile.discussion.DiscussionComment) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Activity(android.app.Activity) Page(org.edx.mobile.model.Page) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 2 with DiscussionComment

use of org.edx.mobile.discussion.DiscussionComment in project edx-app-android by edx.

the class CourseDiscussionResponsesAdapter method bindSocialView.

private void bindSocialView(DiscussionSocialLayoutViewHolder holder, final int position, final DiscussionComment response) {
    holder.setDiscussionResponse(response);
    holder.voteViewContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            discussionService.setCommentVoted(response.getIdentifier(), new VoteBody(!response.isVoted())).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);
                }
            });
        }
    });
}
Also used : ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) VoteBody(org.edx.mobile.discussion.DiscussionService.VoteBody) NonNull(android.support.annotation.NonNull) DiscussionComment(org.edx.mobile.discussion.DiscussionComment) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 3 with DiscussionComment

use of org.edx.mobile.discussion.DiscussionComment 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);
    }
}
Also used : StringRes(android.support.annotation.StringRes) DiscussionComment(org.edx.mobile.discussion.DiscussionComment) DiscussionTextUtils(org.edx.mobile.discussion.DiscussionTextUtils) FlagBody(org.edx.mobile.discussion.DiscussionService.FlagBody) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DiscussionThread(org.edx.mobile.discussion.DiscussionThread) ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) NonNull(android.support.annotation.NonNull) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification)

Example 4 with DiscussionComment

use of org.edx.mobile.discussion.DiscussionComment in project edx-app-android by edx.

the class DiscussionCommentsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    if (getItemViewType(position) == RowType.PROGRESS)
        return;
    final ResponseOrCommentViewHolder holder = (ResponseOrCommentViewHolder) viewHolder;
    final DiscussionComment discussionComment;
    final IconDrawable iconDrawable;
    if (position == 0) {
        discussionComment = response;
        DiscussionTextUtils.setEndorsedState(holder.authorLayoutViewHolder.answerTextView, thread, response);
        final int childCount = discussionComment.getChildCount();
        holder.discussionCommentCountReportTextView.setText(context.getResources().getQuantityString(R.plurals.number_responses_or_comments_comments_label, childCount, childCount));
        iconDrawable = new IconDrawable(context, FontAwesomeIcons.fa_comment).sizeRes(context, R.dimen.edx_small).colorRes(context, R.color.edx_brand_gray_base);
        holder.discussionCommentCountReportTextView.setOnClickListener(null);
        holder.discussionCommentCountReportTextView.setClickable(false);
    } else {
        holder.authorLayoutViewHolder.answerTextView.setVisibility(View.GONE);
        discussionComment = discussionComments.get(position - 1);
        iconDrawable = new IconDrawable(context, FontAwesomeIcons.fa_flag).sizeRes(context, R.dimen.edx_small).colorRes(context, discussionComment.isAbuseFlagged() ? R.color.edx_brand_primary_base : R.color.edx_brand_gray_base);
        if (TextUtils.equals(loginPrefs.getUsername(), discussionComment.getAuthor())) {
            holder.discussionCommentCountReportTextView.setVisibility(View.GONE);
        } else {
            holder.discussionCommentCountReportTextView.setVisibility(View.VISIBLE);
            holder.discussionCommentCountReportTextView.setText(discussionComment.isAbuseFlagged() ? context.getString(R.string.discussion_responses_reported_label) : context.getString(R.string.discussion_responses_report_label));
            holder.discussionCommentCountReportTextView.setTextColor(context.getResources().getColor(R.color.edx_brand_gray_base));
            holder.discussionCommentCountReportTextView.setOnClickListener(new View.OnClickListener() {

                public void onClick(final View v) {
                    listener.reportComment(discussionComment);
                }
            });
        }
    }
    holder.authorLayoutViewHolder.populateViewHolder(config, discussionComment, discussionComment, initialTimeStampMs, new Runnable() {

        @Override
        public void run() {
            listener.onClickAuthor(discussionComment.getAuthor());
        }
    });
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.discussionCommentCountReportTextView, iconDrawable, null, null, null);
    DiscussionTextUtils.renderHtml(holder.discussionCommentBody, discussionComment.getRenderedBody());
}
Also used : DiscussionComment(org.edx.mobile.discussion.DiscussionComment) IconDrawable(com.joanzapata.iconify.IconDrawable) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with DiscussionComment

use of org.edx.mobile.discussion.DiscussionComment in project edx-app-android by edx.

the class CourseDiscussionResponsesAdapter method addNewComment.

public void addNewComment(@NonNull DiscussionComment parent) {
    // Since, we have a added a new comment we need to update timestamps of all responses as well
    initialTimeStampMs = System.currentTimeMillis();
    discussionThread.incrementCommentCount();
    String parentId = parent.getIdentifier();
    for (ListIterator<DiscussionComment> responseIterator = discussionResponses.listIterator(); responseIterator.hasNext(); ) {
        DiscussionComment response = responseIterator.next();
        if (parentId.equals(response.getIdentifier())) {
            response.incrementChildCount();
            notifyItemChanged(1 + responseIterator.previousIndex());
            break;
        }
    }
}
Also used : DiscussionComment(org.edx.mobile.discussion.DiscussionComment)

Aggregations

DiscussionComment (org.edx.mobile.discussion.DiscussionComment)5 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 TextView (android.widget.TextView)3 NonNull (android.support.annotation.NonNull)2 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)2 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)2 Activity (android.app.Activity)1 StringRes (android.support.annotation.StringRes)1 IconDrawable (com.joanzapata.iconify.IconDrawable)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 FlagBody (org.edx.mobile.discussion.DiscussionService.FlagBody)1 VoteBody (org.edx.mobile.discussion.DiscussionService.VoteBody)1 DiscussionTextUtils (org.edx.mobile.discussion.DiscussionTextUtils)1 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)1 Page (org.edx.mobile.model.Page)1 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)1