Search in sources :

Example 6 with ReaderComment

use of org.wordpress.android.models.ReaderComment in project WordPress-Android by wordpress-mobile.

the class ReaderCommentAdapter method refreshComment.

public boolean refreshComment(long commentId) {
    int position = positionOfCommentId(commentId);
    if (position == -1) {
        return false;
    }
    ReaderComment comment = getItem(position);
    if (comment == null) {
        return false;
    }
    ReaderComment updatedComment = ReaderCommentTable.getComment(comment.blogId, comment.postId, comment.commentId);
    if (updatedComment != null) {
        // copy the comment level over since loading from the DB always has it as 0
        updatedComment.level = comment.level;
        mComments.set(position - NUM_HEADERS, updatedComment);
        notifyItemChanged(position);
    }
    return true;
}
Also used : ReaderComment(org.wordpress.android.models.ReaderComment)

Example 7 with ReaderComment

use of org.wordpress.android.models.ReaderComment in project WordPress-Android by wordpress-mobile.

the class ReaderCommentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof PostHeaderHolder) {
        PostHeaderHolder headerHolder = (PostHeaderHolder) holder;
        headerHolder.mHeaderView.setPost(mPost);
        if (mIsHeaderClickEnabled) {
            headerHolder.mHeaderView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    ReaderActivityLauncher.showReaderPostDetail(view.getContext(), mPost.blogId, mPost.postId);
                }
            });
        }
        return;
    }
    final ReaderComment comment = getItem(position);
    if (comment == null) {
        return;
    }
    final CommentHolder commentHolder = (CommentHolder) holder;
    commentHolder.txtAuthor.setText(comment.getAuthorName());
    java.util.Date dtPublished = DateTimeUtils.dateFromIso8601(comment.getPublished());
    commentHolder.txtDate.setText(DateTimeUtils.javaDateToTimeSpan(dtPublished, WordPress.getContext()));
    if (comment.hasAuthorAvatar()) {
        String avatarUrl = GravatarUtils.fixGravatarUrl(comment.getAuthorAvatar(), mAvatarSz);
        commentHolder.imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
    } else {
        commentHolder.imgAvatar.showDefaultGravatarImage();
    }
    // tapping avatar or author name opens blog preview
    if (comment.hasAuthorBlogId()) {
        View.OnClickListener authorListener = new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ReaderActivityLauncher.showReaderBlogPreview(view.getContext(), comment.authorBlogId);
            }
        };
        commentHolder.imgAvatar.setOnClickListener(authorListener);
        commentHolder.txtAuthor.setOnClickListener(authorListener);
    } else {
        commentHolder.imgAvatar.setOnClickListener(null);
        commentHolder.txtAuthor.setOnClickListener(null);
    }
    // author name uses different color for comments from the post's author
    if (comment.authorId == mPost.authorId) {
        commentHolder.txtAuthor.setTextColor(mColorAuthor);
    } else {
        commentHolder.txtAuthor.setTextColor(mColorNotAuthor);
    }
    // show indentation spacer for comments with parents and indent it based on comment level
    int indentWidth;
    if (comment.parentId != 0 && comment.level > 0) {
        indentWidth = Math.min(MAX_INDENT_LEVEL, comment.level) * mIndentPerLevel;
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) commentHolder.spacerIndent.getLayoutParams();
        params.width = indentWidth;
        commentHolder.spacerIndent.setVisibility(View.VISIBLE);
    } else {
        indentWidth = 0;
        commentHolder.spacerIndent.setVisibility(View.GONE);
    }
    int maxImageWidth = mContentWidth - indentWidth;
    CommentUtils.displayHtmlComment(commentHolder.txtText, comment.getText(), maxImageWidth, mImageLoader);
    // different background for highlighted comment, with optional progress bar
    if (mHighlightCommentId != 0 && mHighlightCommentId == comment.commentId) {
        commentHolder.container.setBackgroundColor(mColorHighlight);
        commentHolder.progress.setVisibility(mShowProgressForHighlightedComment ? View.VISIBLE : View.GONE);
    } else {
        commentHolder.container.setBackgroundColor(Color.WHITE);
        commentHolder.progress.setVisibility(View.GONE);
    }
    if (!mAccountStore.hasAccessToken()) {
        commentHolder.replyView.setVisibility(View.GONE);
    } else {
        // tapping reply tells activity to show reply box
        commentHolder.replyView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mReplyListener != null) {
                    mReplyListener.onRequestReply(comment.commentId);
                }
            }
        });
        if (mAnimateLikeCommentId != 0 && mAnimateLikeCommentId == comment.commentId) {
            // simulate tapping on the "Like" button. Add a delay to help the user notice it.
            commentHolder.countLikes.postDelayed(new Runnable() {

                @Override
                public void run() {
                    ReaderAnim.animateLikeButton(commentHolder.countLikes.getImageView(), true);
                }
            }, 400);
            // clear the "command" to like a comment
            mAnimateLikeCommentId = 0;
        }
    }
    showLikeStatus(commentHolder, position);
    // fire request to load more
    if (mMoreCommentsExist && mDataRequestedListener != null && (position >= getItemCount() - NUM_HEADERS)) {
        mDataRequestedListener.onRequestData();
    }
}
Also used : WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) View(android.view.View) ReaderCommentsPostHeaderView(org.wordpress.android.ui.reader.views.ReaderCommentsPostHeaderView) ReaderIconCountView(org.wordpress.android.ui.reader.views.ReaderIconCountView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ReaderComment(org.wordpress.android.models.ReaderComment) RelativeLayout(android.widget.RelativeLayout)

Example 8 with ReaderComment

use of org.wordpress.android.models.ReaderComment in project WordPress-Android by wordpress-mobile.

the class ReaderCommentAdapter method toggleLike.

private void toggleLike(Context context, CommentHolder holder, int position) {
    if (!NetworkUtils.checkConnection(context)) {
        return;
    }
    ReaderComment comment = getItem(position);
    if (comment == null) {
        ToastUtils.showToast(context, R.string.reader_toast_err_generic);
        return;
    }
    boolean isAskingToLike = !comment.isLikedByCurrentUser;
    ReaderAnim.animateLikeButton(holder.countLikes.getImageView(), isAskingToLike);
    if (!ReaderCommentActions.performLikeAction(comment, isAskingToLike, mAccountStore.getAccount().getUserId())) {
        ToastUtils.showToast(context, R.string.reader_toast_err_generic);
        return;
    }
    ReaderComment updatedComment = ReaderCommentTable.getComment(comment.blogId, comment.postId, comment.commentId);
    if (updatedComment != null) {
        mComments.set(position - NUM_HEADERS, updatedComment);
        showLikeStatus(holder, position);
    }
    AnalyticsUtils.trackWithReaderPostDetails(isAskingToLike ? AnalyticsTracker.Stat.READER_ARTICLE_COMMENT_LIKED : AnalyticsTracker.Stat.READER_ARTICLE_COMMENT_UNLIKED, mPost);
}
Also used : ReaderComment(org.wordpress.android.models.ReaderComment)

Example 9 with ReaderComment

use of org.wordpress.android.models.ReaderComment in project WordPress-Android by wordpress-mobile.

the class ReaderCommentTable method hasNewComments.

/*
     * returns true if any of the passed comments don't already exist
     * IMPORTANT: assumes passed comments are all for the same post
     */
public static boolean hasNewComments(ReaderCommentList comments) {
    if (comments == null || comments.size() == 0) {
        return false;
    }
    StringBuilder sb = new StringBuilder("SELECT COUNT(*) FROM tbl_comments WHERE blog_id=? AND post_id=? AND comment_id IN (");
    boolean isFirst = true;
    for (ReaderComment comment : comments) {
        if (isFirst) {
            isFirst = false;
        } else {
            sb.append(",");
        }
        sb.append(comment.commentId);
    }
    sb.append(")");
    String[] args = { Long.toString(comments.get(0).blogId), Long.toString(comments.get(0).postId) };
    int numExisting = SqlUtils.intForQuery(ReaderDatabase.getReadableDb(), sb.toString(), args);
    return numExisting != comments.size();
}
Also used : ReaderComment(org.wordpress.android.models.ReaderComment)

Example 10 with ReaderComment

use of org.wordpress.android.models.ReaderComment in project WordPress-Android by wordpress-mobile.

the class ReaderCommentTable method getCommentFromCursor.

private static ReaderComment getCommentFromCursor(Cursor c) {
    if (c == null) {
        throw new IllegalArgumentException("null comment cursor");
    }
    ReaderComment comment = new ReaderComment();
    comment.commentId = c.getLong(c.getColumnIndex("comment_id"));
    comment.blogId = c.getLong(c.getColumnIndex("blog_id"));
    comment.postId = c.getLong(c.getColumnIndex("post_id"));
    comment.parentId = c.getLong(c.getColumnIndex("parent_id"));
    comment.setPublished(c.getString(c.getColumnIndex("published")));
    comment.timestamp = c.getLong(c.getColumnIndex("timestamp"));
    comment.setAuthorAvatar(c.getString(c.getColumnIndex("author_avatar")));
    comment.setAuthorName(c.getString(c.getColumnIndex("author_name")));
    comment.setAuthorUrl(c.getString(c.getColumnIndex("author_url")));
    comment.authorId = c.getLong(c.getColumnIndex("author_id"));
    comment.authorBlogId = c.getLong(c.getColumnIndex("author_blog_id"));
    comment.setStatus(c.getString(c.getColumnIndex("status")));
    comment.setText(c.getString(c.getColumnIndex("text")));
    comment.numLikes = c.getInt(c.getColumnIndex("num_likes"));
    comment.isLikedByCurrentUser = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_liked")));
    comment.pageNumber = c.getInt(c.getColumnIndex("page_number"));
    return comment;
}
Also used : ReaderComment(org.wordpress.android.models.ReaderComment)

Aggregations

ReaderComment (org.wordpress.android.models.ReaderComment)10 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 TextView (android.widget.TextView)2 ReaderCommentsPostHeaderView (org.wordpress.android.ui.reader.views.ReaderCommentsPostHeaderView)2 ReaderIconCountView (org.wordpress.android.ui.reader.views.ReaderIconCountView)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 RelativeLayout (android.widget.RelativeLayout)1 VolleyError (com.android.volley.VolleyError)1 RestRequest (com.wordpress.rest.RestRequest)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1 ReaderUser (org.wordpress.android.models.ReaderUser)1 ReaderActions (org.wordpress.android.ui.reader.actions.ReaderActions)1