use of me.ccrama.redditslide.Views.RoundedBackgroundSpan in project Slide by ccrama.
the class InboxAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (!(viewHolder instanceof ContributionAdapter.EmptyViewHolder) && !(viewHolder instanceof SpacerViewHolder)) {
final MessageViewHolder messageViewHolder = (MessageViewHolder) viewHolder;
final Message comment = dataSet.posts.get(i);
messageViewHolder.time.setText(TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext));
SpannableStringBuilder titleString = new SpannableStringBuilder();
String author = comment.getAuthor();
String direction = "from ";
if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
direction = "to ";
}
if (comment.getDataNode().has("subreddit") && author == null || author.isEmpty()) {
direction = "via /r/" + comment.getSubreddit();
}
titleString.append(direction);
if (author != null) {
titleString.append(author);
titleString.append(" ");
if (UserTags.isUserTagged(author)) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(author) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (UserSubscriptions.friends.contains(author)) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
}
String spacer = mContext.getString(R.string.submission_properties_seperator);
if (comment.getDataNode().has("subreddit") && !comment.getDataNode().get("subreddit").isNull()) {
titleString.append(spacer);
String subname = comment.getDataNode().get("subreddit").asText();
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);
}
messageViewHolder.user.setText(titleString);
SpannableStringBuilder b = new SpannableStringBuilder();
if (mContext instanceof Inbox && comment.getCreated().getTime() > ((Inbox) mContext).last && !comment.isRead()) {
SpannableStringBuilder tagNew = new SpannableStringBuilder("\u00A0NEW\u00A0");
tagNew.setSpan(new RoundedBackgroundSpan(Color.WHITE, mContext.getResources().getColor(R.color.md_green_400), true, mContext), 0, tagNew.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(tagNew);
b.append(" ");
}
b.append(comment.getSubject());
if (comment.getDataNode().has("link_title")) {
SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(link);
}
messageViewHolder.title.setText(b);
if (comment.isRead()) {
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
} else {
messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
}
messageViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
final int color = ta.getColor(0, Color.WHITE);
Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
final Drawable reply = mContext.getResources().getDrawable(R.drawable.reply);
Drawable unhide = mContext.getResources().getDrawable(R.drawable.ic_visibility);
Drawable hide = mContext.getResources().getDrawable(R.drawable.hide);
Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
Drawable reddit = mContext.getResources().getDrawable(R.drawable.commentchange);
profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
reply.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
unhide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(Html.fromHtml(comment.getSubject()));
String author = comment.getAuthor();
if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
}
if (comment.getAuthor() != null) {
b.sheet(1, profile, "/u/" + author);
}
String read = mContext.getString(R.string.mail_mark_read);
Drawable rDrawable = hide;
if (comment.isRead()) {
read = mContext.getString(R.string.mail_mark_unread);
rDrawable = unhide;
}
b.sheet(2, rDrawable, read);
b.sheet(3, reply, mContext.getString(R.string.btn_reply));
b.sheet(25, copy, mContext.getString(R.string.misc_copy_text));
if (comment.isComment()) {
b.sheet(30, reddit, mContext.getString(R.string.mail_view_full_thread));
}
final String finalAuthor = author;
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, finalAuthor);
mContext.startActivity(i);
}
break;
case 2:
{
if (comment.isRead()) {
comment.read = false;
new AsyncSetRead(false).execute(comment);
messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
} else {
comment.read = true;
new AsyncSetRead(true).execute(comment);
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
}
}
break;
case 3:
{
doInboxReply(comment);
}
break;
case 25:
{
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Message", comment.getBody());
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, mContext.getString(R.string.mail_message_copied), Toast.LENGTH_SHORT).show();
}
break;
case 30:
{
String context = comment.getDataNode().get("context").asText();
new OpenRedditLink(mContext, "https://reddit.com" + context.substring(0, context.lastIndexOf("/")));
}
break;
}
}
}).show();
return true;
}
});
messageViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (comment.isRead()) {
if (comment instanceof PrivateMessage) {
DataShare.sharedMessage = (PrivateMessage) comment;
Intent i = new Intent(mContext, SendMessage.class);
i.putExtra(SendMessage.EXTRA_NAME, comment.getAuthor());
i.putExtra(SendMessage.EXTRA_REPLY, true);
mContext.startActivity(i);
} else {
new OpenRedditLink(mContext, comment.getDataNode().get("context").asText());
}
} else {
comment.read = true;
new AsyncSetRead(true).execute(comment);
messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
{
SpannableStringBuilder b = new SpannableStringBuilder(comment.getSubject());
if (comment.getDataNode().has("link_title")) {
SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(link);
}
messageViewHolder.title.setText(b);
}
}
}
});
// Set typeface for body
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
messageViewHolder.content.setTypeface(typeface);
setViews(comment.getDataNode().get("body_html").asText(), "FORCE_LINK_CLICK", messageViewHolder);
}
if (viewHolder instanceof SpacerViewHolder) {
viewHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(viewHolder.itemView.getWidth(), ((Activity) mContext).findViewById(R.id.header).getHeight()));
}
}
use of me.ccrama.redditslide.Views.RoundedBackgroundSpan in project Slide by ccrama.
the class ModLogAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (firstHold instanceof ModLogViewHolder) {
ModLogViewHolder holder = (ModLogViewHolder) firstHold;
final ModAction a = dataSet.posts.get(i);
SpannableStringBuilder b = new SpannableStringBuilder();
SpannableStringBuilder titleString = new SpannableStringBuilder();
String spacer = mContext.getString(R.string.submission_properties_seperator);
String timeAgo = TimeUtils.getTimeAgo(a.getCreated().getTime(), mContext);
String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : // some users were crashing here
timeAgo);
titleString.append(time);
titleString.append(spacer);
if (a.getSubreddit() != null) {
String subname = a.getSubreddit();
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);
}
b.append(titleString);
b.append(spacer);
SpannableStringBuilder author = new SpannableStringBuilder(a.getModerator());
final int authorcolor = Palette.getFontColorUser(a.getModerator());
author.setSpan(new TypefaceSpan("sans-serif-condensed"), 0, author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
author.setSpan(new StyleSpan(Typeface.BOLD), 0, author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (Authentication.name != null && a.getModerator().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
author.replace(0, author.length(), " " + a.getModerator() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, 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);
}
author.setSpan(new RelativeSizeSpan(0.8f), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(author);
b.append("\n\n");
b.append(a.getAction() + " " + (!a.getDataNode().get("target_title").isNull() ? "\"" + a.getDataNode().get("target_title").asText() + "\"" : "") + (a.getTargetAuthor() != null ? " by /u/" + a.getTargetAuthor() : ""));
if (a.getTargetPermalink() != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenRedditLink.openUrl(mContext, a.getTargetPermalink(), true);
}
});
}
if (a.getDetails() != null) {
SpannableStringBuilder description = new SpannableStringBuilder(" (" + a.getDetails() + ")");
description.setSpan(new StyleSpan(Typeface.ITALIC), 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
description.setSpan(new RelativeSizeSpan(0.8f), 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
b.append(description);
}
holder.body.setText(b);
String action = a.getAction();
if (action.equals("removelink")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.close, null));
} else if (action.equals("approvecomment")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.support, null));
} else if (action.equals("removecomment")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null));
} else if (action.equals("approvelink")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.support, null));
} else if (action.equals("editflair")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.flair, null));
} else if (action.equals("distinguish")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null));
} else if (action.equals("sticky")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.lock, null));
} else if (action.equals("unsticky")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.lock, null));
} else if (action.equals("ignorereports")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ignore, null));
} else if (action.equals("unignorereports")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.unignore, null));
} else if (action.equals("marknsfw")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null));
} else if (action.equals("unmarknsfw")) {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null));
} else {
holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.mod, null));
}
}
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 me.ccrama.redditslide.Views.RoundedBackgroundSpan in project Slide by ccrama.
the class SubmissionCache method getCrosspostSpannable.
private static SpannableStringBuilder getCrosspostSpannable(Submission s, Context mContext) {
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder("Crosspost" + spacer);
JsonNode json = s.getDataNode();
if (!json.has("crosspost_parent_list") || json.get("crosspost_parent_list") == null) {
// is not a crosspost
return null;
}
json = json.get("crosspost_parent_list").get(0);
if (json.has("subreddit")) {
String subname = json.get("subreddit").asText().toLowerCase(Locale.ENGLISH);
SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname + spacer);
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor()) || (SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
if (!SettingValues.colorEverywhere) {
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);
}
SpannableStringBuilder author = new SpannableStringBuilder(json.get("author").asText() + " ");
int authorcolor = Palette.getFontColorUser(json.get("author").asText());
if (authorcolor != 0) {
author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(author);
if (UserTags.isUserTagged(json.get("author").asText())) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(json.get("author").asText()) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
}
if (UserSubscriptions.friends.contains(json.get("author").asText())) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
}
return titleString;
}
use of me.ccrama.redditslide.Views.RoundedBackgroundSpan in project Slide by ccrama.
the class SubmissionCache method getInfoSpannable.
private static SpannableStringBuilder getInfoSpannable(Submission submission, Context mContext, String baseSub) {
String spacer = mContext.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
SpannableStringBuilder subreddit = new SpannableStringBuilder(" /r/" + submission.getSubredditName() + " ");
if (submission.getSubredditName() == null) {
subreddit = new SpannableStringBuilder("Promoted ");
}
String subname;
if (submission.getSubredditName() != null) {
subname = submission.getSubredditName().toLowerCase(Locale.ENGLISH);
} else {
subname = "";
}
if (baseSub == null || baseSub.isEmpty())
baseSub = subname;
if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor()) || (baseSub.equals("nomatching") && (SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor()))) {
boolean secondary = (baseSub.equalsIgnoreCase("frontpage") || (baseSub.equalsIgnoreCase("all")) || (baseSub.equalsIgnoreCase("popular")) || (baseSub.equalsIgnoreCase("friends")) || (baseSub.equalsIgnoreCase("mod")) || baseSub.contains(".") || baseSub.contains("+"));
if (!secondary && !SettingValues.colorEverywhere || secondary) {
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);
titleString.append(spacer);
try {
String time = TimeUtils.getTimeAgo(submission.getCreated().getTime(), mContext);
titleString.append(time);
} catch (Exception e) {
titleString.append("just now");
}
titleString.append(((submission.getEdited() != null) ? " (edit " + TimeUtils.getTimeAgo(submission.getEdited().getTime(), mContext) + ")" : ""));
titleString.append(spacer);
SpannableStringBuilder author = new SpannableStringBuilder(" " + submission.getAuthor() + " ");
int authorcolor = Palette.getFontColorUser(submission.getAuthor());
if (submission.getAuthor() != null) {
if (Authentication.name != null && submission.getAuthor().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (submission.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_red_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (submission.getDistinguishedStatus() == DistinguishedStatus.SPECIAL) {
author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_purple_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (submission.getDistinguishedStatus() == DistinguishedStatus.MODERATOR) {
author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_green_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);
}
titleString.append(author);
}
if (UserTags.isUserTagged(submission.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(submission.getAuthor()) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (UserSubscriptions.friends.contains(submission.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
/* too big, might add later todo
if (submission.getAuthorFlair() != null && submission.getAuthorFlair().getText() != null && !submission.getAuthorFlair().getText().isEmpty()) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = mContext.getTheme();
theme.resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + submission.getAuthorFlair().getText() + " ");
pinned.setSpan(new RoundedBackgroundSpan(holder.title.getCurrentTextColor(), color, false, mContext), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (holder.leadImage.getVisibility() == View.GONE && !full) {
String text = "";
switch (ContentType.getContentType(submission)) {
case NSFW_IMAGE:
text = mContext.getString(R.string.type_nsfw_img);
break;
case NSFW_GIF:
case NSFW_GFY:
text = mContext.getString(R.string.type_nsfw_gif);
break;
case REDDIT:
text = mContext.getString(R.string.type_reddit);
break;
case LINK:
case IMAGE_LINK:
text = mContext.getString(R.string.type_link);
break;
case NSFW_LINK:
text = mContext.getString(R.string.type_nsfw_link);
break;
case STREAMABLE:
text = ("Streamable");
break;
case SELF:
text = ("Selftext");
break;
case ALBUM:
text = mContext.getString(R.string.type_album);
break;
case IMAGE:
text = mContext.getString(R.string.type_img);
break;
case IMGUR:
text = mContext.getString(R.string.type_imgur);
break;
case GFY:
case GIF:
case NONE_GFY:
case NONE_GIF:
text = mContext.getString(R.string.type_gif);
break;
case NONE:
text = mContext.getString(R.string.type_title_only);
break;
case NONE_IMAGE:
text = mContext.getString(R.string.type_img);
break;
case VIDEO:
text = mContext.getString(R.string.type_vid);
break;
case EMBEDDED:
text = mContext.getString(R.string.type_emb);
break;
case NONE_URL:
text = mContext.getString(R.string.type_link);
break;
}
if(!text.isEmpty()) {
titleString.append(" \n");
text = text.toUpperCase();
TypedValue typedValue = new TypedValue();
Resources.Theme theme = mContext.getTheme();
theme.resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
SpannableStringBuilder pinned = new SpannableStringBuilder(" " + text + " ");
pinned.setSpan(new RoundedBackgroundSpan(holder.title.getCurrentTextColor(), color, false, mContext), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
}
}*/
if (SettingValues.showDomain) {
titleString.append(spacer);
titleString.append(submission.getDomain());
}
if (SettingValues.typeInfoLine) {
titleString.append(spacer);
SpannableStringBuilder s = new SpannableStringBuilder(ContentType.getContentDescription(submission, mContext));
s.setSpan(new StyleSpan(Typeface.BOLD), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(s);
}
if (SettingValues.votesInfoLine) {
titleString.append("\n ");
SpannableStringBuilder s = new SpannableStringBuilder(submission.getScore() + String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.points, submission.getScore())) + spacer + submission.getCommentCount() + String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.comments, submission.getCommentCount())));
s.setSpan(new StyleSpan(Typeface.BOLD), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (SettingValues.commentLastVisit) {
final int more = LastComments.commentsSince(submission);
s.append(more > 0 ? "(+" + more + ")" : "");
}
titleString.append(s);
}
if (removed.contains(submission.getFullName()) || (submission.getBannedBy() != null && !approved.contains(submission.getFullName()))) {
titleString.append(CommentAdapterHelper.createRemovedLine((submission.getBannedBy() == null) ? Authentication.name : submission.getBannedBy(), mContext));
} else if (approved.contains(submission.getFullName()) || (submission.getApprovedBy() != null && !removed.contains(submission.getFullName()))) {
titleString.append(CommentAdapterHelper.createApprovedLine((submission.getApprovedBy() == null) ? Authentication.name : submission.getApprovedBy(), mContext));
}
return titleString;
}
use of me.ccrama.redditslide.Views.RoundedBackgroundSpan in project Slide by ccrama.
the class PopulateShadowboxInfo method doActionbar.
public static void doActionbar(final CommentNode node, final View rootView, final Activity c, boolean extras) {
final Comment s = node.getComment();
TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title);
TextView desc = (TextView) rootView.findViewById(R.id.desc);
String distingush = "";
if (s != null) {
if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR)
distingush = "[M]";
else if (s.getDistinguishedStatus() == DistinguishedStatus.ADMIN)
distingush = "[A]";
SpannableStringBuilder commentTitle = new SpannableStringBuilder();
SpannableStringBuilder level = new SpannableStringBuilder();
if (!node.isTopLevel()) {
level.append("[" + node.getDepth() + "] ");
level.setSpan(new RelativeSizeSpan(0.7f), 0, level.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
commentTitle.append(level);
}
commentTitle.append(Html.fromHtml(s.getDataNode().get("body_html").asText().trim()));
title.setTextHtml(commentTitle);
title.setMaxLines(3);
String spacer = c.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
SpannableStringBuilder author = new SpannableStringBuilder(" /u/" + s.getAuthor() + " ");
int authorcolor = Palette.getFontColorUser(s.getAuthor());
if (Authentication.name != null && s.getAuthor().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR || s.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_green_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);
}
titleString.append(author);
titleString.append(distingush);
titleString.append(spacer);
titleString.append(TimeUtils.getTimeAgo(s.getCreated().getTime(), c));
desc.setText(titleString);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
if (extras) {
final ImageView downvotebutton = (ImageView) rootView.findViewById(R.id.downvote);
final ImageView upvotebutton = (ImageView) rootView.findViewById(R.id.upvote);
if (s.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);
}
switch(ActionStates.getVoteDirection(s)) {
case UPVOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : 1))));
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
case DOWNVOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : -1))));
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
case NO_VOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(((TextView) rootView.findViewById(R.id.comments)).getCurrentTextColor());
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
}
}
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (ActionStates.isSaved(s)) {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
rootView.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
if (ActionStates.isSaved(s)) {
new AccountManager(Authentication.reddit).unsave(s);
ActionStates.setSaved(s, false);
} else {
new AccountManager(Authentication.reddit).save(s);
ActionStates.setSaved(s, true);
}
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.isSaved(s)) {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, rootView.findViewById(R.id.save), ContextCompat.getColor(c, R.color.md_amber_500));
} else {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
}
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
rootView.findViewById(R.id.save).setVisibility(View.GONE);
}
try {
final TextView points = ((TextView) rootView.findViewById(R.id.score));
final TextView comments = ((TextView) rootView.findViewById(R.id.comments));
if (Authentication.isLoggedIn && Authentication.didOnline) {
{
downvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.getVoteDirection(s) != VoteDirection.DOWNVOTE) {
// has not been downvoted
points.setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, downvotebutton, ContextCompat.getColor(c, R.color.md_blue_500));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
// if a post is at 0 votes, keep it at 0 when downvoting
final int downvoteScore = (s.getScore() == 0) ? 0 : s.getScore() - 1;
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", downvoteScore));
new Vote(false, points, c).execute(s);
ActionStates.setVoteDirection(s, VoteDirection.DOWNVOTE);
} else {
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, c).execute(s);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
});
}
{
upvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.getVoteDirection(s) != VoteDirection.UPVOTE) {
// has not been upvoted
points.setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, upvotebutton, ContextCompat.getColor(c, R.color.md_orange_500));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore() + 1));
new Vote(true, points, c).execute(s);
ActionStates.setVoteDirection(s, VoteDirection.UPVOTE);
} else {
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, c).execute(s);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
});
}
} else {
upvotebutton.setVisibility(View.GONE);
downvotebutton.setVisibility(View.GONE);
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}
}
Aggregations