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 String spoilerText,
|
||||||
@Nullable Status.Mention[] mentions,
|
@Nullable Status.Mention[] mentions,
|
||||||
@NonNull List<Emoji> emojis,
|
@NonNull List<Emoji> emojis,
|
||||||
|
@Nullable PollViewData poll,
|
||||||
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, listener);
|
this.setTextVisible(true, content, mentions, emojis, poll, listener);
|
||||||
} else {
|
} else {
|
||||||
CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription);
|
CharSequence emojiSpoiler = CustomEmojiHelper.emojifyString(spoilerText, emojis, contentWarningDescription);
|
||||||
contentWarningDescription.setText(emojiSpoiler);
|
contentWarningDescription.setText(emojiSpoiler);
|
||||||
|
@ -194,9 +195,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, 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,
|
Spanned content,
|
||||||
Status.Mention[] mentions,
|
Status.Mention[] mentions,
|
||||||
List<Emoji> emojis,
|
List<Emoji> emojis,
|
||||||
|
@Nullable PollViewData poll,
|
||||||
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) {
|
||||||
|
setupPoll(poll, emojis, listener);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LinkHelper.setClickableMentions(this.content, mentions, listener);
|
LinkHelper.setClickableMentions(this.content, mentions, listener);
|
||||||
}
|
}
|
||||||
|
@ -216,6 +221,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
} else {
|
} else {
|
||||||
this.content.setVisibility(View.VISIBLE);
|
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,
|
private void setAvatar(String url,
|
||||||
|
@ -674,12 +687,10 @@ 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(), listener);
|
setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getStatusEmojis(), status.getPoll(), listener);
|
||||||
|
|
||||||
setDescriptionForStatus(status);
|
setDescriptionForStatus(status);
|
||||||
|
|
||||||
setupPoll(status.getPoll(), status.getStatusEmojis(), listener);
|
|
||||||
|
|
||||||
// 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
|
||||||
// but ViewCompat code replaces is with the default one. RecyclerView never
|
// but ViewCompat code replaces is with the default one. RecyclerView never
|
||||||
|
@ -834,55 +845,44 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
private void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
||||||
if (poll == null) {
|
long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
pollOptions.setVisibility(View.GONE);
|
boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime());
|
||||||
|
|
||||||
pollDescription.setVisibility(View.GONE);
|
Context context = pollDescription.getContext();
|
||||||
|
|
||||||
|
pollOptions.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (expired || poll.getVoted()) {
|
||||||
|
// no voting possible
|
||||||
|
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, PollAdapter.RESULT);
|
||||||
|
|
||||||
pollButton.setVisibility(View.GONE);
|
pollButton.setVisibility(View.GONE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
long timestamp = System.currentTimeMillis();
|
// voting possible
|
||||||
|
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE);
|
||||||
|
|
||||||
boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime());
|
pollButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
Context context = pollDescription.getContext();
|
pollButton.setOnClickListener(v -> {
|
||||||
|
|
||||||
pollOptions.setVisibility(View.VISIBLE);
|
int position = getAdapterPosition();
|
||||||
|
|
||||||
if (expired || poll.getVoted()) {
|
if (position != RecyclerView.NO_POSITION) {
|
||||||
// no voting possible
|
|
||||||
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, PollAdapter.RESULT);
|
|
||||||
|
|
||||||
pollButton.setVisibility(View.GONE);
|
List<Integer> pollResult = pollAdapter.getSelected();
|
||||||
} else {
|
|
||||||
// voting possible
|
|
||||||
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE);
|
|
||||||
|
|
||||||
pollButton.setVisibility(View.VISIBLE);
|
if (!pollResult.isEmpty()) {
|
||||||
|
listener.onVoteInPoll(position, pollResult);
|
||||||
pollButton.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
int position = getAdapterPosition();
|
|
||||||
|
|
||||||
if (position != RecyclerView.NO_POSITION) {
|
|
||||||
|
|
||||||
List<Integer> pollResult = pollAdapter.getSelected();
|
|
||||||
|
|
||||||
if (!pollResult.isEmpty()) {
|
|
||||||
listener.onVoteInPoll(position, pollResult);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pollDescription.setVisibility(View.VISIBLE);
|
|
||||||
pollDescription.setText(getPollInfoText(timestamp, poll, context));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pollDescription.setVisibility(View.VISIBLE);
|
||||||
|
pollDescription.setText(getPollInfoText(timestamp, poll, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getPollInfoText(long timestamp, PollViewData poll, Context context) {
|
private CharSequence getPollInfoText(long timestamp, PollViewData poll, Context context) {
|
||||||
|
|
|
@ -108,14 +108,11 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
|
||||||
|
|
||||||
setupButtons(listener, account.getId());
|
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());
|
setConversationName(conversation.getAccounts());
|
||||||
|
|
||||||
setAvatars(conversation.getAccounts());
|
setAvatars(conversation.getAccounts());
|
||||||
|
|
||||||
setupPoll(PollViewDataKt.toViewData(status.getPoll()), status.getEmojis(), listener);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setConversationName(List<ConversationAccountEntity> accounts) {
|
private void setConversationName(List<ConversationAccountEntity> accounts) {
|
||||||
|
|
Loading…
Reference in New Issue