diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 06b8e60b..1012317d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -87,7 +87,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { private PollAdapter pollAdapter; - private boolean useAbsoluteTime; private SimpleDateFormat shortSdf; private SimpleDateFormat longSdf; @@ -145,7 +144,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { pollOptions.setLayoutManager(new LinearLayoutManager(pollOptions.getContext())); ((DefaultItemAnimator) pollOptions.getItemAnimator()).setSupportsChangeAnimations(false); - this.useAbsoluteTime = useAbsoluteTime; this.shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); this.longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); @@ -182,11 +180,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { @Nullable Status.Mention[] mentions, @NonNull List emojis, @Nullable PollViewData poll, + @NonNull StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) { if (TextUtils.isEmpty(spoilerText)) { contentWarningDescription.setVisibility(View.GONE); contentWarningButton.setVisibility(View.GONE); - this.setTextVisible(true, content, mentions, emojis, poll, listener); + this.setTextVisible(true, content, mentions, emojis, poll, statusDisplayOptions, listener); } else { CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription); contentWarningDescription.setText(emojiSpoiler); @@ -198,9 +197,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { if (getAdapterPosition() != RecyclerView.NO_POSITION) { listener.onExpandedChange(isChecked, getAdapterPosition()); } - this.setTextVisible(isChecked, content, mentions, emojis, poll, listener); + this.setTextVisible(isChecked, content, mentions, emojis, poll, statusDisplayOptions, listener); }); - this.setTextVisible(expanded, content, mentions, emojis, poll, listener); + this.setTextVisible(expanded, content, mentions, emojis, poll, statusDisplayOptions, listener); } } @@ -209,12 +208,13 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { Status.Mention[] mentions, List emojis, @Nullable PollViewData poll, + StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) { if (expanded) { Spanned emojifiedText = CustomEmojiHelper.emojifyText(content, emojis, this.content); LinkHelper.setClickableText(this.content, emojifiedText, mentions, listener); if (poll != null) { - setupPoll(poll, emojis, listener); + setupPoll(poll, emojis, statusDisplayOptions, listener); } else { hidePoll(); } @@ -274,8 +274,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } - protected void setCreatedAt(Date createdAt) { - if (useAbsoluteTime) { + protected void setCreatedAt(Date createdAt, StatusDisplayOptions statusDisplayOptions) { + if (statusDisplayOptions.useAbsoluteTime()) { timestampInfo.setText(getAbsoluteTime(createdAt)); } else { if (createdAt == null) { @@ -300,8 +300,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } } - private CharSequence getCreatedAtDescription(Date createdAt) { - if (useAbsoluteTime) { + private CharSequence getCreatedAtDescription(Date createdAt, + StatusDisplayOptions statusDisplayOptions) { + if (statusDisplayOptions.useAbsoluteTime()) { return getAbsoluteTime(createdAt); } else { /* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m" @@ -646,7 +647,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { if (payloads == null) { setDisplayName(status.getUserFullName(), status.getAccountEmojis()); setUsername(status.getNickname()); - setCreatedAt(status.getCreatedAt()); + setCreatedAt(status.getCreatedAt(), statusDisplayOptions); setIsReply(status.getInReplyToId() != null); setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot(), statusDisplayOptions); setReblogged(status.isReblogged()); @@ -677,9 +678,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { setupButtons(listener, status.getSenderId()); setRebloggingEnabled(status.getRebloggingEnabled(), status.getVisibility()); - setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getStatusEmojis(), status.getPoll(), listener); + setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getStatusEmojis(), status.getPoll(), statusDisplayOptions, listener); - setDescriptionForStatus(status); + setDescriptionForStatus(status, statusDisplayOptions); // Workaround for RecyclerView 1.0.0 / androidx.core 1.0.0 // RecyclerView tries to set AccessibilityDelegateCompat to null @@ -691,7 +692,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { if (payloads instanceof List) for (Object item : (List) payloads) { if (Key.KEY_CREATED.equals(item)) { - setCreatedAt(status.getCreatedAt()); + setCreatedAt(status.getCreatedAt(), statusDisplayOptions); } } @@ -707,14 +708,15 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { return false; } - private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status) { + private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status, + StatusDisplayOptions statusDisplayOptions) { Context context = itemView.getContext(); String description = context.getString(R.string.description_status, status.getUserFullName(), getContentWarningDescription(context, status), (TextUtils.isEmpty(status.getSpoilerText()) || !status.isSensitive() || status.isExpanded() ? status.getContent() : ""), - getCreatedAtDescription(status.getCreatedAt()), + getCreatedAtDescription(status.getCreatedAt(), statusDisplayOptions), getReblogDescription(context, status), status.getNickname(), status.isReblogged() ? context.getString(R.string.description_status_reblogged) : "", @@ -724,7 +726,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { getVisibilityDescription(context, status.getVisibility()), getFavsText(context, status.getFavouritesCount()), getReblogsText(context, status.getReblogsCount()), - getPollDescription(context, status) + getPollDescription(status, context, statusDisplayOptions) ); itemView.setContentDescription(description); } @@ -796,8 +798,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { return context.getString(resource); } - private CharSequence getPollDescription(Context context, - @NonNull StatusViewData.Concrete status) { + private CharSequence getPollDescription(@NonNull StatusViewData.Concrete status, + Context context, + StatusDisplayOptions statusDisplayOptions) { PollViewData poll = status.getPoll(); if (poll == null) { return ""; @@ -812,7 +815,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { args[i] = ""; } } - args[4] = getPollInfoText(System.currentTimeMillis(), poll, context); + args[4] = getPollInfoText(System.currentTimeMillis(), poll, statusDisplayOptions, + context); return context.getString(R.string.description_poll, args); } } @@ -835,7 +839,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } } - private void setupPoll(PollViewData poll, List emojis, StatusActionListener listener) { + private void setupPoll(PollViewData poll, List emojis, + StatusDisplayOptions statusDisplayOptions, + StatusActionListener listener) { long timestamp = System.currentTimeMillis(); boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime()); @@ -872,10 +878,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } pollDescription.setVisibility(View.VISIBLE); - pollDescription.setText(getPollInfoText(timestamp, poll, context)); + pollDescription.setText(getPollInfoText(timestamp, poll, statusDisplayOptions, context)); } - private CharSequence getPollInfoText(long timestamp, PollViewData poll, Context context) { + private CharSequence getPollInfoText(long timestamp, PollViewData poll, + StatusDisplayOptions statusDisplayOptions, + Context context) { String votes = numberFormat.format(poll.getVotesCount()); String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes); CharSequence pollDurationInfo; @@ -884,7 +892,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } else if (poll.getExpiresAt() == null) { return votesText; } else { - if (useAbsoluteTime) { + if (statusDisplayOptions.useAbsoluteTime()) { pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt())); } else { String pollDuration = TimestampUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java index 771002ae..06b8aaf6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java @@ -4,11 +4,8 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.graphics.drawable.Drawable; -import android.text.SpannableStringBuilder; -import android.text.Spanned; import android.text.TextUtils; import android.text.method.LinkMovementMethod; -import android.text.style.URLSpan; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -26,7 +23,6 @@ import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Card; import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.interfaces.StatusActionListener; -import com.keylesspalace.tusky.util.CustomURLSpan; import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.viewdata.StatusViewData; @@ -66,8 +62,8 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { } @Override - protected void setCreatedAt(Date createdAt) { - if(createdAt == null) { + protected void setCreatedAt(Date createdAt, StatusDisplayOptions statusDisplayOptions) { + if (createdAt == null) { timestampInfo.setText(""); } else { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT); @@ -154,11 +150,11 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { final Card card = status.getCard(); cardView.setVisibility(View.VISIBLE); cardTitle.setText(card.getTitle()); - if(TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) { + if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) { cardDescription.setVisibility(View.GONE); } else { cardDescription.setVisibility(View.VISIBLE); - if(TextUtils.isEmpty(card.getDescription())) { + if (TextUtils.isEmpty(card.getDescription())) { cardDescription.setText(card.getAuthorName()); } else { cardDescription.setText(card.getDescription()); @@ -199,7 +195,6 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { } - Glide.with(cardImage) .load(card.getImage()) .transform( @@ -232,7 +227,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder { private void setStatusVisibility(Status.Visibility visibility) { - if(visibility == null) { + if (visibility == null) { return; } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java index c759c06c..c0e1a3d2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java @@ -77,7 +77,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder { setDisplayName(account.getDisplayName(), account.getEmojis()); setUsername(account.getUsername()); - setCreatedAt(status.getCreatedAt()); + setCreatedAt(status.getCreatedAt(), statusDisplayOptions); setIsReply(status.getInReplyToId() != null); setFavourited(status.getFavourited()); setBookmarked(status.getBookmarked()); @@ -106,7 +106,9 @@ public class ConversationViewHolder extends StatusBaseViewHolder { setupButtons(listener, account.getId()); - setSpoilerAndContent(status.getExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getEmojis(), PollViewDataKt.toViewData(status.getPoll()), listener); + setSpoilerAndContent(status.getExpanded(), status.getContent(), status.getSpoilerText(), + status.getMentions(), status.getEmojis(), + PollViewDataKt.toViewData(status.getPoll()), statusDisplayOptions, listener); setConversationName(conversation.getAccounts());