Update data models and utils for statuses to better handle collapsing

I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
This commit is contained in:
HellPie 2018-08-31 02:13:31 +02:00 committed by HellPie
parent 0ee004d78d
commit 472effd4a0
2 changed files with 50 additions and 9 deletions

View File

@ -29,7 +29,8 @@ import com.keylesspalace.tusky.viewdata.StatusViewData;
public final class ViewDataUtils { public final class ViewDataUtils {
@Nullable @Nullable
public static StatusViewData.Concrete statusToViewData(@Nullable Status status, public static StatusViewData.Concrete statusToViewData(@Nullable Status status,
boolean alwaysShowSensitiveMedia) { boolean alwaysShowSensitiveMedia,
boolean collapseLongStatusContent) {
if (status == null) return null; if (status == null) return null;
Status visibleStatus = status.getReblog() == null ? status : status.getReblog(); Status visibleStatus = status.getReblog() == null ? status : status.getReblog();
return new StatusViewData.Builder().setId(status.getId()) return new StatusViewData.Builder().setId(status.getId())
@ -58,12 +59,24 @@ public final class ViewDataUtils {
.setApplication(visibleStatus.getApplication()) .setApplication(visibleStatus.getApplication())
.setStatusEmojis(visibleStatus.getEmojis()) .setStatusEmojis(visibleStatus.getEmojis())
.setAccountEmojis(visibleStatus.getAccount().getEmojis()) .setAccountEmojis(visibleStatus.getAccount().getEmojis())
.setCollapsible(collapseLongStatusContent && status.getContent().length() > 500)
.setCollapsed(true)
.createStatusViewData(); .createStatusViewData();
} }
public static NotificationViewData.Concrete notificationToViewData(Notification notification, boolean alwaysShowSensitiveData) { public static NotificationViewData.Concrete notificationToViewData(Notification notification,
return new NotificationViewData.Concrete(notification.getType(), notification.getId(), notification.getAccount(), boolean alwaysShowSensitiveData,
statusToViewData(notification.getStatus(), alwaysShowSensitiveData), false); boolean collapseLongStatusContent) {
return new NotificationViewData.Concrete(
notification.getType(),
notification.getId(),
notification.getAccount(),
statusToViewData(
notification.getStatus(),
alwaysShowSensitiveData,
collapseLongStatusContent
),
false
);
} }
} }

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 isCollapsible; /** Whether the status meets the requirement to be collapse */
private final boolean isCollapsed; /** Whether the status is shown partially or fully */ 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,
@ -89,7 +90,7 @@ public abstract class StatusViewData {
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) { boolean isCollapsible, boolean isCollapsed) {
this.id = id; this.id = id;
this.content = content; this.content = content;
this.reblogged = reblogged; this.reblogged = reblogged;
@ -116,6 +117,7 @@ public abstract class StatusViewData {
this.statusEmojis = statusEmojis; this.statusEmojis = statusEmojis;
this.accountEmojis = accountEmojis; this.accountEmojis = accountEmojis;
this.card = card; this.card = card;
this.isCollapsible = isCollapsible;
this.isCollapsed = isCollapsed; this.isCollapsed = isCollapsed;
} }
@ -230,8 +232,19 @@ public abstract class StatusViewData {
} }
/** /**
* Specifies whether the content of this post is castrated to a certain length or if it is * Specifies whether the content of this post is allowed to be collapsed or if it should show
* currently shown at its full length. * all content regardless.
*
* @return Whether the post is collapsible or never collapsed.
*/
public boolean isCollapsible() {
return isCollapsible;
}
/**
* Specifies whether the content of this post is currently limited in visibility to the first
* 500 characters or not.
*
* @return Whether the post is collapsed or fully expanded. * @return Whether the post is collapsed or fully expanded.
*/ */
public boolean isCollapsed() { public boolean isCollapsed() {
@ -347,6 +360,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 isCollapsible; /** Whether the status meets the requirement to be collapsed */
private boolean isCollapsed; /** Whether the status is shown partially or fully */ private boolean isCollapsed; /** Whether the status is shown partially or fully */
public Builder() { public Builder() {
@ -379,6 +393,8 @@ public abstract class StatusViewData {
statusEmojis = viewData.getStatusEmojis(); statusEmojis = viewData.getStatusEmojis();
accountEmojis = viewData.getAccountEmojis(); accountEmojis = viewData.getAccountEmojis();
card = viewData.getCard(); card = viewData.getCard();
isCollapsible = viewData.isCollapsible();
isCollapsed = viewData.isCollapsed();
} }
public Builder setId(String id) { public Builder setId(String id) {
@ -511,6 +527,18 @@ public abstract class StatusViewData {
return this; return this;
} }
/**
* Configure the {@link com.keylesspalace.tusky.viewdata.StatusViewData} to support collapsing
* its content limiting the visible length when collapsed at 500 characters,
*
* @param collapsible Whether the status should support being collapsed or not.
* @return This {@link com.keylesspalace.tusky.viewdata.StatusViewData.Builder} instance.
*/
public Builder setCollapsible(boolean collapsible) {
isCollapsible = collapsible;
return this;
}
/** /**
* Configure the {@link com.keylesspalace.tusky.viewdata.StatusViewData} to start in a collapsed * 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. * state, hiding partially the content of the post if it exceeds a certain amount of characters.
@ -532,7 +560,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, isCollapsed); statusEmojis, accountEmojis, card, isCollapsible, isCollapsed);
} }
} }
} }