use of net.dean.jraw.models.CommentNode in project Slide by ccrama.
the class CommentAdapter method unhideNumber.
public int unhideNumber(CommentNode n, int i) {
for (CommentNode ignored : n.getChildren()) {
if (!ignored.getComment().getFullName().equals(n.getComment().getFullName())) {
boolean parentHidden = parentHidden(ignored);
if (parentHidden) {
continue;
}
String name = ignored.getComment().getFullName();
if (hidden.contains(name) || hiddenPersons.contains(name)) {
hidden.remove(name);
i++;
if (ignored.hasMoreComments() && !hiddenPersons.contains(name) && dataSet.online) {
name = name + "more";
if (hidden.contains(name)) {
hidden.remove(name);
toCollapse.remove(name);
i++;
}
}
}
i += unhideNumber(ignored, 0);
}
}
if (n.hasMoreComments() && !parentHidden(n) && !hiddenPersons.contains(n.getComment().getFullName()) && dataSet.online) {
String fullname = n.getComment().getFullName() + "more";
if (hidden.contains(fullname)) {
i++;
hidden.remove(fullname);
}
}
return i;
}
use of net.dean.jraw.models.CommentNode in project Slide by ccrama.
the class CommentAdapter method hideNumber.
public int hideNumber(CommentNode n, int i) {
for (CommentNode ignored : n.getChildren()) {
if (!ignored.getComment().getFullName().equals(n.getComment().getFullName())) {
String fullname = ignored.getComment().getFullName();
if (!hidden.contains(fullname)) {
i++;
hidden.add(fullname);
}
if (ignored.hasMoreComments() && dataSet.online) {
if (currentLoading != null && currentLoading.fullname.equals(fullname)) {
currentLoading.cancel(true);
}
fullname = fullname + "more";
if (!hidden.contains(fullname)) {
i++;
hidden.add(fullname);
}
}
i += hideNumber(ignored, 0);
}
}
if (n.hasMoreComments() && dataSet.online) {
String fullname = n.getComment().getFullName() + "more";
if (!hidden.contains(fullname)) {
i++;
hidden.add(fullname);
}
}
return i;
}
use of net.dean.jraw.models.CommentNode in project Slide by ccrama.
the class CommentAdapter method getParents.
public String[] getParents(CommentNode comment) {
String[] bodies = new String[comment.getDepth() + 1];
bodies[0] = comment.getComment().getAuthor();
CommentNode parent = comment.getParent();
int index = 1;
while (parent != null) {
bodies[index] = parent.getComment().getAuthor();
index++;
parent = parent.getParent();
}
bodies[index - 1] = submission.getAuthor();
// Reverse the array so Submission > Author > ... > Current OP
for (int i = 0; i < bodies.length / 2; i++) {
String temp = bodies[i];
bodies[i] = bodies[bodies.length - i - 1];
bodies[bodies.length - i - 1] = temp;
}
return bodies;
}
use of net.dean.jraw.models.CommentNode in project Slide by ccrama.
the class CommentAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int old) {
int pos = old != 0 ? old - 1 : old;
if (firstHolder instanceof CommentViewHolder) {
final CommentViewHolder holder = (CommentViewHolder) firstHolder;
int datasetPosition = pos - 1;
datasetPosition = getRealPosition(datasetPosition);
if (pos > toShiftTo) {
shifted = 0;
}
if (pos < shiftFrom) {
shifted = 0;
}
final CommentNode baseNode = currentComments.get(datasetPosition).comment;
final Comment comment = baseNode.getComment();
if (pos == getItemCount() - 1) {
holder.itemView.setPadding(0, 0, 0, (int) mContext.getResources().getDimension(R.dimen.overview_top_padding_single));
} else {
holder.itemView.setPadding(0, 0, 0, 0);
}
doScoreText(holder, comment, this);
// Long click listeners
View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
return true;
}
};
holder.firstTextView.setOnLongClickListener(onLongClickListener);
holder.commentOverflow.setOnLongClickListener(onLongClickListener);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
}
return true;
}
});
// Single click listeners
OnSingleClickListener singleClick = new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doLongClick(holder, comment, baseNode);
} else {
doOnClick(holder, comment, baseNode);
}
}
}
};
holder.itemView.setOnClickListener(singleClick);
holder.commentOverflow.setOnClickListener(singleClick);
if (!toCollapse.contains(comment.getFullName()) && SettingValues.collapseComments || !SettingValues.collapseComments) {
setViews(comment.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder, singleClick, onLongClickListener);
}
holder.firstTextView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
SpoilerRobotoTextView SpoilerRobotoTextView = (SpoilerRobotoTextView) v;
if (SettingValues.swap) {
if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doLongClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
} else if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doOnClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
}
});
if (ImageFlairs.isSynced(comment.getSubredditName()) && comment.getAuthorFlair() != null && !comment.getAuthorFlair().getText().isEmpty() && !comment.getAuthorFlair().getCssClass().isEmpty()) {
boolean set = false;
for (String s : comment.getAuthorFlair().getCssClass().split(" ")) {
File file = DiskCacheUtils.findInCache(comment.getSubredditName().toLowerCase(Locale.ENGLISH) + ":" + s.toLowerCase(Locale.ENGLISH), ImageFlairs.getFlairImageLoader(mContext).getInstance().getDiskCache());
if (file != null && file.exists()) {
set = true;
holder.imageFlair.setVisibility(View.VISIBLE);
String decodedImgUri = Uri.fromFile(file).toString();
ImageFlairs.getFlairImageLoader(mContext).displayImage(decodedImgUri, holder.imageFlair);
break;
}
}
if (!set) {
holder.imageFlair.setImageDrawable(null);
holder.imageFlair.setVisibility(View.GONE);
}
} else {
holder.imageFlair.setVisibility(View.GONE);
}
// Set typeface for body
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.firstTextView.setTypeface(typeface);
// Show padding on top
if (baseNode.isTopLevel()) {
holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
} else if (holder.itemView.findViewById(R.id.next).getVisibility() == View.VISIBLE) {
holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
}
// Should be collapsed?
if (hiddenPersons.contains(comment.getFullName()) || toCollapse.contains(comment.getFullName())) {
int childnumber = getChildNumber(baseNode);
if (hiddenPersons.contains(comment.getFullName()) && childnumber > 0) {
holder.childrenNumber.setVisibility(View.VISIBLE);
holder.childrenNumber.setText("+" + childnumber);
} else {
holder.childrenNumber.setVisibility(View.GONE);
}
if (SettingValues.collapseComments && toCollapse.contains(comment.getFullName())) {
holder.firstTextView.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.GONE);
}
} else {
holder.childrenNumber.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.VISIBLE);
}
holder.dot.setVisibility(View.VISIBLE);
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
// Padding on the left, starting with the third comment
for (int i = 2; i < baseNode.getDepth(); i++) {
width += dwidth;
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) holder.dot.getLayoutParams();
params2.width = dwidth;
holder.dot.setLayoutParams(params2);
if (baseNode.getDepth() - 1 > 0) {
int i22 = baseNode.getDepth() - 2;
String commentOp = dataSet.commentOPs.get(comment.getId());
if (SettingValues.highlightCommentOP && commentOp != null && comment != null && commentOp.equals(comment.getAuthor())) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_purple_500));
} else {
if (i22 % 5 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_700 : R.color.md_blue_500));
} else if (i22 % 4 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_600 : R.color.md_green_500));
} else if (i22 % 3 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_500 : R.color.md_yellow_500));
} else if (i22 % 2 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_400 : R.color.md_orange_500));
} else {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_300 : R.color.md_red_500));
}
}
} else {
holder.dot.setVisibility(View.GONE);
}
if (currentSelectedItem != null && comment.getFullName().contains(currentSelectedItem) && !currentSelectedItem.isEmpty() && !currentlyEditingId.equals(comment.getFullName())) {
doHighlighted(holder, comment, baseNode, false);
} else if (!currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
}
if (deleted.contains(comment.getFullName())) {
holder.firstTextView.setText(R.string.comment_deleted);
holder.content.setText(R.string.comment_deleted);
}
if (currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
setCommentStateHighlighted(holder, comment, baseNode, true, false);
}
} else if (firstHolder instanceof SubmissionViewHolder && submission != null) {
submissionViewHolder = (SubmissionViewHolder) firstHolder;
new PopulateSubmissionViewHolder().populateSubmissionViewHolder((SubmissionViewHolder) firstHolder, submission, (Activity) mContext, true, true, null, listView, false, false, null, this);
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (submission.isArchived() || submission.isLocked()) {
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
} else {
firstHolder.itemView.findViewById(R.id.reply).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
doReplySubmission(firstHolder);
}
});
firstHolder.itemView.findViewById(R.id.discard).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
currentlyEditing = null;
editingPosition = -1;
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
}
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
currentlyEditingId = "";
backedText = "";
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
}
} else {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
}
firstHolder.itemView.findViewById(R.id.more).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.menu).callOnClick();
}
});
} else if (firstHolder instanceof MoreCommentViewHolder) {
final MoreCommentViewHolder holder = (MoreCommentViewHolder) firstHolder;
int nextPos = pos - 1;
nextPos = getRealPosition(nextPos);
final MoreChildItem baseNode = (MoreChildItem) currentComments.get(nextPos);
if (baseNode.children.getCount() > 0) {
try {
holder.content.setText(mContext.getString(R.string.comment_load_more_string_new, baseNode.children.getLocalizedCount()));
} catch (Exception e) {
holder.content.setText(R.string.comment_load_more_number_unknown);
}
} else if (!baseNode.children.getChildrenIds().isEmpty()) {
holder.content.setText(R.string.comment_load_more_number_unknown);
} else {
holder.content.setText(R.string.thread_continue);
}
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
for (int i = 1; i < baseNode.comment.getDepth(); i++) {
width += dwidth;
}
final View progress = holder.loading;
progress.setVisibility(View.GONE);
final int finalNextPos = nextPos;
holder.content.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (baseNode.children.getChildrenIds().isEmpty()) {
String toGoTo = "https://reddit.com" + submission.getPermalink() + baseNode.comment.getComment().getId() + "?context=0";
new OpenRedditLink(mContext, toGoTo, true);
} else if (progress.getVisibility() == View.GONE) {
progress.setVisibility(View.VISIBLE);
holder.content.setText(R.string.comment_loading_more);
currentLoading = new AsyncLoadMore(getRealPosition(holder.getAdapterPosition() - 2), holder.getAdapterPosition(), holder, finalNextPos, baseNode.comment.getComment().getFullName());
currentLoading.execute(baseNode);
}
}
});
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
}
if (firstHolder instanceof SpacerViewHolder) {
// Make a space the size of the toolbar minus 1 so there isn't a gap
firstHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (Constants.SINGLE_HEADER_VIEW_OFFSET - Reddit.dpToPxVertical(1) + mPage.shownHeaders)));
}
}
use of net.dean.jraw.models.CommentNode in project Slide by ccrama.
the class CommentAdapterSearch method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int pos) {
final CommentViewHolder holder = (CommentViewHolder) firstHolder;
final CommentNode baseNode = dataSet.get(pos);
final Comment comment = baseNode.getComment();
doScoreText(holder, comment, 0);
if (baseNode.isTopLevel()) {
holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
} else {
holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
}
String body = comment.getDataNode().get("body_html").asText();
if (!search.isEmpty() && StringUtils.isAlphanumericSpace(search)) {
body = body.replaceAll(search, "[[h[" + search + "]h]]");
}
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.firstTextView.setTypeface(typeface);
setViews(body, comment.getSubredditName(), holder);
holder.childrenNumber.setVisibility(View.GONE);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle conData = new Bundle();
conData.putString("fullname", comment.getFullName());
Intent intent = new Intent();
intent.putExtras(conData);
((Activity) mContext).setResult(Activity.RESULT_OK, intent);
((Activity) mContext).finish();
}
});
holder.firstTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle conData = new Bundle();
conData.putString("fullname", comment.getFullName());
Intent intent = new Intent();
intent.putExtras(conData);
((Activity) mContext).setResult(Activity.RESULT_OK, intent);
((Activity) mContext).finish();
}
});
holder.itemView.findViewById(R.id.dot).setVisibility(View.VISIBLE);
if (baseNode.getDepth() - 1 > 0) {
View v = holder.itemView.findViewById(R.id.dot);
int i22 = baseNode.getDepth() - 2;
if (i22 % 5 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
} else if (i22 % 4 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_green_500));
} else if (i22 % 3 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_yellow_500));
} else if (i22 % 2 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
} else {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_red_500));
}
} else {
holder.itemView.findViewById(R.id.dot).setVisibility(View.GONE);
}
}
Aggregations