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:
parent
0ee004d78d
commit
472effd4a0
|
@ -29,7 +29,8 @@ import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|||
public final class ViewDataUtils {
|
||||
@Nullable
|
||||
public static StatusViewData.Concrete statusToViewData(@Nullable Status status,
|
||||
boolean alwaysShowSensitiveMedia) {
|
||||
boolean alwaysShowSensitiveMedia,
|
||||
boolean collapseLongStatusContent) {
|
||||
if (status == null) return null;
|
||||
Status visibleStatus = status.getReblog() == null ? status : status.getReblog();
|
||||
return new StatusViewData.Builder().setId(status.getId())
|
||||
|
@ -58,12 +59,24 @@ public final class ViewDataUtils {
|
|||
.setApplication(visibleStatus.getApplication())
|
||||
.setStatusEmojis(visibleStatus.getEmojis())
|
||||
.setAccountEmojis(visibleStatus.getAccount().getEmojis())
|
||||
.setCollapsible(collapseLongStatusContent && status.getContent().length() > 500)
|
||||
.setCollapsed(true)
|
||||
.createStatusViewData();
|
||||
}
|
||||
|
||||
public static NotificationViewData.Concrete notificationToViewData(Notification notification, boolean alwaysShowSensitiveData) {
|
||||
return new NotificationViewData.Concrete(notification.getType(), notification.getId(), notification.getAccount(),
|
||||
statusToViewData(notification.getStatus(), alwaysShowSensitiveData), false);
|
||||
public static NotificationViewData.Concrete notificationToViewData(Notification notification,
|
||||
boolean alwaysShowSensitiveData,
|
||||
boolean collapseLongStatusContent) {
|
||||
return new NotificationViewData.Concrete(
|
||||
notification.getType(),
|
||||
notification.getId(),
|
||||
notification.getAccount(),
|
||||
statusToViewData(
|
||||
notification.getStatus(),
|
||||
alwaysShowSensitiveData,
|
||||
collapseLongStatusContent
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ public abstract class StatusViewData {
|
|||
private final List<Emoji> accountEmojis;
|
||||
@Nullable
|
||||
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 */
|
||||
|
||||
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,
|
||||
@Nullable Status.Mention[] mentions, String senderId, boolean rebloggingEnabled,
|
||||
Status.Application application, List<Emoji> statusEmojis, List<Emoji> accountEmojis, @Nullable Card card,
|
||||
boolean isCollapsed) {
|
||||
boolean isCollapsible, boolean isCollapsed) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
this.reblogged = reblogged;
|
||||
|
@ -116,6 +117,7 @@ public abstract class StatusViewData {
|
|||
this.statusEmojis = statusEmojis;
|
||||
this.accountEmojis = accountEmojis;
|
||||
this.card = card;
|
||||
this.isCollapsible = isCollapsible;
|
||||
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
|
||||
* currently shown at its full length.
|
||||
* Specifies whether the content of this post is allowed to be collapsed or if it should show
|
||||
* 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.
|
||||
*/
|
||||
public boolean isCollapsed() {
|
||||
|
@ -347,6 +360,7 @@ public abstract class StatusViewData {
|
|||
private List<Emoji> statusEmojis;
|
||||
private List<Emoji> accountEmojis;
|
||||
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 */
|
||||
|
||||
public Builder() {
|
||||
|
@ -379,6 +393,8 @@ public abstract class StatusViewData {
|
|||
statusEmojis = viewData.getStatusEmojis();
|
||||
accountEmojis = viewData.getAccountEmojis();
|
||||
card = viewData.getCard();
|
||||
isCollapsible = viewData.isCollapsible();
|
||||
isCollapsed = viewData.isCollapsed();
|
||||
}
|
||||
|
||||
public Builder setId(String id) {
|
||||
|
@ -511,6 +527,18 @@ public abstract class StatusViewData {
|
|||
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
|
||||
* 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,
|
||||
isShowingContent, userFullName, nickname, avatar, createdAt, reblogsCount,
|
||||
favouritesCount, inReplyToId, mentions, senderId, rebloggingEnabled, application,
|
||||
statusEmojis, accountEmojis, card, isCollapsed);
|
||||
statusEmojis, accountEmojis, card, isCollapsible, isCollapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue