mirror of
https://github.com/accelforce/Yuito
synced 2024-12-28 00:32:04 +01:00
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,55 +845,44 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
||||
if (poll == null) {
|
||||
private void setupPoll(PollViewData poll, List<Emoji> emojis, StatusActionListener listener) {
|
||||
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);
|
||||
|
||||
} 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()) {
|
||||
// no voting possible
|
||||
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, PollAdapter.RESULT);
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
|
||||
pollButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
// voting possible
|
||||
pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE);
|
||||
List<Integer> pollResult = pollAdapter.getSelected();
|
||||
|
||||
pollButton.setVisibility(View.VISIBLE);
|
||||
|
||||
pollButton.setOnClickListener(v -> {
|
||||
|
||||
int position = getAdapterPosition();
|
||||
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
|
||||
List<Integer> pollResult = pollAdapter.getSelected();
|
||||
|
||||
if (!pollResult.isEmpty()) {
|
||||
listener.onVoteInPoll(position, pollResult);
|
||||
}
|
||||
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) {
|
||||
|
@ -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
Block a user