use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class TumblrView method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder2, int i) {
if (holder2 instanceof AlbumViewHolder) {
final int position = paddingBottom ? i : i - 1;
AlbumViewHolder holder = (AlbumViewHolder) holder2;
final Photo user = users.get(position);
((Reddit) main.getApplicationContext()).getImageLoader().displayImage(user.getOriginalSize().getUrl(), holder.image, ImageGridAdapter.options);
holder.body.setVisibility(View.VISIBLE);
holder.text.setVisibility(View.VISIBLE);
View imageView = holder.image;
if (imageView.getWidth() == 0) {
holder.image.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
} else {
holder.image.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) getHeightFromAspectRatio(user.getOriginalSize().getHeight(), user.getOriginalSize().getWidth(), imageView.getWidth())));
}
{
int type = new FontPreferences(holder.body.getContext()).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(holder.body.getContext(), type);
} else {
typeface = Typeface.DEFAULT;
}
holder.body.setTypeface(typeface);
}
{
int type = new FontPreferences(holder.body.getContext()).getFontTypeTitle().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(holder.body.getContext(), type);
} else {
typeface = Typeface.DEFAULT;
}
holder.text.setTypeface(typeface);
}
{
holder.text.setVisibility(View.GONE);
}
{
if (user.getCaption() != null) {
List<String> text = SubmissionParser.getBlocks(user.getCaption());
setTextWithLinks(text.get(0), holder.body);
if (holder.body.getText().toString().isEmpty()) {
holder.body.setVisibility(View.GONE);
}
} else {
holder.body.setVisibility(View.GONE);
}
}
View.OnClickListener onGifImageClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (SettingValues.image) {
Intent myIntent = new Intent(main, MediaView.class);
myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
myIntent.putExtra(MediaView.EXTRA_URL, user.getOriginalSize().getUrl());
main.startActivity(myIntent);
} else {
LinkUtil.openExternally(user.getOriginalSize().getUrl(), main);
}
}
};
try {
if (ContentType.isGif(new URI(user.getOriginalSize().getUrl()))) {
holder.body.setVisibility(View.VISIBLE);
holder.body.setSingleLine(false);
// got rid of the \n thing, because it didnt parse and it was already a new line so...
holder.body.setTextHtml(holder.text.getText() + main.getString(R.string.submission_tap_gif).toUpperCase());
holder.body.setOnClickListener(onGifImageClickListener);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
holder.itemView.setOnClickListener(onGifImageClickListener);
} else if (holder2 instanceof SpacerViewHolder) {
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), paddingBottom ? height : main.findViewById(R.id.toolbar).getHeight()));
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class AlbumView method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder2, int i) {
if (holder2 instanceof AlbumViewHolder) {
final int position = paddingBottom ? i : i - 1;
AlbumViewHolder holder = (AlbumViewHolder) holder2;
final Image user = users.get(position);
((Reddit) main.getApplicationContext()).getImageLoader().displayImage(user.getImageUrl(), holder.image, ImageGridAdapter.options);
holder.body.setVisibility(View.VISIBLE);
holder.text.setVisibility(View.VISIBLE);
View imageView = holder.image;
if (imageView.getWidth() == 0) {
holder.image.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
} else {
holder.image.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) getHeightFromAspectRatio(user.getHeight(), user.getWidth(), imageView.getWidth())));
}
{
int type = new FontPreferences(holder.body.getContext()).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(holder.body.getContext(), type);
} else {
typeface = Typeface.DEFAULT;
}
holder.body.setTypeface(typeface);
}
{
int type = new FontPreferences(holder.body.getContext()).getFontTypeTitle().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(holder.body.getContext(), type);
} else {
typeface = Typeface.DEFAULT;
}
holder.text.setTypeface(typeface);
}
{
if (user.getTitle() != null) {
List<String> text = SubmissionParser.getBlocks(user.getTitle());
setTextWithLinks(text.get(0), holder.text);
if (holder.text.getText().toString().isEmpty()) {
holder.text.setVisibility(View.GONE);
}
} else {
holder.text.setVisibility(View.GONE);
}
}
{
if (user.getDescription() != null) {
List<String> text = SubmissionParser.getBlocks(user.getDescription());
setTextWithLinks(text.get(0), holder.body);
if (holder.body.getText().toString().isEmpty()) {
holder.body.setVisibility(View.GONE);
}
} else {
holder.body.setVisibility(View.GONE);
}
}
View.OnClickListener onGifImageClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (SettingValues.image && !user.isAnimated() || SettingValues.gif && user.isAnimated()) {
Intent myIntent = new Intent(main, MediaView.class);
myIntent.putExtra(MediaView.EXTRA_URL, user.getImageUrl());
myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
main.startActivity(myIntent);
} else {
LinkUtil.openExternally(user.getImageUrl(), main);
}
}
};
if (user.isAnimated()) {
holder.body.setVisibility(View.VISIBLE);
holder.body.setSingleLine(false);
// got rid of the \n thing, because it didnt parse and it was already a new line so...
holder.body.setTextHtml(holder.text.getText() + main.getString(R.string.submission_tap_gif).toUpperCase());
holder.body.setOnClickListener(onGifImageClickListener);
}
holder.itemView.setOnClickListener(onGifImageClickListener);
} else if (holder2 instanceof SpacerViewHolder) {
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), paddingBottom ? height : main.findViewById(R.id.toolbar).getHeight()));
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class CommentAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int old) {
int pos = old != 0 ? old - 1 : old;
if (firstHolder instanceof CommentViewHolder) {
final CommentViewHolder holder = (CommentViewHolder) firstHolder;
int datasetPosition = pos - 1;
datasetPosition = getRealPosition(datasetPosition);
if (pos > toShiftTo) {
shifted = 0;
}
if (pos < shiftFrom) {
shifted = 0;
}
final CommentNode baseNode = currentComments.get(datasetPosition).comment;
final Comment comment = baseNode.getComment();
if (pos == getItemCount() - 1) {
holder.itemView.setPadding(0, 0, 0, (int) mContext.getResources().getDimension(R.dimen.overview_top_padding_single));
} else {
holder.itemView.setPadding(0, 0, 0, 0);
}
doScoreText(holder, comment, this);
// Long click listeners
View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
return true;
}
};
holder.firstTextView.setOnLongClickListener(onLongClickListener);
holder.commentOverflow.setOnLongClickListener(onLongClickListener);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
}
return true;
}
});
// Single click listeners
OnSingleClickListener singleClick = new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doLongClick(holder, comment, baseNode);
} else {
doOnClick(holder, comment, baseNode);
}
}
}
};
holder.itemView.setOnClickListener(singleClick);
holder.commentOverflow.setOnClickListener(singleClick);
if (!toCollapse.contains(comment.getFullName()) && SettingValues.collapseComments || !SettingValues.collapseComments) {
setViews(comment.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder, singleClick, onLongClickListener);
}
holder.firstTextView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
SpoilerRobotoTextView SpoilerRobotoTextView = (SpoilerRobotoTextView) v;
if (SettingValues.swap) {
if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doLongClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
} else if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doOnClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
}
});
if (ImageFlairs.isSynced(comment.getSubredditName()) && comment.getAuthorFlair() != null && !comment.getAuthorFlair().getText().isEmpty() && !comment.getAuthorFlair().getCssClass().isEmpty()) {
boolean set = false;
for (String s : comment.getAuthorFlair().getCssClass().split(" ")) {
File file = DiskCacheUtils.findInCache(comment.getSubredditName().toLowerCase(Locale.ENGLISH) + ":" + s.toLowerCase(Locale.ENGLISH), ImageFlairs.getFlairImageLoader(mContext).getInstance().getDiskCache());
if (file != null && file.exists()) {
set = true;
holder.imageFlair.setVisibility(View.VISIBLE);
String decodedImgUri = Uri.fromFile(file).toString();
ImageFlairs.getFlairImageLoader(mContext).displayImage(decodedImgUri, holder.imageFlair);
break;
}
}
if (!set) {
holder.imageFlair.setImageDrawable(null);
holder.imageFlair.setVisibility(View.GONE);
}
} else {
holder.imageFlair.setVisibility(View.GONE);
}
// 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;
}
holder.firstTextView.setTypeface(typeface);
// Show padding on top
if (baseNode.isTopLevel()) {
holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
} else if (holder.itemView.findViewById(R.id.next).getVisibility() == View.VISIBLE) {
holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
}
// Should be collapsed?
if (hiddenPersons.contains(comment.getFullName()) || toCollapse.contains(comment.getFullName())) {
int childnumber = getChildNumber(baseNode);
if (hiddenPersons.contains(comment.getFullName()) && childnumber > 0) {
holder.childrenNumber.setVisibility(View.VISIBLE);
holder.childrenNumber.setText("+" + childnumber);
} else {
holder.childrenNumber.setVisibility(View.GONE);
}
if (SettingValues.collapseComments && toCollapse.contains(comment.getFullName())) {
holder.firstTextView.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.GONE);
}
} else {
holder.childrenNumber.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.VISIBLE);
}
holder.dot.setVisibility(View.VISIBLE);
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
// Padding on the left, starting with the third comment
for (int i = 2; i < baseNode.getDepth(); i++) {
width += dwidth;
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) holder.dot.getLayoutParams();
params2.width = dwidth;
holder.dot.setLayoutParams(params2);
if (baseNode.getDepth() - 1 > 0) {
int i22 = baseNode.getDepth() - 2;
String commentOp = dataSet.commentOPs.get(comment.getId());
if (SettingValues.highlightCommentOP && commentOp != null && comment != null && commentOp.equals(comment.getAuthor())) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_purple_500));
} else {
if (i22 % 5 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_700 : R.color.md_blue_500));
} else if (i22 % 4 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_600 : R.color.md_green_500));
} else if (i22 % 3 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_500 : R.color.md_yellow_500));
} else if (i22 % 2 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_400 : R.color.md_orange_500));
} else {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_300 : R.color.md_red_500));
}
}
} else {
holder.dot.setVisibility(View.GONE);
}
if (currentSelectedItem != null && comment.getFullName().contains(currentSelectedItem) && !currentSelectedItem.isEmpty() && !currentlyEditingId.equals(comment.getFullName())) {
doHighlighted(holder, comment, baseNode, false);
} else if (!currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
}
if (deleted.contains(comment.getFullName())) {
holder.firstTextView.setText(R.string.comment_deleted);
holder.content.setText(R.string.comment_deleted);
}
if (currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
setCommentStateHighlighted(holder, comment, baseNode, true, false);
}
} else if (firstHolder instanceof SubmissionViewHolder && submission != null) {
submissionViewHolder = (SubmissionViewHolder) firstHolder;
new PopulateSubmissionViewHolder().populateSubmissionViewHolder((SubmissionViewHolder) firstHolder, submission, (Activity) mContext, true, true, null, listView, false, false, null, this);
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (submission.isArchived() || submission.isLocked()) {
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
} else {
firstHolder.itemView.findViewById(R.id.reply).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
doReplySubmission(firstHolder);
}
});
firstHolder.itemView.findViewById(R.id.discard).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
currentlyEditing = null;
editingPosition = -1;
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
}
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
currentlyEditingId = "";
backedText = "";
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
}
} else {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
}
firstHolder.itemView.findViewById(R.id.more).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.menu).callOnClick();
}
});
} else if (firstHolder instanceof MoreCommentViewHolder) {
final MoreCommentViewHolder holder = (MoreCommentViewHolder) firstHolder;
int nextPos = pos - 1;
nextPos = getRealPosition(nextPos);
final MoreChildItem baseNode = (MoreChildItem) currentComments.get(nextPos);
if (baseNode.children.getCount() > 0) {
try {
holder.content.setText(mContext.getString(R.string.comment_load_more_string_new, baseNode.children.getLocalizedCount()));
} catch (Exception e) {
holder.content.setText(R.string.comment_load_more_number_unknown);
}
} else if (!baseNode.children.getChildrenIds().isEmpty()) {
holder.content.setText(R.string.comment_load_more_number_unknown);
} else {
holder.content.setText(R.string.thread_continue);
}
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
for (int i = 1; i < baseNode.comment.getDepth(); i++) {
width += dwidth;
}
final View progress = holder.loading;
progress.setVisibility(View.GONE);
final int finalNextPos = nextPos;
holder.content.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (baseNode.children.getChildrenIds().isEmpty()) {
String toGoTo = "https://reddit.com" + submission.getPermalink() + baseNode.comment.getComment().getId() + "?context=0";
new OpenRedditLink(mContext, toGoTo, true);
} else if (progress.getVisibility() == View.GONE) {
progress.setVisibility(View.VISIBLE);
holder.content.setText(R.string.comment_loading_more);
currentLoading = new AsyncLoadMore(getRealPosition(holder.getAdapterPosition() - 2), holder.getAdapterPosition(), holder, finalNextPos, baseNode.comment.getComment().getFullName());
currentLoading.execute(baseNode);
}
}
});
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
}
if (firstHolder instanceof SpacerViewHolder) {
// Make a space the size of the toolbar minus 1 so there isn't a gap
firstHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (Constants.SINGLE_HEADER_VIEW_OFFSET - Reddit.dpToPxVertical(1) + mPage.shownHeaders)));
}
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class CommentAdapterHelper method getScoreString.
public static Spannable getScoreString(Comment comment, Context mContext, CommentViewHolder holder, Submission submission, CommentAdapter adapter) {
final String spacer = " " + mContext.getString(R.string.submission_properties_seperator_comments) + " ";
SpannableStringBuilder titleString = // zero width space to fix first span height
new SpannableStringBuilder("\u200B");
SpannableStringBuilder author = new SpannableStringBuilder(comment.getAuthor());
final int authorcolor = Palette.getFontColorUser(comment.getAuthor());
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 (comment.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, 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, 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, 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, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (submission != null && comment.getAuthor().toLowerCase(Locale.ENGLISH).equals(submission.getAuthor().toLowerCase(Locale.ENGLISH)) && !comment.getAuthor().equals("[deleted]")) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_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(spacer);
int scoreColor;
switch(ActionStates.getVoteDirection(comment)) {
case UPVOTE:
scoreColor = (holder.textColorUp);
break;
case DOWNVOTE:
scoreColor = (holder.textColorDown);
break;
default:
scoreColor = (holder.textColorRegular);
break;
}
String scoreText;
if (comment.isScoreHidden()) {
scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
} else {
scoreText = String.format(Locale.getDefault(), "%d", getScoreText(comment));
}
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())));
}
score.setSpan(new ForegroundColorSpan(scoreColor), 0, score.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(score);
titleString.append((comment.isControversial() ? " †" : ""));
titleString.append(spacer);
Long time = comment.getCreated().getTime();
String timeAgo = TimeUtils.getTimeAgo(time, mContext);
SpannableStringBuilder timeSpan = new SpannableStringBuilder().append((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
if (SettingValues.highlightTime && adapter.lastSeen != 0 && adapter.lastSeen < time && !adapter.dataSet.single && SettingValues.commentLastVisit) {
timeSpan.setSpan(new RoundedBackgroundSpan(Color.WHITE, Palette.getColor(comment.getSubredditName()), false, mContext), 0, timeSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(timeSpan);
titleString.append(((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(" ");
if (comment.getDataNode().get("stickied").asBoolean()) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + mContext.getString(R.string.submission_stickied).toUpperCase() + "\u00A0");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_green_300, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (comment.getTimesGilded() > 0) {
// if the comment has only been gilded once, don't show a number
final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
a.recycle();
Bitmap image = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gold);
float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
gilded.setSpan(new ImageSpan(mContext, image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(gilded);
titleString.append(" ");
}
if (UserTags.isUserTagged(comment.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + UserTags.getUserTag(comment.getAuthor()) + "\u00A0");
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(comment.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + mContext.getString(R.string.profile_friend) + "\u00A0");
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(" ");
}
if (comment.getAuthorFlair() != null) {
String flairText;
if (comment.getAuthorFlair().getText() != null && !comment.getAuthorFlair().getText().isEmpty()) {
flairText = comment.getAuthorFlair().getText();
} else {
flairText = comment.getAuthorFlair().getCssClass();
}
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("\u00A0" + Html.fromHtml(flairText) + "\u00A0");
pinned.setSpan(new RoundedBackgroundSpan(holder.firstTextView.getCurrentTextColor(), color, false, mContext), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (adapter.removed.contains(comment.getFullName()) || (comment.getBannedBy() != null && !adapter.approved.contains(comment.getFullName()))) {
titleString.append(CommentAdapterHelper.createRemovedLine((comment.getBannedBy() == null) ? Authentication.name : comment.getBannedBy(), mContext));
} else if (adapter.approved.contains(comment.getFullName()) || (comment.getApprovedBy() != null && !adapter.removed.contains(comment.getFullName()))) {
titleString.append(CommentAdapterHelper.createApprovedLine((comment.getApprovedBy() == null) ? Authentication.name : comment.getApprovedBy(), mContext));
}
return titleString;
}
use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.
the class CommentAdapterSearch method doScoreText.
public void doScoreText(CommentViewHolder holder, Comment comment, int offset) {
String spacer = " " + mContext.getString(R.string.submission_properties_seperator_comments) + " ";
SpannableStringBuilder titleString = new SpannableStringBuilder();
SpannableStringBuilder author = new SpannableStringBuilder(comment.getAuthor());
final int authorcolor = Palette.getFontColorUser(comment.getAuthor());
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 (comment.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(new RoundedBackgroundSpan(mContext, 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, 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, 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, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else /* todoelse if (submission != null && comment.getAuthor()
.toLowerCase(Locale.ENGLISH)
.equals(submission.getAuthor().toLowerCase(Locale.ENGLISH)) && !comment.getAuthor().equals("[deleted]")) {
author.replace(0, author.length(), " " + comment.getAuthor() + " ");
author.setSpan(
new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_300, false),
0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} */
if (authorcolor != 0) {
author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(author);
titleString.append(spacer);
String scoreText;
if (comment.isScoreHidden()) {
scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
} else {
scoreText = String.format(Locale.getDefault(), "%d", comment.getScore() + offset);
}
SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
titleString.append(score);
if (!scoreText.contains("[")) {
titleString.append(mContext.getResources().getQuantityString(R.plurals.points, comment.getScore()));
}
titleString.append((comment.isControversial() ? " †" : ""));
titleString.append(spacer);
String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
titleString.append((timeAgo == null || timeAgo.isEmpty()) ? "just now" : // some users were crashing here
timeAgo);
titleString.append(((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
titleString.append(" ");
if (comment.getDataNode().get("stickied").asBoolean()) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + mContext.getString(R.string.submission_stickied).toUpperCase() + "\u00A0");
pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_green_300, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
if (UserTags.isUserTagged(comment.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + UserTags.getUserTag(comment.getAuthor()) + "\u00A0");
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 (comment.getTimesGilded() > 0) {
final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
a.recycle();
Bitmap image = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gold);
float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
gilded.setSpan(new ImageSpan(mContext, image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(gilded);
titleString.append(" ");
}
if (UserSubscriptions.friends.contains(comment.getAuthor())) {
SpannableStringBuilder pinned = new SpannableStringBuilder("\u00A0" + mContext.getString(R.string.profile_friend) + "\u00A0");
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(" ");
}
if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().getText().isEmpty() && !comment.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("\u00A0" + Html.fromHtml(comment.getAuthorFlair().getText()) + "\u00A0");
pinned.setSpan(new RoundedBackgroundSpan(holder.firstTextView.getCurrentTextColor(), color, false, mContext), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleString.append(pinned);
titleString.append(" ");
}
holder.content.setText(titleString);
}
Aggregations