Make polls respect content warning visibility setting (#1583)
* Make polls respect content warning visibility setting * Only perform poll setup when poll is visible
This commit is contained in:
parent
4573b32042
commit
bac3003182
|
@ -178,11 +178,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
@Nullable String spoilerText,
|
||||
@Nullable Status.Mention[] mentions,
|
||||
@NonNull List<Emoji> emojis,
|
||||
@Nullable PollViewData poll,
|
||||
final StatusActionListener listener) {
|
||||
if (TextUtils.isEmpty(spoilerText)) {
|
||||
contentWarningDescription.setVisibility(View.GONE);
|
||||
contentWarningButton.setVisibility(View.GONE);
|
||||
this.setTextVisible(true, content, mentions, emojis, listener);
|
||||
this.setTextVisible(true, content, mentions, emojis, poll, listener);
|
||||
} else {
|
||||
CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription);
|
||||
contentWarningDescription.setText(emojiSpoiler);
|
||||
|
@ -194,9 +195,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||
listener.onExpandedChange(isChecked, getAdapterPosition());
|
||||
}
|
||||
this.setTextVisible(isChecked, content, mentions, emojis, listener);
|
||||
this.setTextVisible(isChecked, content, mentions, emojis, poll, listener);
|
||||
});
|
||||
this.setTextVisible(expanded, content, mentions, emojis, listener);
|
||||
this.setTextVisible(expanded, content, mentions, emojis, poll, listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,10 +205,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
Spanned content,
|
||||
Status.Mention[] mentions,
|
||||
List<Emoji> emojis,
|
||||
@Nullable PollViewData poll,
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
LinkHelper.setClickableMentions(this.content, mentions, listener);
|
||||
}
|
||||
|
@ -216,6 +221,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
} else {
|
||||
this.content.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setPollVisible(poll != null && expanded);
|
||||
}
|
||||
|
||||
private void setPollVisible(boolean visible) {
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
pollButton.setVisibility(visibility);
|
||||
pollDescription.setVisibility(visibility);
|
||||
pollOptions.setVisibility(visibility);
|
||||
}
|
||||
|
||||
private void setAvatar(String url,
|
||||
|
@ -674,12 +687,10 @@ 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(), listener);
|
||||
setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getStatusEmojis(), status.getPoll(), listener);
|
||||
|
||||
setDescriptionForStatus(status);
|
||||
|
||||
setupPoll(status.getPoll(), status.getStatusEmojis(), listener);
|
||||
|
||||
// Workaround for RecyclerView 1.0.0 / androidx.core 1.0.0
|
||||
// RecyclerView tries to set AccessibilityDelegateCompat to null
|
||||
// but ViewCompat code replaces is with the default one. RecyclerView never
|
||||
|
@ -834,16 +845,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
protected void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
||||
if (poll == null) {
|
||||
|
||||
pollOptions.setVisibility(View.GONE);
|
||||
|
||||
pollDescription.setVisibility(View.GONE);
|
||||
|
||||
pollButton.setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
private void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime());
|
||||
|
@ -881,8 +883,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
pollDescription.setVisibility(View.VISIBLE);
|
||||
pollDescription.setText(getPollInfoText(timestamp, poll, context));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getPollInfoText(long timestamp, PollViewData poll, Context context) {
|
||||
|
|
|
@ -108,14 +108,11 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
|
|||
|
||||
setupButtons(listener, account.getId());
|
||||
|
||||
setSpoilerAndContent(status.getExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getEmojis(), listener);
|
||||
setSpoilerAndContent(status.getExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getEmojis(), PollViewDataKt.toViewData(status.getPoll()), listener);
|
||||
|
||||
setConversationName(conversation.getAccounts());
|
||||
|
||||
setAvatars(conversation.getAccounts());
|
||||
|
||||
setupPoll(PollViewDataKt.toViewData(status.getPoll()), status.getEmojis(), listener);
|
||||
|
||||
}
|
||||
|
||||
private void setConversationName(List<ConversationAccountEntity> accounts) {
|
||||
|
|
Loading…
Reference in New Issue