include card and collapsed state in instant expanded change (#3394)
This commit is contained in:
parent
816dc0cbbc
commit
ed188783de
4 changed files with 81 additions and 50 deletions
|
@ -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<Status.Mention> mentions,
|
||||
@Nullable List<HashTag> tags,
|
||||
@NonNull List<Emoji> 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<Emoji> 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<Status.Mention> mentions,
|
||||
List<HashTag> tags,
|
||||
List<Emoji> 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<Status.Mention> mentions = actionable.getMentions();
|
||||
List<HashTag> tags =actionable.getTags();
|
||||
List<Emoji> 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())) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in a new issue