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());
}
}
Aggregations