use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class MainActivity method doSubSidebar.
public void doSubSidebar(final String subreddit) {
if (mAsyncGetSubreddit != null) {
mAsyncGetSubreddit.cancel(true);
}
findViewById(R.id.loader).setVisibility(View.VISIBLE);
invalidateOptionsMenu();
if (!subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
if (drawerLayout != null) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END);
}
mAsyncGetSubreddit = new AsyncGetSubreddit();
mAsyncGetSubreddit.execute(subreddit);
final View dialoglayout = findViewById(R.id.sidebarsub);
{
View submit = (dialoglayout.findViewById(R.id.submit));
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
submit.setVisibility(View.GONE);
}
if (SettingValues.fab && SettingValues.fabType == Constants.FAB_POST) {
submit.setVisibility(View.GONE);
}
submit.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Submit.class);
if (!subreddit.contains("/m/") && canSubmit) {
inte.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
}
MainActivity.this.startActivity(inte);
}
});
}
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Wiki.class);
i.putExtra(Wiki.EXTRA_SUBREDDIT, subreddit);
startActivity(i);
}
});
dialoglayout.findViewById(R.id.syncflair).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageFlairs.syncFlairs(MainActivity.this, subreddit);
}
});
dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Submit.class);
if ((!subreddit.contains("/m/") || !subreddit.contains(".")) && canSubmit) {
i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
}
startActivity(i);
}
});
final TextView sort = dialoglayout.findViewById(R.id.sort);
Sorting sortingis = Sorting.HOT;
if (SettingValues.hasSort(subreddit)) {
sortingis = SettingValues.getBaseSubmissionSort(subreddit);
sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
} else {
sort.setText("Set default sorting");
}
final int sortid = SortingUtil.getSortingId(sortingis);
dialoglayout.findViewById(R.id.sorting).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final DialogInterface.OnClickListener l2 = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch(i) {
case 0:
sorts = Sorting.HOT;
break;
case 1:
sorts = Sorting.NEW;
break;
case 2:
sorts = Sorting.RISING;
break;
case 3:
sorts = Sorting.TOP;
askTimePeriod(sorts, subreddit, dialoglayout);
return;
case 4:
sorts = Sorting.CONTROVERSIAL;
askTimePeriod(sorts, subreddit, dialoglayout);
return;
}
SettingValues.setSubSorting(sorts, time, subreddit);
Sorting sortingis = SettingValues.getBaseSubmissionSort(subreddit);
sort.setText(sortingis.name() + ((sortingis == Sorting.CONTROVERSIAL || sortingis == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
reloadSubs();
}
};
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.sorting_choose).setSingleChoiceItems(SortingUtil.getSortingStrings(), sortid, l2).setNegativeButton("Reset default sorting", (dialog, which) -> {
SettingValues.prefs.edit().remove("defaultSort" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
SettingValues.prefs.edit().remove("defaultTime" + subreddit.toLowerCase(Locale.ENGLISH)).apply();
final TextView sort1 = dialoglayout.findViewById(R.id.sort);
if (SettingValues.hasSort(subreddit)) {
Sorting sortingis1 = SettingValues.getBaseSubmissionSort(subreddit);
sort1.setText(sortingis1.name() + ((sortingis1 == Sorting.CONTROVERSIAL || sortingis1 == Sorting.TOP) ? " of " + SettingValues.getBaseTimePeriod(subreddit).name() : ""));
} else {
sort1.setText("Set default sorting");
}
reloadSubs();
}).show();
}
});
dialoglayout.findViewById(R.id.theme).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int style = new ColorPreferences(MainActivity.this).getThemeSubreddit(subreddit);
final Context contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, style);
LayoutInflater localInflater = getLayoutInflater().cloneInContext(contextThemeWrapper);
final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(subreddit);
SettingsSubAdapter.showSubThemeEditor(arrayList, MainActivity.this, dialoglayout);
}
});
dialoglayout.findViewById(R.id.mods).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_findingmods).cancelable(true).content(R.string.misc_please_wait).progress(true, 100).show();
new AsyncTask<Void, Void, Void>() {
ArrayList<UserRecord> mods;
@Override
protected Void doInBackground(Void... params) {
mods = new ArrayList<>();
UserRecordPaginator paginator = new UserRecordPaginator(Authentication.reddit, subreddit, "moderators");
paginator.setSorting(Sorting.HOT);
paginator.setTimePeriod(TimePeriod.ALL);
while (paginator.hasNext()) {
mods.addAll(paginator.next());
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
final ArrayList<String> names = new ArrayList<>();
for (UserRecord rec : mods) {
names.add(rec.getFullName());
}
d.dismiss();
new MaterialDialog.Builder(MainActivity.this).title(getString(R.string.sidebar_submods, subreddit)).items(names).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
Intent i = new Intent(MainActivity.this, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, names.get(which));
startActivity(i);
}
}).positiveText(R.string.btn_message).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent i = new Intent(MainActivity.this, SendMessage.class);
i.putExtra(SendMessage.EXTRA_NAME, "/r/" + subreddit);
startActivity(i);
}
}).show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
dialoglayout.findViewById(R.id.flair).setVisibility(View.GONE);
if (Authentication.didOnline && Authentication.isLoggedIn) {
if (currentFlair != null)
currentFlair.cancel(true);
currentFlair = new AsyncTask<View, Void, View>() {
List<FlairTemplate> flairs;
ArrayList<String> flairText;
String current;
AccountManager m;
@Override
protected View doInBackground(View... params) {
try {
m = new AccountManager(Authentication.reddit);
JsonNode node = m.getFlairChoicesRootNode(subreddit, null);
flairs = m.getFlairChoices(subreddit, node);
FlairTemplate currentF = m.getCurrentFlair(subreddit, node);
if (currentF != null) {
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
}
flairText = new ArrayList<>();
for (FlairTemplate temp : flairs) {
if (temp.getText().isEmpty()) {
flairText.add("[" + temp.getCssClass() + "]");
} else {
flairText.add(temp.getText());
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
return params[0];
}
@Override
protected void onPostExecute(View flair) {
if (flairs != null && !flairs.isEmpty() && flairText != null && !flairText.isEmpty()) {
flair.setVisibility(View.VISIBLE);
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
flair.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MaterialDialog.Builder(MainActivity.this).items(flairText).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 = flairs.get(which);
if (t.isTextEditable()) {
new MaterialDialog.Builder(MainActivity.this).title(R.string.sidebar_select_flair_text).input(getString(R.string.mod_flair_hint), t.getText(), true, (dialog1, 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(subreddit, t, flair, Authentication.name);
FlairTemplate currentF = m.getCurrentFlair(subreddit);
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
} else {
s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
if (s != null) {
LayoutUtils.showSnackbar(s);
}
}
}.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(subreddit, t, null, Authentication.name);
FlairTemplate currentF = m.getCurrentFlair(subreddit);
if (currentF.getText().isEmpty()) {
current = ("[" + currentF.getCssClass() + "]");
} else {
current = (currentF.getText());
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (current != null) {
((TextView) dialoglayout.findViewById(R.id.flair_text)).setText(getString(R.string.sidebar_flair, current));
}
s = Snackbar.make(mToolbar, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
} else {
s = Snackbar.make(mToolbar, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
}
if (s != null) {
LayoutUtils.showSnackbar(s);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}).show();
}
});
}
}
};
currentFlair.execute((View) dialoglayout.findViewById(R.id.flair));
}
} else {
if (drawerLayout != null) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
}
}
}
use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class ContributionAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHolder instanceof SubmissionViewHolder) {
final SubmissionViewHolder holder = (SubmissionViewHolder) firstHolder;
final Submission submission = (Submission) dataSet.posts.get(i);
CreateCardView.resetColorCard(holder.itemView);
if (submission.getSubredditName() != null)
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
final TextView title = dialoglayout.findViewById(R.id.title);
title.setText(CompatUtil.fromHtml(submission.getTitle()));
((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
} else {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
new AsyncSave(mContext, firstHolder.itemView).execute(submission);
}
});
dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlString = "https://reddit.com" + submission.getPermalink();
Intent i = new Intent(mContext, Website.class);
i.putExtra(LinkUtil.EXTRA_URL, urlString);
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSelfPost()) {
if (SettingValues.shareLongLink) {
Reddit.defaultShareText("", "https://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
}
} else {
new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case R.id.reddit_url:
if (SettingValues.shareLongLink) {
Reddit.defaultShareText(submission.getTitle(), "https://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
}
break;
case R.id.link_url:
Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
break;
}
}
}).show();
}
}
});
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
}
title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext).setView(dialoglayout);
final Dialog d = builder.show();
dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
d.dismiss();
Hidden.setHidden(old);
Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.posts.add(pos, old);
notifyItemInserted(pos + 1);
Hidden.undoHidden(old);
}
});
LayoutUtils.showSnackbar(s);
}
});
return true;
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
final ImageView hideButton = holder.itemView.findViewById(R.id.hide);
if (hideButton != null && isHiddenPost) {
hideButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final Contribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
Hidden.undoHidden(old);
}
});
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "www.reddit.com" + submission.getPermalink();
url = url.replace("?ref=search_posts", "");
OpenRedditLink.openUrl(mContext, url, true);
if (SettingValues.storeHistory) {
if (SettingValues.storeNSFWHistory && submission.isNsfw() || !submission.isNsfw())
HasSeen.addSeen(submission.getFullName());
}
notifyItemChanged(pos);
}
});
} else if (firstHolder instanceof ProfileCommentViewHolder) {
// IS COMMENT
ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHolder;
final Comment comment = (Comment) dataSet.posts.get(i);
String scoreText;
if (comment.isScoreHidden()) {
scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
} else {
scoreText = String.format(Locale.getDefault(), "%d", comment.getScore());
}
SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
if (score == null || score.toString().isEmpty()) {
score = new SpannableStringBuilder("0");
}
if (!scoreText.contains("[")) {
score.append(String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.points, comment.getScore())));
}
holder.score.setText(score);
if (Authentication.isLoggedIn) {
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
} else {
holder.score.setTextColor(holder.time.getCurrentTextColor());
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
// some users were crashing here
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(time);
titleString.append(spacer);
if (comment.getSubredditName() != null) {
String subname = comment.getSubredditName();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
holder.time.setText(titleString);
setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.content.setTypeface(typeface);
((TextView) holder.gild).setText("");
if (!SettingValues.hideCommentAwards && (comment.getTimesSilvered() > 0 || comment.getTimesGilded() > 0 || comment.getTimesPlatinized() > 0)) {
TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
a.recycle();
holder.gild.setVisibility(View.VISIBLE);
// Add silver, gold, platinum icons and counts in that order
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesSilvered(), R.drawable.silver);
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesGilded(), R.drawable.gold);
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesPlatinized(), R.drawable.platinum);
} else if (holder.gild.getVisibility() == View.VISIBLE)
holder.gild.setVisibility(View.GONE);
if (comment.getSubmissionTitle() != null)
holder.title.setText(CompatUtil.fromHtml(comment.getSubmissionTitle()));
else
holder.title.setText(CompatUtil.fromHtml(comment.getAuthor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
holder.content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
} else if (firstHolder instanceof SpacerViewHolder) {
firstHolder.itemView.setLayoutParams(new LinearLayout.LayoutParams(firstHolder.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.findViewById(R.id.header).getHeight());
layoutParams.setFullSpan(true);
firstHolder.itemView.setLayoutParams(layoutParams);
}
}
}
use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class ModeratorAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHold instanceof SubmissionViewHolder) {
SubmissionViewHolder holder = (SubmissionViewHolder) firstHold;
final Submission submission = (Submission) dataSet.posts.get(i);
CreateCardView.resetColorCard(holder.itemView);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
LayoutInflater inflater = mContext.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
final TextView title = dialoglayout.findViewById(R.id.title);
title.setText(CompatUtil.fromHtml(submission.getTitle()));
((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, SubredditView.class);
i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
} else {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
new AsyncSave(mContext, firstHold.itemView).execute(submission);
}
});
dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
if (submission.isSaved()) {
((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
}
dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlString = "https://reddit.com" + submission.getPermalink();
Intent i = new Intent(mContext, Website.class);
i.putExtra(LinkUtil.EXTRA_URL, urlString);
mContext.startActivity(i);
}
});
dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (submission.isSelfPost()) {
if (SettingValues.shareLongLink) {
Reddit.defaultShareText("", "https://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
}
} else {
new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case R.id.reddit_url:
if (SettingValues.shareLongLink) {
Reddit.defaultShareText(submission.getTitle(), "https://reddit.com" + submission.getPermalink(), mContext);
} else {
Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
}
break;
case R.id.link_url:
Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
break;
}
}
}).show();
}
}
});
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
}
title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext).setView(dialoglayout);
final Dialog d = builder.show();
dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int pos = dataSet.posts.indexOf(submission);
final PublicContribution old = dataSet.posts.get(pos);
dataSet.posts.remove(submission);
notifyItemRemoved(pos + 1);
d.dismiss();
Hidden.setHidden(old);
Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.posts.add(pos, old);
notifyItemInserted(pos + 1);
Hidden.undoHidden(old);
}
});
LayoutUtils.showSnackbar(s);
}
});
return true;
}
});
new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
final ImageView hideButton = holder.itemView.findViewById(R.id.hide);
if (hideButton != null) {
hideButton.setVisibility(View.GONE);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "www.reddit.com" + submission.getPermalink();
url = url.replace("?ref=search_posts", "");
OpenRedditLink.openUrl(mContext, url, true);
}
});
} else if (firstHold instanceof ProfileCommentViewHolder) {
// IS COMMENT
final ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHold;
final Comment comment = (Comment) dataSet.posts.get(i);
SpannableStringBuilder author = new SpannableStringBuilder(comment.getAuthor());
final int authorcolor = Palette.getFontColorUser(comment.getAuthor());
if (comment.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, android.R.color.white, R.color.md_red_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (comment.getDistinguishedStatus() == DistinguishedStatus.SPECIAL) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, android.R.color.white, R.color.md_red_500, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (comment.getDistinguishedStatus() == DistinguishedStatus.MODERATOR) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, android.R.color.white, R.color.md_green_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (Authentication.name != null && comment.getAuthor().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, android.R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (authorcolor != 0) {
author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
ToolboxUI.appendToolboxNote(mContext, author, comment.getSubredditName(), comment.getAuthor());
holder.user.setText(author);
holder.user.append(mContext.getResources().getString(R.string.submission_properties_seperator));
holder.user.setVisibility(View.VISIBLE);
holder.score.setText(comment.getScore() + " " + mContext.getResources().getQuantityString(R.plurals.points, comment.getScore()));
if (Authentication.isLoggedIn) {
if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
} else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
} else {
holder.score.setTextColor(holder.time.getCurrentTextColor());
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
// some users were crashing here
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(time);
titleString.append(spacer);
final ImageView mod = holder.itemView.findViewById(R.id.mod);
try {
if (UserSubscriptions.modOf.contains(comment.getSubredditName())) {
// todo
mod.setVisibility(View.GONE);
} else {
mod.setVisibility(View.GONE);
}
} catch (Exception e) {
Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
}
if ((UserSubscriptions.modOf != null) && UserSubscriptions.modOf.contains(comment.getSubredditName().toLowerCase(Locale.ENGLISH))) {
mod.setVisibility(View.VISIBLE);
final Map<String, Integer> reports = comment.getUserReports();
final Map<String, String> reports2 = comment.getModeratorReports();
if (reports.size() + reports2.size() > 0) {
BlendModeUtil.tintImageViewAsSrcAtop(mod, ContextCompat.getColor(mContext, R.color.md_red_300));
} else {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
BlendModeUtil.tintImageViewAsSrcAtop(mod, color);
ta.recycle();
}
mod.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
showModBottomSheet(mContext, comment, holder, reports, reports2);
}
});
} else {
mod.setVisibility(View.GONE);
}
if (comment.getSubredditName() != null) {
String subname = comment.getSubredditName();
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(subreddit);
}
holder.time.setText(titleString);
setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
((TextView) holder.gild).setText("");
if (!SettingValues.hideCommentAwards && (comment.getTimesSilvered() > 0 || comment.getTimesGilded() > 0 || comment.getTimesPlatinized() > 0)) {
TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
a.recycle();
holder.gild.setVisibility(View.VISIBLE);
// Add silver, gold, platinum icons and counts in that order
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesSilvered(), R.drawable.silver);
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesGilded(), R.drawable.gold);
MiscUtil.addAwards(mContext, fontsize, holder, comment.getTimesPlatinized(), R.drawable.platinum);
} else if (holder.gild.getVisibility() == View.VISIBLE)
holder.gild.setVisibility(View.GONE);
if (comment.getSubmissionTitle() != null)
holder.title.setText(CompatUtil.fromHtml(comment.getSubmissionTitle()));
else
holder.title.setText(CompatUtil.fromHtml(comment.getAuthor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
holder.content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
}
});
}
if (firstHold instanceof SpacerViewHolder) {
firstHold.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(firstHold.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
}
}
use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class CommentAdapterHelper method showBan.
public static void showBan(final Context mContext, final View mToolbar, final Comment submission, String rs, String nt, String msg, String t) {
LinearLayout l = new LinearLayout(mContext);
l.setOrientation(LinearLayout.VERTICAL);
int sixteen = DisplayUtil.dpToPxVertical(16);
l.setPadding(sixteen, 0, sixteen, 0);
final EditText reason = new EditText(mContext);
reason.setHint(R.string.mod_ban_reason);
reason.setText(rs);
reason.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(reason);
final EditText note = new EditText(mContext);
note.setHint(R.string.mod_ban_note_mod);
note.setText(nt);
note.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(note);
final EditText message = new EditText(mContext);
message.setHint(R.string.mod_ban_note_user);
message.setText(msg);
message.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(message);
final EditText time = new EditText(mContext);
time.setHint(R.string.mod_ban_time);
time.setText(t);
time.setInputType(InputType.TYPE_CLASS_NUMBER);
l.addView(time);
new AlertDialog.Builder(mContext).setView(l).setTitle(mContext.getString(R.string.mod_ban_title, submission.getAuthor())).setCancelable(true).setPositiveButton(R.string.mod_btn_ban, (dialog, which) -> {
// to ban
if (reason.getText().toString().isEmpty()) {
new AlertDialog.Builder(mContext).setTitle(R.string.mod_ban_reason_required).setMessage(R.string.misc_please_try_again).setPositiveButton(R.string.btn_ok, (dialog1, which1) -> showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString())).setCancelable(false).show();
} else {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
String n = note.getText().toString();
String m = message.getText().toString();
if (n.isEmpty()) {
n = null;
}
if (m.isEmpty()) {
m = null;
}
if (time.getText().toString().isEmpty()) {
new ModerationManager(Authentication.reddit).banUserPermanently(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m);
} else {
new ModerationManager(Authentication.reddit).banUser(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m, Integer.parseInt(time.getText().toString()));
}
return true;
} catch (Exception e) {
if (e instanceof InvalidScopeException) {
scope = true;
}
e.printStackTrace();
return false;
}
}
boolean scope;
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
s = Snackbar.make(mToolbar, R.string.mod_ban_success, Snackbar.LENGTH_SHORT);
} else {
if (scope) {
new AlertDialog.Builder(mContext).setTitle(R.string.mod_ban_reauth).setMessage(R.string.mod_ban_reauth_question).setPositiveButton(R.string.btn_ok, (dialog12, which12) -> {
Intent i = new Intent(mContext, Reauthenticate.class);
mContext.startActivity(i);
}).setNegativeButton(R.string.misc_maybe_later, null).setCancelable(false).show();
}
s = Snackbar.make(mToolbar, R.string.mod_ban_fail, Snackbar.LENGTH_INDEFINITE).setAction(R.string.misc_try_again, new View.OnClickListener() {
@Override
public void onClick(View v) {
showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
}
});
}
if (s != null) {
LayoutUtils.showSnackbar(s);
}
}
}.execute();
}
}).setNegativeButton(R.string.btn_cancel, null).show();
}
use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class CommentAdapterHelper method categorizeComment.
private static void categorizeComment(final Comment comment, final Context mContext) {
new AsyncTask<Void, Void, List<String>>() {
Dialog d;
@Override
public void onPreExecute() {
d = new MaterialDialog.Builder(mContext).progress(true, 100).content(R.string.misc_please_wait).title(R.string.profile_category_loading).show();
}
@Override
protected List<String> doInBackground(Void... params) {
try {
List<String> categories = new ArrayList<String>(new AccountManager(Authentication.reddit).getSavedCategories());
categories.add("New category");
return categories;
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<String>() {
{
add("New category");
}
};
}
}
@Override
public void onPostExecute(final List<String> data) {
try {
new MaterialDialog.Builder(mContext).items(data).title(R.string.sidebar_select_flair).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, final View itemView, int which, CharSequence text) {
final String t = data.get(which);
if (which == data.size() - 1) {
new MaterialDialog.Builder(mContext).title(R.string.category_set_name).input(mContext.getString(R.string.category_set_name_hint), null, false, (dialog1, 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 AccountManager(Authentication.reddit).save(comment, flair);
return true;
} catch (ApiException e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (itemView != null) {
s = Snackbar.make(itemView, R.string.submission_info_saved, Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
}
} else {
if (itemView != null) {
s = Snackbar.make(itemView, R.string.category_set_error, Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
}
}
}
}.execute();
}
}).negativeText(R.string.btn_cancel).show();
} else {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
new AccountManager(Authentication.reddit).save(comment, t);
return true;
} catch (ApiException e) {
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
if (itemView != null) {
s = Snackbar.make(itemView, R.string.submission_info_saved, Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
}
} else {
if (itemView != null) {
s = Snackbar.make(itemView, R.string.category_set_error, Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
}
}
}
}.execute();
}
}
}).show();
if (d != null) {
d.dismiss();
}
} catch (Exception ignored) {
}
}
}.execute();
}
Aggregations