use of net.dean.jraw.models.PublicContribution 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()));
}
}
Aggregations