include card and collapsed state in instant expanded change (#3394)
This commit is contained in:
parent
816dc0cbbc
commit
ed188783de
|
@ -191,16 +191,17 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
contentWarningButton.performClick();
|
contentWarningButton.performClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setSpoilerAndContent(boolean expanded,
|
protected void setSpoilerAndContent(@NonNull StatusViewData.Concrete status,
|
||||||
@NonNull Spanned content,
|
|
||||||
@Nullable String spoilerText,
|
|
||||||
@Nullable List<Status.Mention> mentions,
|
|
||||||
@Nullable List<HashTag> tags,
|
|
||||||
@NonNull List<Emoji> emojis,
|
|
||||||
@Nullable PollViewData poll,
|
|
||||||
@NonNull StatusDisplayOptions statusDisplayOptions,
|
@NonNull StatusDisplayOptions statusDisplayOptions,
|
||||||
final StatusActionListener listener) {
|
final StatusActionListener listener) {
|
||||||
|
|
||||||
|
Status actionable = status.getActionable();
|
||||||
|
String spoilerText = status.getSpoilerText();
|
||||||
|
List<Emoji> emojis = actionable.getEmojis();
|
||||||
|
|
||||||
boolean sensitive = !TextUtils.isEmpty(spoilerText);
|
boolean sensitive = !TextUtils.isEmpty(spoilerText);
|
||||||
|
boolean expanded = status.isExpanded();
|
||||||
|
|
||||||
if (sensitive) {
|
if (sensitive) {
|
||||||
CharSequence emojiSpoiler = CustomEmojiHelper.emojify(
|
CharSequence emojiSpoiler = CustomEmojiHelper.emojify(
|
||||||
spoilerText, emojis, contentWarningDescription, statusDisplayOptions.animateEmojis()
|
spoilerText, emojis, contentWarningDescription, statusDisplayOptions.animateEmojis()
|
||||||
|
@ -209,20 +210,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
contentWarningDescription.setVisibility(View.VISIBLE);
|
contentWarningDescription.setVisibility(View.VISIBLE);
|
||||||
contentWarningButton.setVisibility(View.VISIBLE);
|
contentWarningButton.setVisibility(View.VISIBLE);
|
||||||
setContentWarningButtonText(expanded);
|
setContentWarningButtonText(expanded);
|
||||||
contentWarningButton.setOnClickListener(view -> {
|
contentWarningButton.setOnClickListener(view -> toggleExpandedState(true, !expanded, status, statusDisplayOptions, listener));
|
||||||
contentWarningDescription.invalidate();
|
this.setTextVisible(true, expanded, status, statusDisplayOptions, listener);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
contentWarningDescription.setVisibility(View.GONE);
|
contentWarningDescription.setVisibility(View.GONE);
|
||||||
contentWarningButton.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,
|
private void setTextVisible(boolean sensitive,
|
||||||
boolean expanded,
|
boolean expanded,
|
||||||
Spanned content,
|
@NonNull final StatusViewData.Concrete status,
|
||||||
List<Status.Mention> mentions,
|
@NonNull final StatusDisplayOptions statusDisplayOptions,
|
||||||
List<HashTag> tags,
|
|
||||||
List<Emoji> emojis,
|
|
||||||
@Nullable PollViewData poll,
|
|
||||||
StatusDisplayOptions statusDisplayOptions,
|
|
||||||
final StatusActionListener listener) {
|
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) {
|
if (expanded) {
|
||||||
CharSequence emojifiedText = CustomEmojiHelper.emojify(content, emojis, this.content, statusDisplayOptions.animateEmojis());
|
CharSequence emojifiedText = CustomEmojiHelper.emojify(content, emojis, this.content, statusDisplayOptions.animateEmojis());
|
||||||
LinkHelper.setClickableText(this.content, emojifiedText, mentions, tags, listener);
|
LinkHelper.setClickableText(this.content, emojifiedText, mentions, tags, listener);
|
||||||
for (int i = 0; i < mediaLabels.length; ++i) {
|
for (int i = 0; i < mediaLabels.length; ++i) {
|
||||||
updateMediaLabel(i, sensitive, expanded);
|
updateMediaLabel(i, sensitive, true);
|
||||||
}
|
}
|
||||||
if (poll != null) {
|
if (poll != null) {
|
||||||
setupPoll(poll, emojis, statusDisplayOptions, listener);
|
setupPoll(poll, emojis, statusDisplayOptions, listener);
|
||||||
|
@ -742,18 +757,13 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
hideSensitiveMediaWarning();
|
hideSensitiveMediaWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cardView != null) {
|
setupCard(status, status.isExpanded(), statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener);
|
||||||
setupCard(status, statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
setupButtons(listener, actionable.getAccount().getId(), status.getContent().toString(),
|
setupButtons(listener, actionable.getAccount().getId(), status.getContent().toString(),
|
||||||
statusDisplayOptions);
|
statusDisplayOptions);
|
||||||
setRebloggingEnabled(actionable.rebloggingAllowed(), actionable.getVisibility());
|
setRebloggingEnabled(actionable.rebloggingAllowed(), actionable.getVisibility());
|
||||||
|
|
||||||
setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(),
|
setSpoilerAndContent(status, statusDisplayOptions, listener);
|
||||||
actionable.getMentions(), actionable.getTags(), actionable.getEmojis(),
|
|
||||||
PollViewDataKt.toViewData(actionable.getPoll()), statusDisplayOptions,
|
|
||||||
listener);
|
|
||||||
|
|
||||||
setDescriptionForStatus(status, statusDisplayOptions);
|
setDescriptionForStatus(status, statusDisplayOptions);
|
||||||
|
|
||||||
|
@ -1008,20 +1018,27 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupCard(
|
protected void setupCard(
|
||||||
StatusViewData.Concrete status,
|
final StatusViewData.Concrete status,
|
||||||
CardViewMode cardViewMode,
|
boolean expanded,
|
||||||
StatusDisplayOptions statusDisplayOptions,
|
final CardViewMode cardViewMode,
|
||||||
|
final StatusDisplayOptions statusDisplayOptions,
|
||||||
final StatusActionListener listener
|
final StatusActionListener listener
|
||||||
) {
|
) {
|
||||||
|
if (cardView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Status actionable = status.getActionable();
|
final Status actionable = status.getActionable();
|
||||||
final Card card = actionable.getCard();
|
final Card card = actionable.getCard();
|
||||||
|
|
||||||
if (cardViewMode != CardViewMode.NONE &&
|
if (cardViewMode != CardViewMode.NONE &&
|
||||||
actionable.getAttachments().size() == 0 &&
|
actionable.getAttachments().size() == 0 &&
|
||||||
actionable.getPoll() == null &&
|
actionable.getPoll() == null &&
|
||||||
card != null &&
|
card != null &&
|
||||||
!TextUtils.isEmpty(card.getUrl()) &&
|
!TextUtils.isEmpty(card.getUrl()) &&
|
||||||
(!actionable.getSensitive() || status.isExpanded()) &&
|
(!actionable.getSensitive() || expanded) &&
|
||||||
(!status.isCollapsible() || !status.isCollapsed())) {
|
(!status.isCollapsible() || !status.isCollapsed())) {
|
||||||
|
|
||||||
cardView.setVisibility(View.VISIBLE);
|
cardView.setVisibility(View.VISIBLE);
|
||||||
cardTitle.setText(card.getTitle());
|
cardTitle.setText(card.getTitle());
|
||||||
if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) {
|
if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) {
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
||||||
status;
|
status;
|
||||||
|
|
||||||
super.setupWithStatus(uncollapsedStatus, listener, statusDisplayOptions, payloads);
|
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) {
|
if (payloads == null) {
|
||||||
Status actionable = uncollapsedStatus.getActionable();
|
Status actionable = uncollapsedStatus.getActionable();
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,10 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
||||||
@Nullable Object payloads) {
|
@Nullable Object payloads) {
|
||||||
if (payloads == null) {
|
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();
|
Status reblogging = status.getRebloggingStatus();
|
||||||
if (reblogging == null) {
|
if (reblogging == null) {
|
||||||
|
@ -74,7 +77,6 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
||||||
|
|
||||||
}
|
}
|
||||||
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRebloggedByDisplayName(final CharSequence name,
|
private void setRebloggedByDisplayName(final CharSequence name,
|
||||||
|
@ -103,9 +105,12 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
||||||
statusInfo.setVisibility(View.GONE);
|
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 */
|
/* 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 -> {
|
contentCollapseButton.setOnClickListener(view -> {
|
||||||
int position = getBindingAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position != RecyclerView.NO_POSITION)
|
if (position != RecyclerView.NO_POSITION)
|
||||||
|
@ -130,4 +135,16 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
||||||
super.showStatusContent(show);
|
super.showStatusContent(show);
|
||||||
contentCollapseButton.setVisibility(show ? View.VISIBLE : View.GONE);
|
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.ImageLoadingHelper;
|
||||||
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
||||||
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
||||||
import com.keylesspalace.tusky.viewdata.PollViewDataKt;
|
|
||||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -110,9 +109,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
|
||||||
setupButtons(listener, account.getId(), statusViewData.getContent().toString(),
|
setupButtons(listener, account.getId(), statusViewData.getContent().toString(),
|
||||||
statusDisplayOptions);
|
statusDisplayOptions);
|
||||||
|
|
||||||
setSpoilerAndContent(statusViewData.isExpanded(), statusViewData.getContent(), status.getSpoilerText(),
|
setSpoilerAndContent(statusViewData, statusDisplayOptions, listener);
|
||||||
status.getMentions(), status.getTags(), status.getEmojis(),
|
|
||||||
PollViewDataKt.toViewData(status.getPoll()), statusDisplayOptions, listener);
|
|
||||||
|
|
||||||
setConversationName(conversation.getAccounts());
|
setConversationName(conversation.getAccounts());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue