Fix missing cases of using StatusDisplayOptions (#1614)

This commit is contained in:
Ivan Kupalov 2020-01-03 20:22:02 +01:00 committed by Konrad Pozniak
parent 4a9c1288d0
commit 426e7edb73
3 changed files with 41 additions and 36 deletions

View file

@ -87,7 +87,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
private PollAdapter pollAdapter; private PollAdapter pollAdapter;
private boolean useAbsoluteTime;
private SimpleDateFormat shortSdf; private SimpleDateFormat shortSdf;
private SimpleDateFormat longSdf; private SimpleDateFormat longSdf;
@ -145,7 +144,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
pollOptions.setLayoutManager(new LinearLayoutManager(pollOptions.getContext())); pollOptions.setLayoutManager(new LinearLayoutManager(pollOptions.getContext()));
((DefaultItemAnimator) pollOptions.getItemAnimator()).setSupportsChangeAnimations(false); ((DefaultItemAnimator) pollOptions.getItemAnimator()).setSupportsChangeAnimations(false);
this.useAbsoluteTime = useAbsoluteTime;
this.shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); this.shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
this.longSdf = new SimpleDateFormat("MM/dd 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, @Nullable Status.Mention[] mentions,
@NonNull List<Emoji> emojis, @NonNull List<Emoji> emojis,
@Nullable PollViewData poll, @Nullable PollViewData poll,
@NonNull StatusDisplayOptions statusDisplayOptions,
final StatusActionListener listener) { final StatusActionListener listener) {
if (TextUtils.isEmpty(spoilerText)) { if (TextUtils.isEmpty(spoilerText)) {
contentWarningDescription.setVisibility(View.GONE); contentWarningDescription.setVisibility(View.GONE);
contentWarningButton.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 { } else {
CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription); CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription);
contentWarningDescription.setText(emojiSpoiler); contentWarningDescription.setText(emojiSpoiler);
@ -198,9 +197,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (getAdapterPosition() != RecyclerView.NO_POSITION) { if (getAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onExpandedChange(isChecked, getAdapterPosition()); 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, Status.Mention[] mentions,
List<Emoji> emojis, List<Emoji> emojis,
@Nullable PollViewData poll, @Nullable PollViewData poll,
StatusDisplayOptions statusDisplayOptions,
final StatusActionListener listener) { final StatusActionListener listener) {
if (expanded) { if (expanded) {
Spanned emojifiedText = CustomEmojiHelper.emojifyText(content, emojis, this.content); Spanned emojifiedText = CustomEmojiHelper.emojifyText(content, emojis, this.content);
LinkHelper.setClickableText(this.content, emojifiedText, mentions, listener); LinkHelper.setClickableText(this.content, emojifiedText, mentions, listener);
if (poll != null) { if (poll != null) {
setupPoll(poll, emojis, listener); setupPoll(poll, emojis, statusDisplayOptions, listener);
} else { } else {
hidePoll(); hidePoll();
} }
@ -274,8 +274,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
protected void setCreatedAt(Date createdAt) { protected void setCreatedAt(Date createdAt, StatusDisplayOptions statusDisplayOptions) {
if (useAbsoluteTime) { if (statusDisplayOptions.useAbsoluteTime()) {
timestampInfo.setText(getAbsoluteTime(createdAt)); timestampInfo.setText(getAbsoluteTime(createdAt));
} else { } else {
if (createdAt == null) { if (createdAt == null) {
@ -300,8 +300,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
} }
private CharSequence getCreatedAtDescription(Date createdAt) { private CharSequence getCreatedAtDescription(Date createdAt,
if (useAbsoluteTime) { StatusDisplayOptions statusDisplayOptions) {
if (statusDisplayOptions.useAbsoluteTime()) {
return getAbsoluteTime(createdAt); return getAbsoluteTime(createdAt);
} else { } else {
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m" /* 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) { if (payloads == null) {
setDisplayName(status.getUserFullName(), status.getAccountEmojis()); setDisplayName(status.getUserFullName(), status.getAccountEmojis());
setUsername(status.getNickname()); setUsername(status.getNickname());
setCreatedAt(status.getCreatedAt()); setCreatedAt(status.getCreatedAt(), statusDisplayOptions);
setIsReply(status.getInReplyToId() != null); setIsReply(status.getInReplyToId() != null);
setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot(), statusDisplayOptions); setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot(), statusDisplayOptions);
setReblogged(status.isReblogged()); setReblogged(status.isReblogged());
@ -677,9 +678,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
setupButtons(listener, status.getSenderId()); setupButtons(listener, status.getSenderId());
setRebloggingEnabled(status.getRebloggingEnabled(), status.getVisibility()); 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 // Workaround for RecyclerView 1.0.0 / androidx.core 1.0.0
// RecyclerView tries to set AccessibilityDelegateCompat to null // RecyclerView tries to set AccessibilityDelegateCompat to null
@ -691,7 +692,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (payloads instanceof List) if (payloads instanceof List)
for (Object item : (List) payloads) { for (Object item : (List) payloads) {
if (Key.KEY_CREATED.equals(item)) { 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; return false;
} }
private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status) { private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status,
StatusDisplayOptions statusDisplayOptions) {
Context context = itemView.getContext(); Context context = itemView.getContext();
String description = context.getString(R.string.description_status, String description = context.getString(R.string.description_status,
status.getUserFullName(), status.getUserFullName(),
getContentWarningDescription(context, status), getContentWarningDescription(context, status),
(TextUtils.isEmpty(status.getSpoilerText()) || !status.isSensitive() || status.isExpanded() ? status.getContent() : ""), (TextUtils.isEmpty(status.getSpoilerText()) || !status.isSensitive() || status.isExpanded() ? status.getContent() : ""),
getCreatedAtDescription(status.getCreatedAt()), getCreatedAtDescription(status.getCreatedAt(), statusDisplayOptions),
getReblogDescription(context, status), getReblogDescription(context, status),
status.getNickname(), status.getNickname(),
status.isReblogged() ? context.getString(R.string.description_status_reblogged) : "", status.isReblogged() ? context.getString(R.string.description_status_reblogged) : "",
@ -724,7 +726,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
getVisibilityDescription(context, status.getVisibility()), getVisibilityDescription(context, status.getVisibility()),
getFavsText(context, status.getFavouritesCount()), getFavsText(context, status.getFavouritesCount()),
getReblogsText(context, status.getReblogsCount()), getReblogsText(context, status.getReblogsCount()),
getPollDescription(context, status) getPollDescription(status, context, statusDisplayOptions)
); );
itemView.setContentDescription(description); itemView.setContentDescription(description);
} }
@ -796,8 +798,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
return context.getString(resource); return context.getString(resource);
} }
private CharSequence getPollDescription(Context context, private CharSequence getPollDescription(@NonNull StatusViewData.Concrete status,
@NonNull StatusViewData.Concrete status) { Context context,
StatusDisplayOptions statusDisplayOptions) {
PollViewData poll = status.getPoll(); PollViewData poll = status.getPoll();
if (poll == null) { if (poll == null) {
return ""; return "";
@ -812,7 +815,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
args[i] = ""; 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); 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<Emoji> emojis, StatusActionListener listener) { private void setupPoll(PollViewData poll, List<Emoji> emojis,
StatusDisplayOptions statusDisplayOptions,
StatusActionListener listener) {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime()); 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.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 votes = numberFormat.format(poll.getVotesCount());
String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes); String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes);
CharSequence pollDurationInfo; CharSequence pollDurationInfo;
@ -884,7 +892,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} else if (poll.getExpiresAt() == null) { } else if (poll.getExpiresAt() == null) {
return votesText; return votesText;
} else { } else {
if (useAbsoluteTime) { if (statusDisplayOptions.useAbsoluteTime()) {
pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt())); pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt()));
} else { } else {
String pollDuration = TimestampUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp); String pollDuration = TimestampUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp);

View file

@ -4,11 +4,8 @@ import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -26,7 +23,6 @@ import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Card; import com.keylesspalace.tusky.entity.Card;
import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.entity.Status;
import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.interfaces.StatusActionListener;
import com.keylesspalace.tusky.util.CustomURLSpan;
import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.LinkHelper;
import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.util.StatusDisplayOptions;
import com.keylesspalace.tusky.viewdata.StatusViewData; import com.keylesspalace.tusky.viewdata.StatusViewData;
@ -66,8 +62,8 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
} }
@Override @Override
protected void setCreatedAt(Date createdAt) { protected void setCreatedAt(Date createdAt, StatusDisplayOptions statusDisplayOptions) {
if(createdAt == null) { if (createdAt == null) {
timestampInfo.setText(""); timestampInfo.setText("");
} else { } else {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
@ -154,11 +150,11 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
final Card card = status.getCard(); final Card card = status.getCard();
cardView.setVisibility(View.VISIBLE); cardView.setVisibility(View.VISIBLE);
cardTitle.setText(card.getTitle()); 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); cardDescription.setVisibility(View.GONE);
} else { } else {
cardDescription.setVisibility(View.VISIBLE); cardDescription.setVisibility(View.VISIBLE);
if(TextUtils.isEmpty(card.getDescription())) { if (TextUtils.isEmpty(card.getDescription())) {
cardDescription.setText(card.getAuthorName()); cardDescription.setText(card.getAuthorName());
} else { } else {
cardDescription.setText(card.getDescription()); cardDescription.setText(card.getDescription());
@ -199,7 +195,6 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
} }
Glide.with(cardImage) Glide.with(cardImage)
.load(card.getImage()) .load(card.getImage())
.transform( .transform(
@ -232,7 +227,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
private void setStatusVisibility(Status.Visibility visibility) { private void setStatusVisibility(Status.Visibility visibility) {
if(visibility == null) { if (visibility == null) {
return; return;
} }

View file

@ -77,7 +77,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
setDisplayName(account.getDisplayName(), account.getEmojis()); setDisplayName(account.getDisplayName(), account.getEmojis());
setUsername(account.getUsername()); setUsername(account.getUsername());
setCreatedAt(status.getCreatedAt()); setCreatedAt(status.getCreatedAt(), statusDisplayOptions);
setIsReply(status.getInReplyToId() != null); setIsReply(status.getInReplyToId() != null);
setFavourited(status.getFavourited()); setFavourited(status.getFavourited());
setBookmarked(status.getBookmarked()); setBookmarked(status.getBookmarked());
@ -106,7 +106,9 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
setupButtons(listener, account.getId()); 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()); setConversationName(conversation.getAccounts());