From ed188783de8cd622dc764ae629f1ef25471e5664 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Wed, 1 Mar 2023 20:00:56 +0100 Subject: [PATCH] include card and collapsed state in instant expanded change (#3394) --- .../tusky/adapter/StatusBaseViewHolder.java | 99 +++++++++++-------- .../adapter/StatusDetailedViewHolder.java | 2 +- .../tusky/adapter/StatusViewHolder.java | 25 ++++- .../conversation/ConversationViewHolder.java | 5 +- 4 files changed, 81 insertions(+), 50 deletions(-) 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 f38a5d68d..582abee44 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -191,16 +191,17 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { contentWarningButton.performClick(); } - protected void setSpoilerAndContent(boolean expanded, - @NonNull Spanned content, - @Nullable String spoilerText, - @Nullable List mentions, - @Nullable List tags, - @NonNull List emojis, - @Nullable PollViewData poll, + protected void setSpoilerAndContent(@NonNull StatusViewData.Concrete status, @NonNull StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) { + + Status actionable = status.getActionable(); + String spoilerText = status.getSpoilerText(); + List emojis = actionable.getEmojis(); + boolean sensitive = !TextUtils.isEmpty(spoilerText); + boolean expanded = status.isExpanded(); + if (sensitive) { CharSequence emojiSpoiler = CustomEmojiHelper.emojify( spoilerText, emojis, contentWarningDescription, statusDisplayOptions.animateEmojis() @@ -209,20 +210,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { contentWarningDescription.setVisibility(View.VISIBLE); contentWarningButton.setVisibility(View.VISIBLE); setContentWarningButtonText(expanded); - contentWarningButton.setOnClickListener(view -> { - contentWarningDescription.invalidate(); - if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) { - listener.onExpandedChange(!expanded, getBindingAdapterPosition()); - } - setContentWarningButtonText(!expanded); - - this.setTextVisible(sensitive, !expanded, content, mentions, tags, emojis, poll, statusDisplayOptions, listener); - }); - this.setTextVisible(sensitive, expanded, content, mentions, tags, emojis, poll, statusDisplayOptions, listener); + contentWarningButton.setOnClickListener(view -> toggleExpandedState(true, !expanded, status, statusDisplayOptions, listener)); + this.setTextVisible(true, expanded, status, statusDisplayOptions, listener); } else { contentWarningDescription.setVisibility(View.GONE); contentWarningButton.setVisibility(View.GONE); - this.setTextVisible(sensitive, true, content, mentions, tags, emojis, poll, statusDisplayOptions, listener); + this.setTextVisible(false, true, status, statusDisplayOptions, listener); } } @@ -234,20 +227,42 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } } + protected void toggleExpandedState(boolean sensitive, + boolean expanded, + @NonNull final StatusViewData.Concrete status, + @NonNull final StatusDisplayOptions statusDisplayOptions, + @NonNull final StatusActionListener listener) { + + contentWarningDescription.invalidate(); + int adapterPosition = getBindingAdapterPosition(); + if (adapterPosition != RecyclerView.NO_POSITION) { + listener.onExpandedChange(expanded, adapterPosition); + } + setContentWarningButtonText(expanded); + + this.setTextVisible(sensitive, expanded, status, statusDisplayOptions, listener); + + setupCard(status, expanded, statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener); + } + private void setTextVisible(boolean sensitive, boolean expanded, - Spanned content, - List mentions, - List tags, - List emojis, - @Nullable PollViewData poll, - StatusDisplayOptions statusDisplayOptions, + @NonNull final StatusViewData.Concrete status, + @NonNull final StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) { + + Status actionable = status.getActionable(); + Spanned content = status.getContent(); + List mentions = actionable.getMentions(); + List tags =actionable.getTags(); + List emojis = actionable.getEmojis(); + PollViewData poll = PollViewDataKt.toViewData(actionable.getPoll()); + if (expanded) { CharSequence emojifiedText = CustomEmojiHelper.emojify(content, emojis, this.content, statusDisplayOptions.animateEmojis()); LinkHelper.setClickableText(this.content, emojifiedText, mentions, tags, listener); for (int i = 0; i < mediaLabels.length; ++i) { - updateMediaLabel(i, sensitive, expanded); + updateMediaLabel(i, sensitive, true); } if (poll != null) { setupPoll(poll, emojis, statusDisplayOptions, listener); @@ -742,18 +757,13 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { hideSensitiveMediaWarning(); } - if (cardView != null) { - setupCard(status, statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener); - } + setupCard(status, status.isExpanded(), statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener); setupButtons(listener, actionable.getAccount().getId(), status.getContent().toString(), statusDisplayOptions); setRebloggingEnabled(actionable.rebloggingAllowed(), actionable.getVisibility()); - setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), - actionable.getMentions(), actionable.getTags(), actionable.getEmojis(), - PollViewDataKt.toViewData(actionable.getPoll()), statusDisplayOptions, - listener); + setSpoilerAndContent(status, statusDisplayOptions, listener); setDescriptionForStatus(status, statusDisplayOptions); @@ -1008,20 +1018,27 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } protected void setupCard( - StatusViewData.Concrete status, - CardViewMode cardViewMode, - StatusDisplayOptions statusDisplayOptions, + final StatusViewData.Concrete status, + boolean expanded, + final CardViewMode cardViewMode, + final StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener ) { + if (cardView == null) { + return; + } + final Status actionable = status.getActionable(); final Card card = actionable.getCard(); + if (cardViewMode != CardViewMode.NONE && - actionable.getAttachments().size() == 0 && - actionable.getPoll() == null && - card != null && - !TextUtils.isEmpty(card.getUrl()) && - (!actionable.getSensitive() || status.isExpanded()) && - (!status.isCollapsible() || !status.isCollapsed())) { + actionable.getAttachments().size() == 0 && + actionable.getPoll() == null && + card != null && + !TextUtils.isEmpty(card.getUrl()) && + (!actionable.getSensitive() || expanded) && + (!status.isCollapsible() || !status.isCollapsed())) { + cardView.setVisibility(View.VISIBLE); cardTitle.setText(card.getTitle()); if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) { 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 1725dac9c..76eda1107 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java @@ -159,7 +159,7 @@ public class StatusDetailedViewHolder extends StatusBaseViewHolder { status; super.setupWithStatus(uncollapsedStatus, listener, statusDisplayOptions, payloads); - setupCard(uncollapsedStatus, CardViewMode.FULL_WIDTH, statusDisplayOptions, listener); // Always show card for detailed status + setupCard(uncollapsedStatus, status.isExpanded(), CardViewMode.FULL_WIDTH, statusDisplayOptions, listener); // Always show card for detailed status if (payloads == null) { Status actionable = uncollapsedStatus.getActionable(); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java index 13d175a0c..18a669a16 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java @@ -60,7 +60,10 @@ public class StatusViewHolder extends StatusBaseViewHolder { @Nullable Object payloads) { if (payloads == null) { - setupCollapsedState(status, listener); + boolean sensitive = !TextUtils.isEmpty(status.getActionable().getSpoilerText()); + boolean expanded = status.isExpanded(); + + setupCollapsedState(sensitive, expanded, status, listener); Status reblogging = status.getRebloggingStatus(); if (reblogging == null) { @@ -74,7 +77,6 @@ public class StatusViewHolder extends StatusBaseViewHolder { } super.setupWithStatus(status, listener, statusDisplayOptions, payloads); - } private void setRebloggedByDisplayName(final CharSequence name, @@ -103,9 +105,12 @@ public class StatusViewHolder extends StatusBaseViewHolder { statusInfo.setVisibility(View.GONE); } - private void setupCollapsedState(final StatusViewData.Concrete status, final StatusActionListener listener) { + private void setupCollapsedState(boolean sensitive, + boolean expanded, + final StatusViewData.Concrete status, + final StatusActionListener listener) { /* input filter for TextViews have to be set before text */ - if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) { + if (status.isCollapsible() && (!sensitive || expanded)) { contentCollapseButton.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position != RecyclerView.NO_POSITION) @@ -130,4 +135,16 @@ public class StatusViewHolder extends StatusBaseViewHolder { super.showStatusContent(show); contentCollapseButton.setVisibility(show ? View.VISIBLE : View.GONE); } + + @Override + protected void toggleExpandedState(boolean sensitive, + boolean expanded, + @NonNull StatusViewData.Concrete status, + @NonNull StatusDisplayOptions statusDisplayOptions, + @NonNull final StatusActionListener listener) { + + setupCollapsedState(sensitive, expanded, status, listener); + + super.toggleExpandedState(sensitive, expanded, status, statusDisplayOptions, listener); + } } 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 64b42eaa3..722a9f3c5 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 @@ -36,7 +36,6 @@ import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.util.ImageLoadingHelper; import com.keylesspalace.tusky.util.SmartLengthInputFilter; import com.keylesspalace.tusky.util.StatusDisplayOptions; -import com.keylesspalace.tusky.viewdata.PollViewDataKt; import com.keylesspalace.tusky.viewdata.StatusViewData; import java.util.List; @@ -110,9 +109,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder { setupButtons(listener, account.getId(), statusViewData.getContent().toString(), statusDisplayOptions); - setSpoilerAndContent(statusViewData.isExpanded(), statusViewData.getContent(), status.getSpoilerText(), - status.getMentions(), status.getTags(), status.getEmojis(), - PollViewDataKt.toViewData(status.getPoll()), statusDisplayOptions, listener); + setSpoilerAndContent(statusViewData, statusDisplayOptions, listener); setConversationName(conversation.getAccounts());