use of me.ccrama.redditslide.Activities.MainActivity in project Slide by ccrama.
the class PopulateNewsViewHolder method showBottomSheet.
public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final NewsViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.profile, null);
final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.sub, null);
Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null);
Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null);
final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.report, null);
Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.save, null);
Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.openexternal, null);
Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.link, null);
Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null);
Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.filter, null);
profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
sub.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
saved.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
link.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
readLater.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
filter.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
final boolean isReadLater = mContext instanceof PostReadLater;
final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
if (Authentication.didOnline) {
b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
String save = mContext.getString(R.string.btn_save);
if (ActionStates.isSaved(submission)) {
save = mContext.getString(R.string.comment_unsave);
}
if (Authentication.isLoggedIn) {
b.sheet(3, saved, save);
}
}
if (isAddedToReadLaterList) {
b.sheet(28, readLater, "Mark As Read");
} else {
b.sheet(28, readLater, "Read later");
}
if (Authentication.didOnline) {
if (Authentication.isLoggedIn) {
b.sheet(12, report, mContext.getString(R.string.btn_report));
}
}
if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
}
boolean hidden = submission.isHidden();
if (!full && Authentication.didOnline) {
if (!hidden) {
b.sheet(5, hide, mContext.getString(R.string.submission_hide));
} else {
b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
}
}
b.sheet(7, open, mContext.getString(R.string.submission_link_extern));
b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
b.sheet(10, filter, mContext.getString(R.string.filter_content));
}
b.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 1:
{
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
break;
case 2:
{
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivityForResult(i, 14);
}
break;
case 10:
String[] choices;
final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
if (flair.isEmpty()) {
choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
oldChosen = chosen.clone();
} else {
choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
}
;
chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(baseSub + ":" + flair) };
oldChosen = chosen.clone();
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.filter_title).alwaysCallMultiChoiceCallback().setMultiChoiceItems(choices, chosen, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
chosen[which] = isChecked;
}
}).setPositiveButton(R.string.filter_btn, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean filtered = false;
SharedPreferences.Editor e = SettingValues.prefs.edit();
if (chosen[0] && chosen[0] != oldChosen[0]) {
SettingValues.subredditFilters = SettingValues.subredditFilters + ((SettingValues.subredditFilters.isEmpty() || SettingValues.subredditFilters.endsWith(",")) ? "" : ",") + submission.getSubredditName();
filtered = true;
e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
PostMatch.subreddits = null;
} else if (!chosen[0] && chosen[0] != oldChosen[0]) {
SettingValues.subredditFilters = SettingValues.subredditFilters.replace(submission.getSubredditName(), "");
filtered = false;
e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
e.apply();
PostMatch.subreddits = null;
}
if (chosen[1] && chosen[1] != oldChosen[1]) {
SettingValues.userFilters = SettingValues.userFilters + ((SettingValues.userFilters.isEmpty() || SettingValues.userFilters.endsWith(",")) ? "" : ",") + submission.getAuthor();
filtered = true;
e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
PostMatch.users = null;
} else if (!chosen[1] && chosen[1] != oldChosen[1]) {
SettingValues.userFilters = SettingValues.userFilters.replace(submission.getAuthor(), "");
filtered = false;
e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
e.apply();
PostMatch.users = null;
}
if (chosen[2] && chosen[2] != oldChosen[2]) {
SettingValues.domainFilters = SettingValues.domainFilters + ((SettingValues.domainFilters.isEmpty() || SettingValues.domainFilters.endsWith(",")) ? "" : ",") + submission.getDomain();
filtered = true;
e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
PostMatch.domains = null;
} else if (!chosen[2] && chosen[2] != oldChosen[2]) {
SettingValues.domainFilters = SettingValues.domainFilters.replace(submission.getDomain(), "");
filtered = false;
e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
e.apply();
PostMatch.domains = null;
}
if (chosen[3] && chosen[3] != oldChosen[3]) {
SettingValues.alwaysExternal = SettingValues.alwaysExternal + ((SettingValues.alwaysExternal.isEmpty() || SettingValues.alwaysExternal.endsWith(",")) ? "" : ",") + submission.getDomain();
e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
e.apply();
} else if (!chosen[3] && chosen[3] != oldChosen[3]) {
SettingValues.alwaysExternal = SettingValues.alwaysExternal.replace(submission.getDomain(), "");
e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
e.apply();
}
if (chosen.length > 4) {
if (chosen[4] && chosen[4] != oldChosen[4]) {
SettingValues.flairFilters = SettingValues.flairFilters + ((SettingValues.flairFilters.isEmpty() || SettingValues.flairFilters.endsWith(",")) ? "" : ",") + (baseSub + ":" + flair);
e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
e.apply();
PostMatch.flairs = null;
filtered = true;
} else if (!chosen[4] && chosen[4] != oldChosen[4]) {
SettingValues.flairFilters = SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).replace((baseSub + ":" + flair).toLowerCase(Locale.ENGLISH), "");
e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
e.apply();
PostMatch.flairs = null;
}
}
if (filtered) {
e.apply();
PostMatch.domains = null;
PostMatch.subreddits = null;
PostMatch.users = null;
ArrayList<Contribution> toRemove = new ArrayList<>();
for (Contribution s : posts) {
if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
toRemove.add(s);
}
}
OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
for (Contribution remove : toRemove) {
final int pos = posts.indexOf(remove);
posts.remove(pos);
if (baseSub != null) {
s.hideMulti(pos);
}
}
s.writeToMemoryNoStorage();
recyclerview.getAdapter().notifyDataSetChanged();
}
}
}).setNegativeButton(R.string.btn_cancel, null).show();
break;
case 5:
{
hideSubmission(submission, posts, baseSub, recyclerview, mContext);
}
break;
case 7:
LinkUtil.openExternally(submission.getUrl(), mContext);
if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
// Do nothing if the post is NSFW and storeNSFWHistory is not enabled
} else if (SettingValues.storeHistory) {
HasSeen.addSeen(submission.getFullName());
}
break;
case 28:
if (!isAddedToReadLaterList) {
ReadLater.setReadLater(submission, true);
Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
ReadLater.setReadLater(submission, false);
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
tv2.setTextColor(Color.WHITE);
s2.show();
}
});
if (NetworkUtil.isConnected(mContext)) {
new CommentCacheAsync(Arrays.asList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
s.show();
} else {
ReadLater.setReadLater(submission, false);
if (isReadLater || !Authentication.didOnline) {
final int pos = posts.indexOf(submission);
posts.remove(submission);
recyclerview.getAdapter().notifyItemRemoved(holder.getAdapterPosition());
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
tv2.setTextColor(Color.WHITE);
s2.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
posts.add(pos, (T) submission);
recyclerview.getAdapter().notifyDataSetChanged();
}
});
} else {
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
s2.show();
}
OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
}
break;
case 4:
Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
break;
case 12:
reportReason = "";
new MaterialDialog.Builder(mContext).input(mContext.getString(R.string.input_reason_for_report), null, true, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
reportReason = input.toString();
}
}).title(R.string.report_post).alwaysCallInputCallback().inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onNegative(null).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
new AccountManager(Authentication.reddit).report(submission, reportReason);
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (holder.itemView != null) {
try {
Snackbar s = Snackbar.make(holder.itemView, R.string.msg_report_sent, 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();
} catch (Exception ignored) {
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}).show();
break;
case 8:
Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), "https://reddit.com" + submission.getPermalink(), mContext);
break;
case 6:
{
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Link", submission.getUrl());
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
}
break;
case 25:
final TextView showText = new TextView(mContext);
showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
showText.setTextIsSelectable(true);
int sixteen = Reddit.dpToPxVertical(24);
showText.setPadding(sixteen, 0, sixteen, 0);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setView(showText).setTitle("Select text to copy").setCancelable(true).setPositiveButton("COPY SELECTED", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
if (!selected.isEmpty()) {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", selected);
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
} else {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.btn_cancel, null).setNeutralButton("COPY ALL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
}
}).show();
break;
}
}
});
b.show();
}
use of me.ccrama.redditslide.Activities.MainActivity 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);
}
}
}
use of me.ccrama.redditslide.Activities.MainActivity in project Slide by ccrama.
the class PopulateSubmissionViewHolder method showBottomSheet.
public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final SubmissionViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.profile, null);
final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.sub, null);
Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null);
Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null);
final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.report, null);
Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.save, null);
Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.openexternal, null);
Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.link, null);
Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null);
Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.filter, null);
Drawable crosspost = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.forward, null);
profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
sub.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
saved.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
link.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
readLater.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
filter.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
crosspost.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
final boolean isReadLater = mContext instanceof PostReadLater;
final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
if (Authentication.didOnline) {
b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
String save = mContext.getString(R.string.btn_save);
if (ActionStates.isSaved(submission)) {
save = mContext.getString(R.string.comment_unsave);
}
if (Authentication.isLoggedIn) {
b.sheet(3, saved, save);
}
}
if (isAddedToReadLaterList) {
b.sheet(28, readLater, "Mark As Read");
} else {
b.sheet(28, readLater, "Read later");
}
if (Authentication.didOnline) {
if (Authentication.isLoggedIn) {
b.sheet(12, report, mContext.getString(R.string.btn_report));
b.sheet(13, crosspost, mContext.getString(R.string.btn_crosspost));
}
}
if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
}
boolean hidden = submission.isHidden();
if (!full && Authentication.didOnline) {
if (!hidden) {
b.sheet(5, hide, mContext.getString(R.string.submission_hide));
} else {
b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
}
}
b.sheet(7, open, mContext.getString(R.string.submission_link_extern));
b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
b.sheet(10, filter, mContext.getString(R.string.filter_content));
}
b.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 1:
{
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
break;
case 2:
{
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivityForResult(i, 14);
}
break;
case 10:
String[] choices;
final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
if (flair.isEmpty()) {
choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
oldChosen = chosen.clone();
} else {
choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
}
chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(baseSub + ":" + flair) };
oldChosen = chosen.clone();
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.filter_title).alwaysCallMultiChoiceCallback().setMultiChoiceItems(choices, chosen, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
chosen[which] = isChecked;
}
}).setPositiveButton(R.string.filter_btn, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean filtered = false;
SharedPreferences.Editor e = SettingValues.prefs.edit();
if (chosen[0] && chosen[0] != oldChosen[0]) {
SettingValues.subredditFilters = SettingValues.subredditFilters + ((SettingValues.subredditFilters.isEmpty() || SettingValues.subredditFilters.endsWith(",")) ? "" : ",") + submission.getSubredditName();
filtered = true;
e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
PostMatch.subreddits = null;
} else if (!chosen[0] && chosen[0] != oldChosen[0]) {
SettingValues.subredditFilters = SettingValues.subredditFilters.replace(submission.getSubredditName(), "");
filtered = false;
e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
e.apply();
PostMatch.subreddits = null;
}
if (chosen[1] && chosen[1] != oldChosen[1]) {
SettingValues.userFilters = SettingValues.userFilters + ((SettingValues.userFilters.isEmpty() || SettingValues.userFilters.endsWith(",")) ? "" : ",") + submission.getAuthor();
filtered = true;
e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
PostMatch.users = null;
} else if (!chosen[1] && chosen[1] != oldChosen[1]) {
SettingValues.userFilters = SettingValues.userFilters.replace(submission.getAuthor(), "");
filtered = false;
e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
e.apply();
PostMatch.users = null;
}
if (chosen[2] && chosen[2] != oldChosen[2]) {
SettingValues.domainFilters = SettingValues.domainFilters + ((SettingValues.domainFilters.isEmpty() || SettingValues.domainFilters.endsWith(",")) ? "" : ",") + submission.getDomain();
filtered = true;
e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
PostMatch.domains = null;
} else if (!chosen[2] && chosen[2] != oldChosen[2]) {
SettingValues.domainFilters = SettingValues.domainFilters.replace(submission.getDomain(), "");
filtered = false;
e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
e.apply();
PostMatch.domains = null;
}
if (chosen[3] && chosen[3] != oldChosen[3]) {
SettingValues.alwaysExternal = SettingValues.alwaysExternal + ((SettingValues.alwaysExternal.isEmpty() || SettingValues.alwaysExternal.endsWith(",")) ? "" : ",") + submission.getDomain();
e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
e.apply();
} else if (!chosen[3] && chosen[3] != oldChosen[3]) {
SettingValues.alwaysExternal = SettingValues.alwaysExternal.replace(submission.getDomain(), "");
e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
e.apply();
}
if (chosen.length > 4) {
if (chosen[4] && chosen[4] != oldChosen[4]) {
SettingValues.flairFilters = SettingValues.flairFilters + ((SettingValues.flairFilters.isEmpty() || SettingValues.flairFilters.endsWith(",")) ? "" : ",") + (baseSub + ":" + flair);
e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
e.apply();
PostMatch.flairs = null;
filtered = true;
} else if (!chosen[4] && chosen[4] != oldChosen[4]) {
SettingValues.flairFilters = SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).replace((baseSub + ":" + flair).toLowerCase(Locale.ENGLISH), "");
e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
e.apply();
PostMatch.flairs = null;
}
}
if (filtered) {
e.apply();
PostMatch.domains = null;
PostMatch.subreddits = null;
PostMatch.users = null;
ArrayList<Contribution> toRemove = new ArrayList<>();
for (Contribution s : posts) {
if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
toRemove.add(s);
}
}
OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
for (Contribution remove : toRemove) {
final int pos = posts.indexOf(remove);
posts.remove(pos);
if (baseSub != null) {
s.hideMulti(pos);
}
}
s.writeToMemoryNoStorage();
recyclerview.getAdapter().notifyDataSetChanged();
}
}
}).setNegativeButton(R.string.btn_cancel, null).show();
break;
case 3:
saveSubmission(submission, mContext, holder, full);
break;
case 5:
{
hideSubmission(submission, posts, baseSub, recyclerview, mContext);
}
break;
case 7:
LinkUtil.openExternally(submission.getUrl(), mContext);
if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
// Do nothing if the post is NSFW and storeNSFWHistory is not enabled
} else if (SettingValues.storeHistory) {
HasSeen.addSeen(submission.getFullName());
}
break;
case 13:
LinkUtil.crosspost(submission, mContext);
break;
case 28:
if (!isAddedToReadLaterList) {
ReadLater.setReadLater(submission, true);
Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
ReadLater.setReadLater(submission, false);
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
tv2.setTextColor(Color.WHITE);
s2.show();
}
});
if (NetworkUtil.isConnected(mContext)) {
new CommentCacheAsync(Arrays.asList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
s.show();
} else {
ReadLater.setReadLater(submission, false);
if (isReadLater || !Authentication.didOnline) {
final int pos = posts.indexOf(submission);
posts.remove(submission);
recyclerview.getAdapter().notifyItemRemoved(holder.getAdapterPosition());
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
tv2.setTextColor(Color.WHITE);
s2.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
posts.add(pos, (T) submission);
recyclerview.getAdapter().notifyDataSetChanged();
}
});
} else {
Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
View view2 = s2.getView();
TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
s2.show();
}
OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
}
break;
case 4:
Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
break;
case 12:
reportReason = "";
new MaterialDialog.Builder(mContext).input(mContext.getString(R.string.input_reason_for_report), null, true, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
reportReason = input.toString();
}
}).title(R.string.report_post).alwaysCallInputCallback().inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onNegative(null).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
new AccountManager(Authentication.reddit).report(submission, reportReason);
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (holder.itemView != null) {
try {
Snackbar s = Snackbar.make(holder.itemView, R.string.msg_report_sent, Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
} catch (Exception ignored) {
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}).show();
break;
case 8:
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 6:
{
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Link", submission.getUrl());
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
}
break;
case 25:
final TextView showText = new TextView(mContext);
showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
showText.setTextIsSelectable(true);
int sixteen = Reddit.dpToPxVertical(24);
showText.setPadding(sixteen, 0, sixteen, 0);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setView(showText).setTitle("Select text to copy").setCancelable(true).setPositiveButton("COPY SELECTED", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
if (!selected.isEmpty()) {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", selected);
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
} else {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.btn_cancel, null).setNeutralButton("COPY ALL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
}
}).show();
break;
}
}
});
b.show();
}
use of me.ccrama.redditslide.Activities.MainActivity in project Slide by ccrama.
the class PopulateSubmissionViewHolder method addClickFunctions.
private static void addClickFunctions(final View base, final ContentType.Type type, final Activity contextActivity, final Submission submission, final SubmissionViewHolder holder, final boolean full) {
base.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (NetworkUtil.isConnected(contextActivity) || (!NetworkUtil.isConnected(contextActivity) && ContentType.fullImage(type))) {
if (SettingValues.storeHistory && !full) {
if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
HasSeen.addSeen(submission.getFullName());
if (contextActivity instanceof MainActivity || contextActivity instanceof MultiredditOverview || contextActivity instanceof SubredditView || contextActivity instanceof Search || contextActivity instanceof Profile) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
}
}
}
if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking() || (base instanceof HeaderImageLinkView && ((HeaderImageLinkView) base).popped)) {
if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
switch(type) {
case VID_ME:
case STREAMABLE:
if (SettingValues.video) {
Intent myIntent = new Intent(contextActivity, MediaView.class);
myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());
myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
addAdaptorPosition(myIntent, submission, holder.getAdapterPosition());
contextActivity.startActivity(myIntent);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case IMGUR:
openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
break;
case EMBEDDED:
if (SettingValues.video) {
String data = Html.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
{
Intent i = new Intent(contextActivity, FullscreenVideo.class);
i.putExtra(FullscreenVideo.EXTRA_HTML, data);
contextActivity.startActivity(i);
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case REDDIT:
openRedditContent(submission.getUrl(), contextActivity);
break;
case LINK:
LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), contextActivity, holder.getAdapterPosition(), submission);
break;
case SELF:
if (holder != null) {
OnSingleClickListener.override = true;
holder.itemView.performClick();
}
break;
case ALBUM:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(contextActivity, AlbumPager.class);
i.putExtra(AlbumPager.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
} else {
i = new Intent(contextActivity, Album.class);
i.putExtra(Album.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
}
addAdaptorPosition(i, submission, holder.getAdapterPosition());
contextActivity.startActivity(i);
contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case TUMBLR:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(contextActivity, TumblrPager.class);
i.putExtra(TumblrPager.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
} else {
i = new Intent(contextActivity, Tumblr.class);
i.putExtra(Tumblr.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
}
addAdaptorPosition(i, submission, holder.getAdapterPosition());
contextActivity.startActivity(i);
contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case DEVIANTART:
case XKCD:
case IMAGE:
openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
break;
case VREDDIT_REDIRECT:
case GIF:
case VREDDIT_DIRECT:
openGif(contextActivity, submission, holder.getAdapterPosition());
break;
case NONE:
if (holder != null) {
holder.itemView.performClick();
}
break;
case VIDEO:
if (Reddit.videoPlugin) {
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
sharingIntent.putExtra("url", submission.getUrl());
contextActivity.startActivity(sharingIntent);
} catch (Exception e) {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
}
} else {
if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking()) {
Snackbar s = Snackbar.make(holder.itemView, R.string.go_online_view_content, Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
}
use of me.ccrama.redditslide.Activities.MainActivity in project Slide by ccrama.
the class CommentPage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
v = localInflater.inflate(R.layout.fragment_verticalcontenttoolbar, container, false);
rv = (RecyclerView) v.findViewById(R.id.vertical_content);
rv.setLayoutManager(mLayoutManager);
rv.getLayoutManager().scrollToPosition(0);
toolbar = (Toolbar) v.findViewById(R.id.toolbar);
toolbar.setPopupTheme(new ColorPreferences(getActivity()).getFontStyle().getBaseId());
if (!SettingValues.fabComments) {
v.findViewById(R.id.comment_floating_action_button).setVisibility(View.GONE);
} else {
fab = (FloatingActionButton) v.findViewById(R.id.comment_floating_action_button);
if (SettingValues.fastscroll) {
FrameLayout.LayoutParams fabs = (FrameLayout.LayoutParams) fab.getLayoutParams();
fabs.setMargins(fabs.leftMargin, fabs.topMargin, fabs.rightMargin, fabs.bottomMargin * 3);
fab.setLayoutParams(fabs);
}
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = getActivity().getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.edit_comment, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
final EditText e = (EditText) dialoglayout.findViewById(R.id.entry);
// Tint the replyLine appropriately if the base theme is Light or Sepia
if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
final int TINT = ContextCompat.getColor(getContext(), R.color.md_grey_600);
e.setHintTextColor(TINT);
e.getBackground().setColorFilter(TINT, PorterDuff.Mode.SRC_IN);
}
DoEditorActions.doActions(e, dialoglayout, getActivity().getSupportFragmentManager(), getActivity(), adapter.submission.isSelfPost() ? adapter.submission.getSelftext() : null, new String[] { adapter.submission.getAuthor() });
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) {
adapter.dataSet.refreshLayout.setRefreshing(true);
new ReplyTaskComment(adapter.submission).execute(e.getText().toString());
d.dismiss();
}
});
}
});
}
if (fab != null)
fab.show();
resetScroll(false);
fastScroll = v.findViewById(R.id.commentnav);
if (!SettingValues.fastscroll) {
fastScroll.setVisibility(View.GONE);
} else {
v.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0) {
goDown();
}
}
});
v.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0)
goUp();
}
});
v.findViewById(R.id.nav).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.currentComments != null) {
int parentCount, opCount, linkCount, gildCount;
parentCount = 0;
opCount = 0;
linkCount = 0;
gildCount = 0;
String op = adapter.submission.getAuthor();
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && !(o instanceof MoreChildItem)) {
if (o.comment.isTopLevel())
parentCount++;
if (o.comment.getComment().getTimesGilded() > 0)
gildCount++;
if (o.comment.getComment().getAuthor() != null && o.comment.getComment().getAuthor().equals(op)) {
opCount++;
}
if (o.comment.getComment().getDataNode().has("body_html") && o.comment.getComment().getDataNode().get("body_html").asText().contains("</a")) {
linkCount++;
}
}
}
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.set_nav_mode).setSingleChoiceItems(Reddit.stringToArray("Parent comment (" + parentCount + ")" + "," + "Children comment (highlight child comment & navigate)" + "," + "OP (" + opCount + ")" + "," + "Time" + "," + "Link (" + linkCount + ")" + "," + ((Authentication.isLoggedIn) ? "You" + "," : "") + "Gilded (" + gildCount + ")").toArray(new String[Authentication.isLoggedIn ? 6 : 5]), getCurrentSort(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
currentSort = CommentNavType.PARENTS;
break;
case 1:
currentSort = CommentNavType.CHILDREN;
break;
case 2:
currentSort = CommentNavType.OP;
break;
case 3:
currentSort = CommentNavType.TIME;
LayoutInflater inflater = getActivity().getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.commenttime, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
final Slider landscape = (Slider) dialoglayout.findViewById(R.id.landscape);
final TextView since = (TextView) dialoglayout.findViewById(R.id.time_string);
landscape.setValueRange(60, 18000, false);
landscape.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {
@Override
public void onPositionChanged(Slider slider, boolean b, float v, float v1, int i, int i1) {
Calendar c = Calendar.getInstance();
sortTime = c.getTimeInMillis() - i1 * 1000;
int commentcount = 0;
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && o.comment.getComment().getDataNode().has("created") && o.comment.getComment().getCreated().getTime() > sortTime) {
commentcount += 1;
}
}
since.setText(TimeUtils.getTimeAgo(sortTime, getActivity()) + " (" + commentcount + " comments)");
}
});
landscape.setValue(600, false);
builder.setView(dialoglayout);
builder.setPositiveButton(R.string.btn_set, null).show();
break;
case 5:
currentSort = CommentNavType.YOU;
break;
case 4:
currentSort = CommentNavType.LINK;
break;
case 6:
currentSort = CommentNavType.GILDED;
break;
}
}
}).show();
}
}
});
}
v.findViewById(R.id.up).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// Scroll to top
rv.getLayoutManager().scrollToPosition(1);
return true;
}
});
if (SettingValues.voteGestures) {
v.findViewById(R.id.up).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.upvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!upvoted) {
text = getString(R.string.profile_upvoted);
downvoted = false;
} else {
text = getString(R.string.vote_removed);
}
upvoted = !upvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
if (SettingValues.voteGestures) {
v.findViewById(R.id.down).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.downvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!downvoted) {
text = getString(R.string.profile_downvoted);
upvoted = false;
} else {
text = getString(R.string.vote_removed);
}
downvoted = !downvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
toolbar.setBackgroundColor(Palette.getColor(subreddit));
mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, getActivity()));
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (comments != null) {
comments.loadMore(adapter, subreddit, true);
} else {
mSwipeRefreshLayout.setRefreshing(false);
}
// TODO catch errors
}
});
toolbar.setTitle(subreddit);
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
toolbar.inflateMenu(R.menu.menu_comment_items);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.search:
{
if (comments.comments != null && comments.submission != null) {
DataShare.sharedComments = comments.comments;
DataShare.subAuthor = comments.submission.getAuthor();
Intent i = new Intent(getActivity(), CommentSearch.class);
if (getActivity() instanceof MainActivity) {
getActivity().startActivityForResult(i, 423);
} else {
startActivityForResult(i, 423);
}
}
}
return true;
case R.id.sidebar:
doSidebarOpen();
return true;
case R.id.related:
if (adapter.submission.isSelfPost()) {
new AlertDialogWrapper.Builder(getActivity()).setTitle("Selftext posts have no related submissions").setPositiveButton(R.string.btn_ok, null).show();
} else {
Intent i = new Intent(getActivity(), Related.class);
i.putExtra(Related.EXTRA_URL, adapter.submission.getUrl());
startActivity(i);
}
return true;
case R.id.shadowbox:
if (SettingValues.tabletUI) {
if (comments.comments != null && comments.submission != null) {
ShadowboxComments.comments = new ArrayList<>();
for (CommentObject c : comments.comments) {
if (c instanceof CommentItem) {
if (c.comment.getComment().getDataNode().get("body_html").asText().contains("</a")) {
String body = c.comment.getComment().getDataNode().get("body_html").asText();
String url;
String[] split = body.split("<a href=\"");
if (split.length > 1) {
for (String chunk : split) {
url = chunk.substring(0, chunk.indexOf("\"", 1));
ContentType.Type t = ContentType.getContentType(url);
if (ContentType.mediaType(t)) {
ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
}
}
} else {
int start = body.indexOf("<a href=\"");
url = body.substring(start, body.indexOf("\"", start + 1));
ContentType.Type t = ContentType.getContentType(url);
if (ContentType.mediaType(t)) {
ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
}
}
}
}
}
if (!ShadowboxComments.comments.isEmpty()) {
Intent i = new Intent(getActivity(), ShadowboxComments.class);
startActivity(i);
} else {
Snackbar.make(mSwipeRefreshLayout, R.string.shadowbox_comments_nolinks, Snackbar.LENGTH_SHORT).show();
}
}
} else {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(getContext()).setTitle(R.string.general_shadowbox_comments_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
b.show();
}
return true;
case R.id.sort:
{
openPopup(toolbar);
return true;
}
case R.id.content:
{
if (adapter != null && adapter.submission != null) {
if (!PostMatch.openExternal(adapter.submission.getUrl())) {
ContentType.Type type = ContentType.getContentType(adapter.submission);
switch(type) {
case VID_ME:
case STREAMABLE:
if (SettingValues.video) {
Intent myIntent = new Intent(getActivity(), MediaView.class);
myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
myIntent.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
getActivity().startActivity(myIntent);
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
break;
case IMGUR:
case XKCD:
Intent i2 = new Intent(getActivity(), MediaView.class);
i2.putExtra(MediaView.SUBREDDIT, subreddit);
if (adapter.submission.getDataNode().has("preview") && adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && type != ContentType.Type.XKCD) {
// Load the preview image which has probably already been cached in memory instead of the direct link
String previewUrl = adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
i2.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
}
i2.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
getActivity().startActivity(i2);
break;
case EMBEDDED:
if (SettingValues.video) {
String data = adapter.submission.getDataNode().get("media_embed").get("content").asText();
{
Intent i = new Intent(getActivity(), FullscreenVideo.class);
i.putExtra(FullscreenVideo.EXTRA_HTML, data);
getActivity().startActivity(i);
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
break;
case REDDIT:
PopulateSubmissionViewHolder.openRedditContent(adapter.submission.getUrl(), getActivity());
break;
case LINK:
LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getColor(adapter.submission.getSubredditName()), getActivity());
break;
case NONE:
case SELF:
if (adapter.submission.getSelftext().isEmpty()) {
Snackbar s = Snackbar.make(rv, R.string.submission_nocontent, 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();
} else {
LayoutInflater inflater = getActivity().getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
adapter.setViews(adapter.submission.getDataNode().get("selftext_html").asText(), adapter.submission.getSubredditName(), (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
builder.setView(dialoglayout);
builder.show();
}
break;
case ALBUM:
if (SettingValues.album) {
if (SettingValues.albumSwipe) {
Intent i = new Intent(getActivity(), AlbumPager.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(AlbumPager.SUBREDDIT, subreddit);
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
Intent i = new Intent(getActivity(), Album.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(Album.SUBREDDIT, subreddit);
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
break;
case TUMBLR:
if (SettingValues.image) {
if (SettingValues.albumSwipe) {
Intent i = new Intent(getActivity(), TumblrPager.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(TumblrPager.SUBREDDIT, subreddit);
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
Intent i = new Intent(getActivity(), Tumblr.class);
i.putExtra(Tumblr.SUBREDDIT, subreddit);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
break;
case IMAGE:
PopulateSubmissionViewHolder.openImage(type, getActivity(), adapter.submission, null, -1);
break;
case VREDDIT_REDIRECT:
case VREDDIT_DIRECT:
case GIF:
PopulateSubmissionViewHolder.openGif(getActivity(), adapter.submission, -1);
break;
case VIDEO:
if (Reddit.videoPlugin) {
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
sharingIntent.putExtra("url", adapter.submission.getUrl());
getActivity().startActivity(sharingIntent);
} catch (Exception e) {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
}
}
}
return true;
case R.id.reload:
if (comments != null) {
mSwipeRefreshLayout.setRefreshing(true);
comments.loadMore(adapter, subreddit);
}
return true;
case R.id.collapse:
{
if (adapter != null) {
adapter.collapseAll();
}
}
return true;
case android.R.id.home:
getActivity().onBackPressed();
return true;
}
return false;
}
});
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayoutManager) rv.getLayoutManager()).scrollToPositionWithOffset(1, headerHeight);
resetScroll(false);
}
});
addClickFunctionSubName(toolbar);
doTopBar();
if (Authentication.didOnline && !NetworkUtil.isConnectedNoOverride(getActivity())) {
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.err_title).setMessage(R.string.err_connection_failed_msg).setNegativeButton(R.string.btn_close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!(getActivity() instanceof MainActivity)) {
getActivity().finish();
}
}
}).setPositiveButton(R.string.btn_offline, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(getActivity());
}
}).show();
}
if (!(getActivity() instanceof CommentsScreen) || ((CommentsScreen) getActivity()).currentPage == page) {
doAdapter(true);
} else {
doAdapter(false);
}
return v;
}
Aggregations