Update status data model to store whether the message has been collapsed

This commit is contained in:
HellPie 2018-08-30 21:11:13 +02:00 committed by HellPie
parent 6b1ec083b7
commit bdf0264c56
1 changed files with 51 additions and 25 deletions

View File

@ -80,6 +80,7 @@ public abstract class StatusViewData {
private final List<Emoji> accountEmojis; private final List<Emoji> accountEmojis;
@Nullable @Nullable
private final Card card; private final Card card;
private final boolean isCollapsed; /** Whether the status is shown partially or fully */
public Concrete(String id, Spanned content, boolean reblogged, boolean favourited, public Concrete(String id, Spanned content, boolean reblogged, boolean favourited,
@Nullable String spoilerText, Status.Visibility visibility, List<Attachment> attachments, @Nullable String spoilerText, Status.Visibility visibility, List<Attachment> attachments,
@ -87,7 +88,8 @@ public abstract class StatusViewData {
boolean isShowingContent, String userFullName, String nickname, String avatar, boolean isShowingContent, String userFullName, String nickname, String avatar,
Date createdAt, int reblogsCount, int favouritesCount, @Nullable String inReplyToId, Date createdAt, int reblogsCount, int favouritesCount, @Nullable String inReplyToId,
@Nullable Status.Mention[] mentions, String senderId, boolean rebloggingEnabled, @Nullable Status.Mention[] mentions, String senderId, boolean rebloggingEnabled,
Status.Application application, List<Emoji> statusEmojis, List<Emoji> accountEmojis, @Nullable Card card) { Status.Application application, List<Emoji> statusEmojis, List<Emoji> accountEmojis, @Nullable Card card,
boolean isCollapsed) {
this.id = id; this.id = id;
this.content = content; this.content = content;
this.reblogged = reblogged; this.reblogged = reblogged;
@ -114,6 +116,7 @@ public abstract class StatusViewData {
this.statusEmojis = statusEmojis; this.statusEmojis = statusEmojis;
this.accountEmojis = accountEmojis; this.accountEmojis = accountEmojis;
this.card = card; this.card = card;
this.isCollapsed = isCollapsed;
} }
public String getId() { public String getId() {
@ -226,6 +229,15 @@ public abstract class StatusViewData {
return card; return card;
} }
/**
* Specifies whether the content of this post is castrated to a certain length or if it is
* currently shown at its full length.
* @return Whether the post is collapsed or fully expanded.
*/
public boolean isCollapsed() {
return isCollapsed;
}
@Override public long getViewDataId() { @Override public long getViewDataId() {
// Chance of collision is super low and impact of mistake is low as well // Chance of collision is super low and impact of mistake is low as well
return getId().hashCode(); return getId().hashCode();
@ -236,31 +248,32 @@ public abstract class StatusViewData {
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Concrete concrete = (Concrete) o; Concrete concrete = (Concrete) o;
return reblogged == concrete.reblogged && return reblogged == concrete.reblogged &&
favourited == concrete.favourited && favourited == concrete.favourited &&
isSensitive == concrete.isSensitive && isSensitive == concrete.isSensitive &&
isExpanded == concrete.isExpanded && isExpanded == concrete.isExpanded &&
isShowingContent == concrete.isShowingContent && isShowingContent == concrete.isShowingContent &&
reblogsCount == concrete.reblogsCount && reblogsCount == concrete.reblogsCount &&
favouritesCount == concrete.favouritesCount && favouritesCount == concrete.favouritesCount &&
rebloggingEnabled == concrete.rebloggingEnabled && rebloggingEnabled == concrete.rebloggingEnabled &&
Objects.equals(id, concrete.id) && Objects.equals(id, concrete.id) &&
Objects.equals(content, concrete.content) && Objects.equals(content, concrete.content) &&
Objects.equals(spoilerText, concrete.spoilerText) && Objects.equals(spoilerText, concrete.spoilerText) &&
visibility == concrete.visibility && visibility == concrete.visibility &&
Objects.equals(attachments, concrete.attachments) && Objects.equals(attachments, concrete.attachments) &&
Objects.equals(rebloggedByUsername, concrete.rebloggedByUsername) && Objects.equals(rebloggedByUsername, concrete.rebloggedByUsername) &&
Objects.equals(rebloggedAvatar, concrete.rebloggedAvatar) && Objects.equals(rebloggedAvatar, concrete.rebloggedAvatar) &&
Objects.equals(userFullName, concrete.userFullName) && Objects.equals(userFullName, concrete.userFullName) &&
Objects.equals(nickname, concrete.nickname) && Objects.equals(nickname, concrete.nickname) &&
Objects.equals(avatar, concrete.avatar) && Objects.equals(avatar, concrete.avatar) &&
Objects.equals(createdAt, concrete.createdAt) && Objects.equals(createdAt, concrete.createdAt) &&
Objects.equals(inReplyToId, concrete.inReplyToId) && Objects.equals(inReplyToId, concrete.inReplyToId) &&
Arrays.equals(mentions, concrete.mentions) && Arrays.equals(mentions, concrete.mentions) &&
Objects.equals(senderId, concrete.senderId) && Objects.equals(senderId, concrete.senderId) &&
Objects.equals(application, concrete.application) && Objects.equals(application, concrete.application) &&
Objects.equals(statusEmojis, concrete.statusEmojis) && Objects.equals(statusEmojis, concrete.statusEmojis) &&
Objects.equals(accountEmojis, concrete.accountEmojis) && Objects.equals(accountEmojis, concrete.accountEmojis) &&
Objects.equals(card, concrete.card); Objects.equals(card, concrete.card)
&& isCollapsed == concrete.isCollapsed;
} }
} }
@ -334,6 +347,7 @@ public abstract class StatusViewData {
private List<Emoji> statusEmojis; private List<Emoji> statusEmojis;
private List<Emoji> accountEmojis; private List<Emoji> accountEmojis;
private Card card; private Card card;
private boolean isCollapsed; /** Whether the status is shown partially or fully */
public Builder() { public Builder() {
} }
@ -497,6 +511,18 @@ public abstract class StatusViewData {
return this; return this;
} }
/**
* Configure the {@link com.keylesspalace.tusky.viewdata.StatusViewData} to start in a collapsed
* state, hiding partially the content of the post if it exceeds a certain amount of characters.
*
* @param collapsed Whether to show the full content of the status or not.
* @return This {@link com.keylesspalace.tusky.viewdata.StatusViewData.Builder} instance.
*/
public Builder setCollapsed(boolean collapsed) {
isCollapsed = collapsed;
return this;
}
public StatusViewData.Concrete createStatusViewData() { public StatusViewData.Concrete createStatusViewData() {
if (this.statusEmojis == null) statusEmojis = Collections.emptyList(); if (this.statusEmojis == null) statusEmojis = Collections.emptyList();
if (this.accountEmojis == null) accountEmojis = Collections.emptyList(); if (this.accountEmojis == null) accountEmojis = Collections.emptyList();
@ -506,7 +532,7 @@ public abstract class StatusViewData {
attachments, rebloggedByUsername, rebloggedAvatar, isSensitive, isExpanded, attachments, rebloggedByUsername, rebloggedAvatar, isSensitive, isExpanded,
isShowingContent, userFullName, nickname, avatar, createdAt, reblogsCount, isShowingContent, userFullName, nickname, avatar, createdAt, reblogsCount,
favouritesCount, inReplyToId, mentions, senderId, rebloggingEnabled, application, favouritesCount, inReplyToId, mentions, senderId, rebloggingEnabled, application,
statusEmojis, accountEmojis, card); statusEmojis, accountEmojis, card, isCollapsed);
} }
} }
} }