Search in sources :

Example 6 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class NotesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(NoteViewHolder noteViewHolder, int position) {
    final Note note = getNoteAtPosition(position);
    if (note == null) {
        return;
    }
    noteViewHolder.itemView.setTag(note.getId());
    // Display group header
    Note.NoteTimeGroup timeGroup = Note.getTimeGroupForTimestamp(note.getTimestamp());
    Note.NoteTimeGroup previousTimeGroup = null;
    if (position > 0) {
        Note previousNote = getNoteAtPosition(position - 1);
        previousTimeGroup = Note.getTimeGroupForTimestamp(previousNote.getTimestamp());
    }
    if (previousTimeGroup != null && previousTimeGroup == timeGroup) {
        noteViewHolder.headerView.setVisibility(View.GONE);
    } else {
        if (timeGroup == Note.NoteTimeGroup.GROUP_TODAY) {
            noteViewHolder.headerText.setText(R.string.stats_timeframe_today);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_YESTERDAY) {
            noteViewHolder.headerText.setText(R.string.stats_timeframe_yesterday);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_OLDER_TWO_DAYS) {
            noteViewHolder.headerText.setText(R.string.older_two_days);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_OLDER_WEEK) {
            noteViewHolder.headerText.setText(R.string.older_last_week);
        } else {
            noteViewHolder.headerText.setText(R.string.older_month);
        }
        noteViewHolder.headerView.setVisibility(View.VISIBLE);
    }
    if (mHiddenNoteIds.size() > 0 && mHiddenNoteIds.contains(note.getId())) {
        noteViewHolder.contentView.setVisibility(View.GONE);
        noteViewHolder.headerView.setVisibility(View.GONE);
    } else {
        noteViewHolder.contentView.setVisibility(View.VISIBLE);
    }
    CommentStatus commentStatus = CommentStatus.ALL;
    if (note.getCommentStatus() == CommentStatus.UNAPPROVED) {
        commentStatus = CommentStatus.UNAPPROVED;
    }
    if (!TextUtils.isEmpty(note.getLocalStatus())) {
        commentStatus = CommentStatus.fromString(note.getLocalStatus());
    }
    if (mModeratingNoteIds.size() > 0 && mModeratingNoteIds.contains(note.getId())) {
        noteViewHolder.progressBar.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.progressBar.setVisibility(View.GONE);
    }
    // Subject is stored in db as html to preserve text formatting
    CharSequence noteSubjectSpanned = note.getFormattedSubject();
    // Trim the '\n\n' added by Html.fromHtml()
    noteSubjectSpanned = noteSubjectSpanned.subSequence(0, TextUtils.getTrimmedLength(noteSubjectSpanned));
    noteViewHolder.txtSubject.setText(noteSubjectSpanned);
    String noteSubjectNoticon = note.getCommentSubjectNoticon();
    if (!TextUtils.isEmpty(noteSubjectNoticon)) {
        CommentUtils.indentTextViewFirstLine(noteViewHolder.txtSubject, mTextIndentSize);
        noteViewHolder.txtSubjectNoticon.setText(noteSubjectNoticon);
        noteViewHolder.txtSubjectNoticon.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.txtSubjectNoticon.setVisibility(View.GONE);
    }
    String noteSnippet = note.getCommentSubject();
    if (!TextUtils.isEmpty(noteSnippet)) {
        noteViewHolder.txtSubject.setMaxLines(2);
        noteViewHolder.txtDetail.setText(noteSnippet);
        noteViewHolder.txtDetail.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.txtSubject.setMaxLines(3);
        noteViewHolder.txtDetail.setVisibility(View.GONE);
    }
    String avatarUrl = GravatarUtils.fixGravatarUrl(note.getIconURL(), mAvatarSz);
    noteViewHolder.imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
    boolean isUnread = note.isUnread();
    String noticonCharacter = note.getNoticonCharacter();
    noteViewHolder.noteIcon.setText(noticonCharacter);
    if (commentStatus == CommentStatus.UNAPPROVED) {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_orange);
    } else if (isUnread) {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_blue_white_stroke);
    } else {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_grey);
    }
    if (isUnread) {
        noteViewHolder.itemView.setBackgroundColor(mColorUnread);
    } else {
        noteViewHolder.itemView.setBackgroundColor(mColorRead);
    }
    // request to load more comments when we near the end
    if (mOnLoadMoreListener != null && position >= getItemCount() - 1) {
        mOnLoadMoreListener.onLoadMore(note.getTimestamp());
    }
}
Also used : Note(org.wordpress.android.models.Note) CommentStatus(org.wordpress.android.fluxc.model.CommentStatus)

Aggregations

CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)6 View (android.view.View)2 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 TextView (android.widget.TextView)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 KeyEvent (android.view.KeyEvent)1 RelativeLayout (android.widget.RelativeLayout)1 CommentActionBuilder (org.wordpress.android.fluxc.generated.CommentActionBuilder)1 CommentModel (org.wordpress.android.fluxc.model.CommentModel)1 CommentList (org.wordpress.android.models.CommentList)1 Note (org.wordpress.android.models.Note)1