use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class CommentAdapterSearch method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int pos) {
final CommentViewHolder holder = (CommentViewHolder) firstHolder;
final CommentNode baseNode = dataSet.get(pos);
final Comment comment = baseNode.getComment();
doScoreText(holder, comment, 0);
if (baseNode.isTopLevel()) {
holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
} else {
holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
}
String body = comment.getDataNode().get("body_html").asText();
if (!search.isEmpty() && StringUtils.isAlphanumericSpace(search)) {
body = body.replaceAll(search, "[[h[" + search + "]h]]");
}
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.firstTextView.setTypeface(typeface);
setViews(body, comment.getSubredditName(), holder);
holder.childrenNumber.setVisibility(View.GONE);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle conData = new Bundle();
conData.putString("fullname", comment.getFullName());
Intent intent = new Intent();
intent.putExtras(conData);
((Activity) mContext).setResult(Activity.RESULT_OK, intent);
((Activity) mContext).finish();
}
});
holder.firstTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle conData = new Bundle();
conData.putString("fullname", comment.getFullName());
Intent intent = new Intent();
intent.putExtras(conData);
((Activity) mContext).setResult(Activity.RESULT_OK, intent);
((Activity) mContext).finish();
}
});
holder.itemView.findViewById(R.id.dot).setVisibility(View.VISIBLE);
if (baseNode.getDepth() - 1 > 0) {
View v = holder.itemView.findViewById(R.id.dot);
int i22 = baseNode.getDepth() - 2;
if (i22 % 5 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
} else if (i22 % 4 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_green_500));
} else if (i22 % 3 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_yellow_500));
} else if (i22 % 2 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
} else {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_red_500));
}
} else {
holder.itemView.findViewById(R.id.dot).setVisibility(View.GONE);
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class Shortcut method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
super.onCreate(savedInstanceState);
doShortcut();
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class Tutorial method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
setContentView(R.layout.activity_tutorial);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.vp);
/*
The pager adapter, which provides the pages to the view pager widget.
*/
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
if (getIntent().hasExtra("page")) {
mPager.setCurrentItem(1);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Palette.getDarkerColor(Color.parseColor("#FF5252")));
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class SettingsFont method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_settings_font);
setupAppBar(R.id.toolbar, R.string.settings_title_font, true, true);
final TextView colorComment = (TextView) findViewById(R.id.commentFont);
colorComment.setText(new FontPreferences(this).getCommentFontStyle().getTitle());
findViewById(R.id.commentfontsize).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(SettingsFont.this, v);
popup.getMenu().add(0, R.string.font_size_huge, 0, R.string.font_size_huge);
popup.getMenu().add(0, R.string.font_size_larger, 0, R.string.font_size_larger);
popup.getMenu().add(0, R.string.font_size_large, 0, R.string.font_size_large);
popup.getMenu().add(0, R.string.font_size_medium, 0, R.string.font_size_medium);
popup.getMenu().add(0, R.string.font_size_small, 0, R.string.font_size_small);
popup.getMenu().add(0, R.string.font_size_smaller, 0, R.string.font_size_smaller);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
new FontPreferences(SettingsFont.this).setCommentFontStyle(FontPreferences.FontStyleComment.valueOf(getFontName(item.getItemId())));
colorComment.setText(new FontPreferences(SettingsFont.this).getCommentFontStyle().getTitle());
SettingsTheme.changed = true;
return true;
}
});
popup.show();
}
});
final TextView colorPost = (TextView) findViewById(R.id.postFont);
colorPost.setText(new FontPreferences(this).getPostFontStyle().getTitle());
findViewById(R.id.postfontsize).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(SettingsFont.this, v);
popup.getMenu().add(0, R.string.font_size_huge, 0, R.string.font_size_huge);
popup.getMenu().add(0, R.string.font_size_larger, 0, R.string.font_size_larger);
popup.getMenu().add(0, R.string.font_size_large, 0, R.string.font_size_large);
popup.getMenu().add(0, R.string.font_size_medium, 0, R.string.font_size_medium);
popup.getMenu().add(0, R.string.font_size_small, 0, R.string.font_size_small);
popup.getMenu().add(0, R.string.font_size_smaller, 0, R.string.font_size_smaller);
popup.getMenu().add(0, R.string.font_size_tiny, 0, R.string.font_size_tiny);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
new FontPreferences(SettingsFont.this).setPostFontStyle(FontPreferences.FontStyle.valueOf(getFontName(item.getItemId())));
colorPost.setText(new FontPreferences(SettingsFont.this).getPostFontStyle().getTitle());
SettingsTheme.changed = true;
return true;
}
});
popup.show();
}
});
switch(new FontPreferences(this).getFontTypeComment()) {
case Regular:
((RobotoRadioButton) findViewById(R.id.creg)).setChecked(true);
break;
case Slab:
((RobotoRadioButton) findViewById(R.id.cslab)).setChecked(true);
break;
case Condensed:
((RobotoRadioButton) findViewById(R.id.ccond)).setChecked(true);
break;
case Light:
((RobotoRadioButton) findViewById(R.id.clight)).setChecked(true);
break;
case System:
((RobotoRadioButton) findViewById(R.id.cnone)).setChecked(true);
break;
}
((RobotoRadioButton) findViewById(R.id.ccond)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setCommentFont(FontPreferences.FontTypeComment.Condensed);
}
}
});
((RobotoRadioButton) findViewById(R.id.cslab)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setCommentFont(FontPreferences.FontTypeComment.Slab);
}
}
});
((RobotoRadioButton) findViewById(R.id.creg)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setCommentFont(FontPreferences.FontTypeComment.Regular);
}
}
});
((RobotoRadioButton) findViewById(R.id.clight)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setCommentFont(FontPreferences.FontTypeComment.Light);
}
}
});
((RobotoRadioButton) findViewById(R.id.cnone)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setCommentFont(FontPreferences.FontTypeComment.System);
}
}
});
switch(new FontPreferences(this).getFontTypeTitle()) {
case Regular:
((RobotoRadioButton) findViewById(R.id.sreg)).setChecked(true);
break;
case Light:
((RobotoRadioButton) findViewById(R.id.sregl)).setChecked(true);
break;
case Slab:
((RobotoRadioButton) findViewById(R.id.sslabl)).setChecked(true);
break;
case SlabReg:
((RobotoRadioButton) findViewById(R.id.sslab)).setChecked(true);
break;
case CondensedReg:
((RobotoRadioButton) findViewById(R.id.scond)).setChecked(true);
break;
case CondensedBold:
((RobotoRadioButton) findViewById(R.id.scondb)).setChecked(true);
break;
case Condensed:
((RobotoRadioButton) findViewById(R.id.scondl)).setChecked(true);
break;
case Bold:
((RobotoRadioButton) findViewById(R.id.sbold)).setChecked(true);
break;
case Medium:
((RobotoRadioButton) findViewById(R.id.smed)).setChecked(true);
break;
case System:
((RobotoRadioButton) findViewById(R.id.snone)).setChecked(true);
break;
}
((RobotoRadioButton) findViewById(R.id.scond)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.CondensedReg);
}
}
});
((RobotoRadioButton) findViewById(R.id.sslab)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.SlabReg);
}
}
});
((RobotoRadioButton) findViewById(R.id.scondl)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Condensed);
}
}
});
((RobotoRadioButton) findViewById(R.id.sbold)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Bold);
}
}
});
((RobotoRadioButton) findViewById(R.id.smed)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Medium);
}
}
});
((RobotoRadioButton) findViewById(R.id.sslabl)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Slab);
}
}
});
((RobotoRadioButton) findViewById(R.id.sreg)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Regular);
}
}
});
((RobotoRadioButton) findViewById(R.id.sregl)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.Light);
}
}
});
((RobotoRadioButton) findViewById(R.id.snone)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.System);
}
}
});
((RobotoRadioButton) findViewById(R.id.scondb)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SettingsTheme.changed = true;
new FontPreferences(SettingsFont.this).setTitleFont(FontPreferences.FontTypeTitle.CondensedBold);
}
}
});
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.linktype);
single.setChecked(SettingValues.typeInText);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.typeInText = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_TYPE_IN_TEXT, isChecked).apply();
}
});
}
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.enlarge_links);
single.setChecked(SettingValues.largeLinks);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.largeLinks = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_LARGE_LINKS, isChecked).apply();
}
});
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class PopulateSubmissionViewHolder method populateSubmissionViewHolder.
public <T extends Contribution> void populateSubmissionViewHolder(final SubmissionViewHolder holder, final Submission submission, final Activity mContext, boolean fullscreen, final boolean full, final List<T> posts, final RecyclerView recyclerview, final boolean same, final boolean offline, final String baseSub, @Nullable final CommentAdapter adapter) {
holder.itemView.findViewById(R.id.vote).setVisibility(View.GONE);
if (!offline && UserSubscriptions.modOf != null && submission.getSubredditName() != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
holder.mod.setVisibility(View.VISIBLE);
final Map<String, Integer> reports = submission.getUserReports();
final Map<String, String> reports2 = submission.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
((ImageView) holder.mod).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) holder.mod).setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
}
holder.mod.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showModBottomSheet(mContext, submission, posts, holder, recyclerview, reports, reports2);
}
});
} else {
holder.mod.setVisibility(View.GONE);
}
holder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showBottomSheet(mContext, submission, holder, posts, baseSub, recyclerview, full);
}
});
// Use this to offset the submission score
int submissionScore = submission.getScore();
final int commentCount = submission.getCommentCount();
final int more = LastComments.commentsSince(submission);
holder.comments.setText(String.format(Locale.getDefault(), "%d %s", commentCount, ((more > 0 && SettingValues.commentLastVisit) ? "(+" + more + ")" : "")));
String scoreRatio = (SettingValues.upvotePercentage && full && submission.getUpvoteRatio() != null) ? "(" + (int) (submission.getUpvoteRatio() * 100) + "%)" : "";
if (!scoreRatio.isEmpty()) {
TextView percent = holder.itemView.findViewById(R.id.percent);
percent.setVisibility(View.VISIBLE);
percent.setText(scoreRatio);
final double numb = (submission.getUpvoteRatio());
if (numb <= .5) {
if (numb <= .1) {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
} else if (numb <= .3) {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_400));
} else {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_300));
}
} else {
if (numb >= .9) {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
} else if (numb >= .7) {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_400));
} else {
percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_300));
}
}
}
final ImageView downvotebutton = (ImageView) holder.downvote;
final ImageView upvotebutton = (ImageView) holder.upvote;
if (submission.isArchived()) {
downvotebutton.setVisibility(View.GONE);
upvotebutton.setVisibility(View.GONE);
} else if (Authentication.isLoggedIn && Authentication.didOnline) {
if (SettingValues.actionbarVisible && downvotebutton.getVisibility() != View.VISIBLE) {
downvotebutton.setVisibility(View.VISIBLE);
upvotebutton.setVisibility(View.VISIBLE);
}
}
// Set the colors and styles for the score text depending on what state it is in
switch(ActionStates.getVoteDirection(submission)) {
case UPVOTE:
{
holder.score.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
holder.score.setTypeface(null, Typeface.BOLD);
downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
if (submission.getVote() != VoteDirection.UPVOTE) {
if (submission.getVote() == VoteDirection.DOWNVOTE)
++submissionScore;
// offset the score by +1
++submissionScore;
}
break;
}
case DOWNVOTE:
{
holder.score.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
holder.score.setTypeface(null, Typeface.BOLD);
upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
if (submission.getVote() != VoteDirection.DOWNVOTE) {
if (submission.getVote() == VoteDirection.UPVOTE)
--submissionScore;
// offset the score by +1
--submissionScore;
}
break;
}
case NO_VOTE:
{
holder.score.setTextColor(holder.comments.getCurrentTextColor());
holder.score.setTypeface(null, Typeface.NORMAL);
downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
break;
}
}
// if the submission is already at 0pts, keep it at 0pts
submissionScore = ((submissionScore < 0) ? 0 : submissionScore);
if (submissionScore >= 10000 && SettingValues.abbreviateScores) {
holder.score.setText(String.format(Locale.getDefault(), "%.1fk", (((double) submissionScore) / 1000)));
} else {
holder.score.setText(String.format(Locale.getDefault(), "%d", submissionScore));
}
// Save the score so we can use it in the OnClickListeners for the vote buttons
final int SUBMISSION_SCORE = submissionScore;
final ImageView hideButton = (ImageView) holder.hide;
if (hideButton != null) {
if (SettingValues.hideButton && Authentication.isLoggedIn) {
hideButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideSubmission(submission, posts, baseSub, recyclerview, mContext);
}
});
} else {
hideButton.setVisibility(View.GONE);
}
}
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (ActionStates.isSaved(submission)) {
((ImageView) holder.save).setColorFilter(ContextCompat.getColor(mContext, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) holder.save).setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
}
holder.save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveSubmission(submission, mContext, holder, full);
}
});
}
if (!SettingValues.saveButton && !full || !Authentication.isLoggedIn || !Authentication.didOnline) {
holder.save.setVisibility(View.GONE);
}
ImageView thumbImage2 = ((ImageView) holder.thumbimage);
if (holder.leadImage.thumbImage2 == null) {
holder.leadImage.setThumbnail(thumbImage2);
}
final ContentType.Type type = ContentType.getContentType(submission);
addClickFunctions(holder.leadImage, type, mContext, submission, holder, full);
if (thumbImage2 != null) {
addClickFunctions(thumbImage2, type, mContext, submission, holder, full);
}
if (full) {
addClickFunctions(holder.itemView.findViewById(R.id.wraparea), type, mContext, submission, holder, full);
}
if (full) {
holder.leadImage.setWrapArea(holder.itemView.findViewById(R.id.wraparea));
}
boolean crosspost = submission.getDataNode().has("crosspost_parent_list");
if (full && crosspost) {
holder.itemView.findViewById(R.id.crosspost).setVisibility(View.VISIBLE);
((TextView) holder.itemView.findViewById(R.id.crossinfo)).setText(SubmissionCache.getCrosspostLine(submission, mContext));
((Reddit) mContext.getApplicationContext()).getImageLoader().displayImage(submission.getDataNode().get("crosspost_parent_list").get(0).get("thumbnail").asText(), ((ImageView) holder.itemView.findViewById(R.id.crossthumb)));
holder.itemView.findViewById(R.id.crosspost).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, submission.getDataNode().get("crosspost_parent_list").get(0).get("permalink").asText(), true);
}
});
}
holder.leadImage.setSubmission(submission, full, baseSub, type);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (offline) {
Snackbar s = Snackbar.make(holder.itemView, mContext.getString(R.string.offline_msg), Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
} else {
if (SettingValues.actionbarTap && !full) {
CreateCardView.toggleActionbar(holder.itemView);
} else {
holder.itemView.findViewById(R.id.menu).callOnClick();
}
}
return true;
}
});
doText(holder, submission, mContext, baseSub, full);
if (!full && SettingValues.isSelftextEnabled(baseSub) && submission.isSelfPost() && !submission.getSelftext().isEmpty() && !submission.isNsfw() && !submission.getDataNode().get("spoiler").asBoolean() && !submission.getDataNode().get("selftext_html").asText().trim().isEmpty()) {
holder.body.setVisibility(View.VISIBLE);
String text = submission.getDataNode().get("selftext_html").asText();
int typef = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (typef >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, typef);
} else {
typeface = Typeface.DEFAULT;
}
holder.body.setTypeface(typeface);
holder.body.setTextHtml(Html.fromHtml(text.substring(0, text.contains("\n") ? text.indexOf("\n") : text.length())).toString().replace("<sup>", "<sup><small>").replace("</sup>", "</small></sup>"), "none ");
holder.body.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.itemView.callOnClick();
}
});
holder.body.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.menu.callOnClick();
return true;
}
});
} else if (!full) {
holder.body.setVisibility(View.GONE);
}
if (full) {
if (!submission.getSelftext().isEmpty()) {
int typef = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (typef >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, typef);
} else {
typeface = Typeface.DEFAULT;
}
holder.firstTextView.setTypeface(typeface);
setViews(submission.getDataNode().get("selftext_html").asText(), submission.getSubredditName() == null ? "all" : submission.getSubredditName(), holder);
holder.itemView.findViewById(R.id.body_area).setVisibility(View.VISIBLE);
} else {
holder.itemView.findViewById(R.id.body_area).setVisibility(View.GONE);
}
}
try {
final TextView points = holder.score;
final TextView comments = holder.comments;
if (Authentication.isLoggedIn && !offline && Authentication.didOnline) {
{
downvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (SettingValues.storeHistory && !full) {
if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
HasSeen.addSeen(submission.getFullName());
if (mContext instanceof MainActivity) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
}
}
}
if (ActionStates.getVoteDirection(submission) != VoteDirection.DOWNVOTE) {
// has not been downvoted
points.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(holder.itemView, downvotebutton, ContextCompat.getColor(mContext, R.color.md_blue_500));
holder.score.setTypeface(null, Typeface.BOLD);
final int DOWNVOTE_SCORE = (SUBMISSION_SCORE == 0) ? 0 : SUBMISSION_SCORE - // if a post is at 0 votes, keep it at 0 when downvoting
1;
new Vote(false, points, mContext).execute(submission);
ActionStates.setVoteDirection(submission, VoteDirection.DOWNVOTE);
setSubmissionScoreText(submission, holder);
} else {
// un-downvoted a post
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, mContext).execute(submission);
holder.score.setTypeface(null, Typeface.NORMAL);
ActionStates.setVoteDirection(submission, VoteDirection.NO_VOTE);
downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
setSubmissionScoreText(submission, holder);
}
if (!full && !SettingValues.actionbarVisible && SettingValues.defaultCardView != CreateCardView.CardEnum.DESKTOP) {
CreateCardView.toggleActionbar(holder.itemView);
}
}
});
}
{
upvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (SettingValues.storeHistory && !full) {
if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
HasSeen.addSeen(submission.getFullName());
if (mContext instanceof MainActivity) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
}
}
}
if (ActionStates.getVoteDirection(submission) != VoteDirection.UPVOTE) {
// has not been upvoted
points.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(holder.itemView, upvotebutton, ContextCompat.getColor(mContext, R.color.md_orange_500));
holder.score.setTypeface(null, Typeface.BOLD);
new Vote(true, points, mContext).execute(submission);
ActionStates.setVoteDirection(submission, VoteDirection.UPVOTE);
setSubmissionScoreText(submission, holder);
} else {
// un-upvoted a post
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, mContext).execute(submission);
holder.score.setTypeface(null, Typeface.NORMAL);
ActionStates.setVoteDirection(submission, VoteDirection.NO_VOTE);
upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
setSubmissionScoreText(submission, holder);
}
if (!full && !SettingValues.actionbarVisible && SettingValues.defaultCardView != CreateCardView.CardEnum.DESKTOP) {
CreateCardView.toggleActionbar(holder.itemView);
}
}
});
}
} else {
upvotebutton.setVisibility(View.GONE);
downvotebutton.setVisibility(View.GONE);
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
final View edit = holder.edit;
if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(submission.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
edit.setVisibility(View.VISIBLE);
edit.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
new AsyncTask<Void, Void, ArrayList<String>>() {
List<FlairTemplate> flairlist;
@Override
protected ArrayList<String> doInBackground(Void... params) {
FlairReference allFlairs = new FluentRedditClient(Authentication.reddit).subreddit(submission.getSubredditName()).flair();
try {
flairlist = allFlairs.options(submission);
final ArrayList<String> finalFlairs = new ArrayList<>();
for (FlairTemplate temp : flairlist) {
finalFlairs.add(temp.getText());
}
return finalFlairs;
} catch (Exception e) {
e.printStackTrace();
// sub probably has no flairs?
}
return null;
}
@Override
public void onPostExecute(final ArrayList<String> data) {
final boolean flair = (data != null && !data.isEmpty());
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
final int color2 = ta.getColor(0, Color.WHITE);
Drawable edit_drawable = mContext.getResources().getDrawable(R.drawable.edit);
Drawable nsfw_drawable = mContext.getResources().getDrawable(R.drawable.hide);
Drawable delete_drawable = mContext.getResources().getDrawable(R.drawable.delete);
Drawable flair_drawable = mContext.getResources().getDrawable(R.drawable.fontsizedarker);
edit_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
nsfw_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
delete_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
flair_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
if (submission.isSelfPost()) {
b.sheet(1, edit_drawable, mContext.getString(R.string.edit_selftext));
}
if (submission.isNsfw()) {
b.sheet(4, nsfw_drawable, mContext.getString(R.string.mod_btn_unmark_nsfw));
} else {
b.sheet(4, nsfw_drawable, mContext.getString(R.string.mod_btn_mark_nsfw));
}
b.sheet(2, delete_drawable, mContext.getString(R.string.delete_submission));
if (flair) {
b.sheet(3, flair_drawable, mContext.getString(R.string.set_submission_flair));
}
b.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 1:
{
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.edit_comment, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
final EditText e = dialoglayout.findViewById(R.id.entry);
e.setText(StringEscapeUtils.unescapeHtml4(submission.getSelftext()));
DoEditorActions.doActions(e, dialoglayout, ((AppCompatActivity) mContext).getSupportFragmentManager(), mContext, null, null);
builder.setCancelable(false).setView(dialoglayout);
final Dialog d = builder.create();
d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
d.show();
dialoglayout.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String text = e.getText().toString();
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
new AccountManager(Authentication.reddit).updateContribution(submission, text);
if (adapter != null) {
adapter.dataSet.reloadSubmission(adapter);
}
d.dismiss();
} catch (Exception e) {
(mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.comment_delete_err).setMessage(R.string.comment_delete_err_msg).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
doInBackground();
}
}).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (adapter != null) {
adapter.notifyItemChanged(1);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
}
break;
case 2:
{
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.really_delete_submission).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
new ModerationManager(Authentication.reddit).delete(submission);
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
(mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
(holder.title).setTextHtml(mContext.getString(R.string.content_deleted));
if (holder.firstTextView != null) {
holder.firstTextView.setText(R.string.content_deleted);
holder.commentOverflow.setVisibility(View.GONE);
} else {
if (holder.itemView.findViewById(R.id.body) != null) {
((TextView) holder.itemView.findViewById(R.id.body)).setText(R.string.content_deleted);
}
}
}
});
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}).setNegativeButton(R.string.btn_cancel, null).show();
}
break;
case 3:
{
new MaterialDialog.Builder(mContext).items(data).title(R.string.sidebar_select_flair).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
final FlairTemplate t = flairlist.get(which);
if (t.isTextEditable()) {
new MaterialDialog.Builder(mContext).title(R.string.mod_btn_submission_flair_text).input(mContext.getString(R.string.mod_flair_hint), t.getText(), true, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
}
}).positiveText(R.string.btn_set).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
final String flair = dialog.getInputEditText().getText().toString();
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
new ModerationManager(Authentication.reddit).setFlair(submission.getSubredditName(), t, flair, submission);
return true;
} catch (ApiException e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s = null;
if (done) {
if (holder.itemView != null) {
s = Snackbar.make(holder.itemView, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
SubmissionCache.updateTitleFlair(submission, flair, mContext);
holder.title.setText(SubmissionCache.getTitleLine(submission, mContext));
}
} else {
if (holder.itemView != null) {
s = Snackbar.make(holder.itemView, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
}
if (s != null) {
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}).negativeText(R.string.btn_cancel).show();
} else {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
new ModerationManager(Authentication.reddit).setFlair(submission.getSubredditName(), t, null, submission);
return true;
} catch (ApiException e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s = null;
if (done) {
if (holder.itemView != null) {
s = Snackbar.make(holder.itemView, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
SubmissionCache.updateTitleFlair(submission, t.getCssClass(), mContext);
holder.title.setText(SubmissionCache.getTitleLine(submission, mContext));
}
} else {
if (holder.itemView != null) {
s = Snackbar.make(holder.itemView, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
}
if (s != null) {
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}).show();
}
break;
case 4:
if (submission.isNsfw()) {
unNsfwSubmission(mContext, submission, holder);
} else {
setPostNsfw(mContext, submission, holder);
}
break;
}
}
}).show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {
edit.setVisibility(View.GONE);
}
if (HasSeen.getSeen(submission) && !full) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
} else {
holder.title.setAlpha(1f);
if (!full) {
holder.body.setAlpha(1f);
}
}
}
Aggregations