use of me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder in project Slide by ccrama.
the class ModeratorAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHold instanceof SubmissionViewHolder) {
SubmissionViewHolder holder = (SubmissionViewHolder) firstHold;
final Submission submission = (Submission) dataSet.posts.get(i);
CreateCardView.resetColorCard(holder.itemView);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
title.setText(Html.fromHtml(submission.getTitle()));
((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
} else {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
new AsyncSave(firstHold.itemView).execute(submission);
}
});
dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlString = "https://reddit.com" + submission.getPermalink();
Intent i = new Intent(mContext, Website.class);
i.putExtra(Website.EXTRA_URL, urlString);
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSelfPost()) {
if (SettingValues.shareLongLink) {
Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
}
} else {
new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case R.id.reddit_url:
if (SettingValues.shareLongLink) {
Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
}
break;
case R.id.link_url:
Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
break;
}
}
}).show();
}
}
});
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
}
title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
builder.setView(dialoglayout);
final Dialog d = builder.show();
dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
d.dismiss();
Hidden.setHidden(old);
Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.posts.add(pos, (PublicContribution) old);
notifyItemInserted(pos + 1);
Hidden.undoHidden(old);
}
});
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
});
return true;
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
if (hideButton != null) {
hideButton.setVisibility(View.GONE);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "www.reddit.com" + submission.getPermalink();
url = url.replace("?ref=search_posts", "");
new OpenRedditLink(mContext, url);
}
});
} else if (firstHold instanceof ProfileCommentViewHolder) {
// IS COMMENT
final ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHold;
final Comment comment = (Comment) dataSet.posts.get(i);
holder.score.setText(comment.getScore() + " " + mContext.getResources().getQuantityString(R.plurals.points, comment.getScore()));
if (Authentication.isLoggedIn) {
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
} else {
holder.score.setTextColor(holder.time.getCurrentTextColor());
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
// some users were crashing here
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(time);
titleString.append(spacer);
{
final ImageView mod = (ImageView) holder.itemView.findViewById(R.id.mod);
try {
if (UserSubscriptions.modOf.contains(comment.getSubredditName())) {
// todo
mod.setVisibility(View.GONE);
} else {
mod.setVisibility(View.GONE);
}
} catch (Exception e) {
Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
}
}
if ((UserSubscriptions.modOf != null) && UserSubscriptions.modOf.contains(comment.getSubredditName().toLowerCase(Locale.ENGLISH))) {
holder.itemView.findViewById(R.id.mod).setVisibility(View.VISIBLE);
final Map<String, Integer> reports = comment.getUserReports();
final Map<String, String> reports2 = comment.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
((ImageView) holder.itemView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
} else {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
((ImageView) holder.itemView.findViewById(R.id.mod)).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
}
holder.itemView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
showModBottomSheet(mContext, comment, holder, reports, reports2);
}
});
} else {
holder.itemView.findViewById(R.id.mod).setVisibility(View.GONE);
}
if (comment.getSubredditName() != null) {
String subname = comment.getSubredditName();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
holder.time.setText(titleString);
setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
if (comment.getTimesGilded() > 0) {
holder.gild.setVisibility(View.VISIBLE);
((TextView) holder.gild).setText(Integer.toString(comment.getTimesGilded()));
} else if (holder.gild.getVisibility() == View.VISIBLE)
holder.gild.setVisibility(View.GONE);
if (comment.getSubmissionTitle() != null)
holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
else
holder.title.setText(Html.fromHtml(comment.getAuthor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
holder.content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
}
if (firstHold instanceof SpacerViewHolder) {
firstHold.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(firstHold.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
}
}
use of me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder in project Slide by ccrama.
the class SubmissionAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (holder2 instanceof SubmissionViewHolder) {
final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
final Submission submission = dataSet.posts.get(i);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
holder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (Authentication.didOnline || submission.getComments() != null) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
if (context instanceof MainActivity) {
final MainActivity a = (MainActivity) context;
if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.toOpenComments = a.pager.getCurrentItem() + 1;
a.currentComment = holder.getAdapterPosition() - 1;
((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
try {
a.adapter.notifyDataSetChanged();
} catch (Exception ignored) {
}
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
} else if (context instanceof SubredditView) {
final SubredditView a = (SubredditView) context;
if (a.singleMode && a.commentPager) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.currentComment = holder.getAdapterPosition() - 1;
((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
a.adapter.notifyDataSetChanged();
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
}
} else {
if (!Reddit.appRestart.contains("offlinepopup")) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
} else {
Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
s.setAction(R.string.misc_more_info, new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
}
});
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
}
if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((SubmissionsView) displayer).forceRefresh();
}
});
}
}
if (holder2 instanceof SpacerViewHolder) {
View header = (context).findViewById(R.id.header);
int height = header.getHeight();
if (height == 0) {
header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
height = header.getMeasuredHeight();
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
} else {
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
}
}
}
use of me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder in project Slide by ccrama.
the class ContributionAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHolder instanceof SubmissionViewHolder) {
final SubmissionViewHolder holder = (SubmissionViewHolder) firstHolder;
final Submission submission = (Submission) dataSet.posts.get(i);
CreateCardView.resetColorCard(holder.itemView);
if (submission.getSubredditName() != null)
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
title.setText(Html.fromHtml(submission.getTitle()));
((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
} else {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
new AsyncSave(firstHolder.itemView).execute(submission);
}
});
dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlString = "https://reddit.com" + submission.getPermalink();
Intent i = new Intent(mContext, Website.class);
i.putExtra(Website.EXTRA_URL, urlString);
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSelfPost()) {
if (SettingValues.shareLongLink) {
Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
}
} else {
new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case R.id.reddit_url:
if (SettingValues.shareLongLink) {
Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
}
break;
case R.id.link_url:
Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
break;
}
}
}).show();
}
}
});
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
}
title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
builder.setView(dialoglayout);
final Dialog d = builder.show();
dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
d.dismiss();
Hidden.setHidden(old);
Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.posts.add(pos, old);
notifyItemInserted(pos + 1);
Hidden.undoHidden(old);
}
});
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
});
return true;
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
if (hideButton != null && isHiddenPost) {
hideButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
Hidden.undoHidden(old);
}
});
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "www.reddit.com" + submission.getPermalink();
url = url.replace("?ref=search_posts", "");
new OpenRedditLink(mContext, url);
if (SettingValues.storeHistory) {
if (SettingValues.storeNSFWHistory && submission.isNsfw() || !submission.isNsfw())
HasSeen.addSeen(submission.getFullName());
}
notifyItemChanged(pos);
}
});
} else if (firstHolder instanceof ProfileCommentViewHolder) {
// IS COMMENT
ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHolder;
final Comment comment = (Comment) dataSet.posts.get(i);
String scoreText;
if (comment.isScoreHidden()) {
scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
} else {
scoreText = String.format(Locale.getDefault(), "%d", comment.getScore());
}
SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
if (score == null || score.toString().isEmpty()) {
score = new SpannableStringBuilder("0");
}
if (!scoreText.contains("[")) {
score.append(String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.points, comment.getScore())));
}
holder.score.setText(score);
if (Authentication.isLoggedIn) {
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
} else {
holder.score.setTextColor(holder.time.getCurrentTextColor());
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
// some users were crashing here
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(time);
titleString.append(spacer);
if (comment.getSubredditName() != null) {
String subname = comment.getSubredditName();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
holder.time.setText(titleString);
setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.content.setTypeface(typeface);
if (comment.getTimesGilded() > 0) {
final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
a.recycle();
Bitmap image = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gold);
float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
gilded.setSpan(new ImageSpan(mContext, image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.gild.setVisibility(View.VISIBLE);
((TextView) holder.gild).setText(gilded);
} else if (holder.gild.getVisibility() == View.VISIBLE)
holder.gild.setVisibility(View.GONE);
if (comment.getSubmissionTitle() != null)
holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
else
holder.title.setText(Html.fromHtml(comment.getAuthor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
holder.content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
} else if (firstHolder instanceof SpacerViewHolder) {
firstHolder.itemView.setLayoutParams(new LinearLayout.LayoutParams(firstHolder.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.findViewById(R.id.header).getHeight());
layoutParams.setFullSpan(true);
firstHolder.itemView.setLayoutParams(layoutParams);
}
}
}
use of me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder 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 me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder in project Slide by ccrama.
the class MultiredditAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = (pos != 0) ? (pos - 1) : pos;
if (holder2 instanceof SubmissionViewHolder) {
final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
final Submission submission = dataSet.posts.get(i);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "multi" + dataSet.multiReddit.getDisplayName(), true);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (Authentication.didOnline || submission.getComments() != null) {
holder.title.setAlpha(0.65f);
holder.leadImage.setAlpha(0.65f);
holder.thumbimage.setAlpha(0.65f);
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_MULTIREDDIT, dataSet.multiReddit.getDisplayName());
context.startActivityForResult(i2, 940);
i2.putExtra("fullname", submission.getFullName());
clicked = holder2.getAdapterPosition();
} else {
Snackbar s = Snackbar.make(holder.itemView, R.string.offline_comments_not_loaded, Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
});
final boolean saved = submission.isSaved();
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, true, false, "multi" + dataSet.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), null);
}
if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
// the loading spinner to replaced by nomoreposts.xml
notifyItemChanged(dataSet.posts.size() + 1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.loadMore(context, baseView, true, MultiredditAdapter.this);
}
});
}
}
if (holder2 instanceof SpacerViewHolder) {
final int height = (context).findViewById(R.id.header).getHeight();
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
}
}
Aggregations