use of net.dean.jraw.models.Comment in project Slide by ccrama.
the class CommentAdapter method setCommentStateHighlighted.
public void setCommentStateHighlighted(final CommentViewHolder holder, final Comment n, final CommentNode baseNode, boolean isReplying, boolean animate) {
if (currentlySelected != null && currentlySelected != holder) {
setCommentStateUnhighlighted(currentlySelected, currentBaseNode, true);
}
if (mContext instanceof BaseActivity) {
((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink() + n.getFullName() + "?context=3");
}
// and expand to show all children comments
if (SettingValues.swap && holder.firstTextView.getVisibility() == View.GONE && !isReplying) {
hiddenPersons.remove(n.getFullName());
unhideAll(baseNode, holder.getAdapterPosition() + 1);
if (toCollapse.contains(n.getFullName()) && SettingValues.collapseComments) {
setViews(n.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder);
}
CommentAdapterHelper.hideChildrenObject(holder.childrenNumber);
holder.commentOverflow.setVisibility(View.VISIBLE);
toCollapse.remove(n.getFullName());
} else {
currentlySelected = holder;
currentBaseNode = baseNode;
int color = Palette.getColor(n.getSubredditName());
currentSelectedItem = n.getFullName();
currentNode = baseNode;
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
resetMenu(holder.menuArea, false);
final View baseView = (SettingValues.rightHandedCommentMenu) ? inflater.inflate(R.layout.comment_menu_right_handed, holder.menuArea) : inflater.inflate(R.layout.comment_menu, holder.menuArea);
if (!isReplying) {
baseView.setVisibility(View.GONE);
if (animate) {
expand(baseView);
} else {
baseView.setVisibility(View.VISIBLE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
baseView.measure(widthSpec, heightSpec);
View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
l2.measure(widthSpec2, heightSpec2);
ViewGroup.LayoutParams layoutParams = baseView.getLayoutParams();
layoutParams.height = baseView.getMeasuredHeight() - l2.getMeasuredHeight();
baseView.setLayoutParams(layoutParams);
}
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
holder.itemView.setLayoutParams(params);
View reply = baseView.findViewById(R.id.reply);
View send = baseView.findViewById(R.id.send);
final View menu = baseView.findViewById(R.id.menu);
final View replyArea = baseView.findViewById(R.id.replyArea);
final View more = baseView.findViewById(R.id.more);
final ImageView upvote = (ImageView) baseView.findViewById(R.id.upvote);
final ImageView downvote = (ImageView) baseView.findViewById(R.id.downvote);
View discard = baseView.findViewById(R.id.discard);
final EditText replyLine = (EditText) baseView.findViewById(R.id.replyLine);
final Comment comment = baseNode.getComment();
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
} else {
downvote.clearColorFilter();
upvote.clearColorFilter();
}
{
final ImageView mod = (ImageView) baseView.findViewById(R.id.mod);
try {
if (UserSubscriptions.modOf.contains(submission.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(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
baseView.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) baseView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
baseView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
}
});
} else {
baseView.findViewById(R.id.mod).setVisibility(View.GONE);
}
final ImageView edit = (ImageView) baseView.findViewById(R.id.edit);
if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
edit.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.doCommentEdit(CommentAdapter.this, mContext, fm, baseNode, baseNode.isTopLevel() ? submission.getSelftext() : baseNode.getParent().getComment().getBody(), holder);
}
});
} else {
edit.setVisibility(View.GONE);
}
final ImageView delete = (ImageView) baseView.findViewById(R.id.delete);
if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
delete.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.deleteComment(CommentAdapter.this, mContext, baseNode, holder);
}
});
} else {
delete.setVisibility(View.GONE);
}
if (Authentication.isLoggedIn && !submission.isArchived() && !submission.isLocked() && !deleted.contains(n.getFullName()) && !comment.getAuthor().equals("[deleted]") && Authentication.didOnline) {
if (isReplying) {
baseView.setVisibility(View.VISIBLE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
baseView.measure(widthSpec, heightSpec);
View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
l2.measure(widthSpec2, heightSpec2);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) baseView.getLayoutParams();
params2.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
params2.addRule(RelativeLayout.BELOW, R.id.commentOverflow);
baseView.setLayoutParams(params2);
replyArea.setVisibility(View.VISIBLE);
menu.setVisibility(View.GONE);
currentlyEditing = replyLine;
currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mPage.fastScroll.setVisibility(View.GONE);
if (mPage.fab != null) {
mPage.fab.setVisibility(View.GONE);
}
mPage.overrideFab = true;
} else if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null) {
mPage.fab.setVisibility(View.VISIBLE);
}
mPage.overrideFab = false;
}
}
});
final TextView profile = (TextView) baseView.findViewById(R.id.profile);
changedProfile = Authentication.name;
profile.setText("/u/" + changedProfile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final int i = keys.indexOf(changedProfile);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}
});
builder.alwaysCallSingleChoiceCallback();
builder.setNegativeButton(R.string.btn_cancel, null);
builder.show();
}
});
replyLine.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.setText(backedText);
replyLine.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
editingPosition = holder.getAdapterPosition();
}
reply.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
expandAndSetParams(baseView);
// If the base theme is Light or Sepia, tint the Editor actions to be white
if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
((ImageView) replyArea.findViewById(R.id.savedraft)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.draft)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.imagerep)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.link)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.bold)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.italics)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.bulletlist)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.numlist)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.draw)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.quote)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.size)).setColorFilter(Color.WHITE);
((ImageView) replyArea.findViewById(R.id.strike)).setColorFilter(Color.WHITE);
((TextView) replyArea.findViewById(R.id.author)).setTextColor(Color.WHITE);
replyLine.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
}
replyArea.setVisibility(View.VISIBLE);
menu.setVisibility(View.GONE);
currentlyEditing = replyLine;
DoEditorActions.doActions(currentlyEditing, replyArea, fm, (Activity) mContext, comment.getBody(), getParents(baseNode));
currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mPage.fastScroll.setVisibility(View.GONE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.GONE);
mPage.overrideFab = true;
} else if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
}
}
});
final TextView profile = (TextView) baseView.findViewById(R.id.profile);
changedProfile = Authentication.name;
profile.setText("/u/" + changedProfile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final int i = keys.indexOf(changedProfile);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = keys.get(which);
profile.setText("/u/" + changedProfile);
}
});
builder.alwaysCallSingleChoiceCallback();
builder.setNegativeButton(R.string.btn_cancel, null);
builder.show();
}
});
replyLine.requestFocus();
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
currentlyEditingId = n.getFullName();
replyLine.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
backedText = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
editingPosition = holder.getAdapterPosition();
}
});
send.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
currentlyEditingId = "";
backedText = "";
doShowMenu(baseView);
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
}
dataSet.refreshLayout.setRefreshing(true);
if (currentlyEditing != null) {
String text = currentlyEditing.getText().toString();
new ReplyTaskComment(n, baseNode, holder, changedProfile).execute(text);
currentlyEditing = null;
editingPosition = -1;
}
// Hide soft keyboard
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
discard.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
currentlyEditing = null;
editingPosition = -1;
currentlyEditingId = "";
backedText = "";
mPage.overrideFab = false;
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
doShowMenu(baseView);
}
});
} else {
if (reply.getVisibility() == View.VISIBLE) {
reply.setVisibility(View.GONE);
}
if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && upvote.getVisibility() == View.VISIBLE) {
upvote.setVisibility(View.GONE);
}
if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && downvote.getVisibility() == View.VISIBLE) {
downvote.setVisibility(View.GONE);
}
}
more.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
CommentAdapterHelper.showOverflowBottomSheet(CommentAdapter.this, mContext, holder, baseNode);
}
});
upvote.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
setCommentStateUnhighlighted(holder, comment, baseNode, true);
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
new Vote(v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
doScoreText(holder, n, CommentAdapter.this);
upvote.clearColorFilter();
} else {
new Vote(true, v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.UPVOTE);
// reset colour
downvote.clearColorFilter();
doScoreText(holder, n, CommentAdapter.this);
upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
}
}
});
downvote.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
setCommentStateUnhighlighted(holder, comment, baseNode, true);
if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
new Vote(v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
doScoreText(holder, n, CommentAdapter.this);
downvote.clearColorFilter();
} else {
new Vote(false, v, mContext).execute(n);
ActionStates.setVoteDirection(comment, VoteDirection.DOWNVOTE);
// reset colour
upvote.clearColorFilter();
doScoreText(holder, n, CommentAdapter.this);
downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
}
}
});
menu.setBackgroundColor(color);
replyArea.setBackgroundColor(color);
if (!isReplying) {
menu.setVisibility(View.VISIBLE);
replyArea.setVisibility(View.GONE);
}
holder.itemView.findViewById(R.id.background).setBackgroundColor(Color.argb(50, Color.red(color), Color.green(color), Color.blue(color)));
}
}
use of net.dean.jraw.models.Comment in project Slide by ccrama.
the class CommentAdapterHelper method viewCommentParent.
private static void viewCommentParent(CommentAdapter adapter, CommentViewHolder holder, Context mContext, CommentNode baseNode) {
int old = holder.getAdapterPosition();
int pos = (old < 2) ? 0 : old - 1;
for (int i = pos - 1; i >= 0; i--) {
CommentObject o = adapter.currentComments.get(adapter.getRealPosition(i));
if (o instanceof CommentItem && pos - 1 != i && o.comment.getDepth() < baseNode.getDepth()) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
Comment parent = o.comment.getComment();
adapter.setViews(parent.getDataNode().get("body_html").asText(), adapter.submission.getSubredditName(), (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
builder.setView(dialoglayout);
builder.show();
break;
}
}
}
use of net.dean.jraw.models.Comment 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 net.dean.jraw.models.Comment 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 net.dean.jraw.models.Comment in project Slide by ccrama.
the class AlbumFullComments method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.submission_albumcard, container, false);
PopulateShadowboxInfo.doActionbar(s.comment, rootView, getActivity(), true);
String url = s.url;
if (url.contains("gallery")) {
gallery = true;
}
list = rootView.findViewById(R.id.images);
list.setVisibility(View.VISIBLE);
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
((RecyclerView) list).setLayoutManager(layoutManager);
((RecyclerView) list).setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
ValueAnimator va = null;
if (dy > 0 && !hidden) {
hidden = true;
if (va != null && va.isRunning())
va.cancel();
final View base = rootView.findViewById(R.id.base);
va = ValueAnimator.ofFloat(1.0f, 0.2f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
} else if (hidden && dy <= 0) {
final View base = rootView.findViewById(R.id.base);
if (va != null && va.isRunning())
va.cancel();
hidden = false;
va = ValueAnimator.ofFloat(0.2f, 1.0f);
// in millis
int mDuration = 250;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
base.setAlpha(value);
}
});
va.start();
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
final View.OnClickListener openClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
};
rootView.findViewById(R.id.base).setOnClickListener(openClick);
final View title = rootView.findViewById(R.id.title);
title.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelHeight(title.getMeasuredHeight());
title.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
}
@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
final Comment c = s.comment.getComment();
rootView.findViewById(R.id.base).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://reddit.com" + "/r/" + c.getSubredditName() + "/comments/" + c.getDataNode().get("link_id").asText().substring(3, c.getDataNode().get("link_id").asText().length()) + "/nothing/" + c.getId() + "?context=3";
new OpenRedditLink(getActivity(), url);
}
});
} else {
rootView.findViewById(R.id.base).setOnClickListener(openClick);
}
}
});
new LoadIntoRecycler(url, getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return rootView;
}
Aggregations