Add support for collapsible statuses when they exceed 500 characters (#825)

* Update Gradle plugin to work with Android Studio 3.3 Canary

Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.

This commit will be reverted once development on the feature is done.

* Update gradle build script to allow installing debug builds alongside store version

This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.

* Add UI changes to support collapsing statuses

The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below

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

* Update status action listener to notify of collapsed state changing

Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.

* Add implementation code to handle status collapse/expand in timeline

Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.

* Add preferences so that users can toggle the collapsing of long posts

This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.

* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8

Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.

* 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.

* Fix search breaking due to newly introduced variables in utils classes

* Fix timeline breaking due to newly introduced variables in utils classes

* Fix item status text for collapsed toggle being shown in the wrong state

* Update timeline fragment to refresh the list when collapsed settings change

* Add support for status content collapse in timeline viewholder

* Fix view holder truncating posts using temporary debug settings at 50 chars

* Add toggle support to notification layout as well

* Add support for collapsed statuses to search results

* Add support for expandable content to notifications too

* Update codebase with some suggested changes by @charlang

* Update more code with more suggestions and move null-safety into view data

* Update even more code with even more suggested code changes

* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)

* Add an input filter utility class to reuse code for trimming statuses

* Update UI of statuses to show a taller collapsible button

* Update notification fragment logging to simplify null checks

* Add smartness to SmartLengthInputFilter such as word trimming and runway

* Fix posts with show more button even if bad ratio didn't collapse

* Fix thread view showing button but not collapsing by implementing the feature

* Fix spannable losing spans when collapsed and restore length to 500 characters

* Remove debug build suffix as per request

* Fix all the merging happened in f66d689, 623cad2 and 7056ba5

* Fix notification button spanning full width rather than content width

* Add a way to access a singleton to smart filter and use clearer code

* Update view holders using smart input filters to use more singletons

* Fix code style lacking spaces before boolean checks in ifs and others

* Remove all code related to collapsibility preferences, strings included

* Update style to match content warning toggle button

* Update strings to give cleaner differentiation between CW and collapse

* Update smart filter code to use fully qualified names to avoid confusion
This commit is contained in:
HellPie 2018-09-19 19:51:20 +02:00 committed by Ivan Kupalov
commit 4759783d10
17 changed files with 558 additions and 63 deletions

View file

@ -18,6 +18,8 @@ package com.keylesspalace.tusky.viewdata;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.entity.Notification;
import io.reactivex.annotations.NonNull;
/**
* Created by charlag on 12/07/2017.
*
@ -37,11 +39,12 @@ public abstract class NotificationViewData {
private final Notification.Type type;
private final String id;
private final Account account;
@NonNull
private final StatusViewData.Concrete statusViewData;
private final boolean isExpanded;
public Concrete(Notification.Type type, String id, Account account,
StatusViewData.Concrete statusViewData, boolean isExpanded) {
@NonNull StatusViewData.Concrete statusViewData, boolean isExpanded) {
this.type = type;
this.id = id;
this.account = account;
@ -61,6 +64,7 @@ public abstract class NotificationViewData {
return account;
}
@NonNull
public StatusViewData.Concrete getStatusViewData() {
return statusViewData;
}

View file

@ -80,6 +80,8 @@ 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,
@Nullable String spoilerText, Status.Visibility visibility, List<Attachment> attachments,
@ -87,7 +89,8 @@ public abstract class StatusViewData {
boolean isShowingContent, String userFullName, String nickname, String avatar,
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) {
Status.Application application, List<Emoji> statusEmojis, List<Emoji> accountEmojis, @Nullable Card card,
boolean isCollapsible, boolean isCollapsed) {
this.id = id;
this.content = content;
this.reblogged = reblogged;
@ -114,6 +117,8 @@ public abstract class StatusViewData {
this.statusEmojis = statusEmojis;
this.accountEmojis = accountEmojis;
this.card = card;
this.isCollapsible = isCollapsible;
this.isCollapsed = isCollapsed;
}
public String getId() {
@ -226,6 +231,26 @@ public abstract class StatusViewData {
return card;
}
/**
* 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() {
return isCollapsed;
}
@Override public long getViewDataId() {
// Chance of collision is super low and impact of mistake is low as well
return getId().hashCode();
@ -236,31 +261,32 @@ public abstract class StatusViewData {
if (o == null || getClass() != o.getClass()) return false;
Concrete concrete = (Concrete) o;
return reblogged == concrete.reblogged &&
favourited == concrete.favourited &&
isSensitive == concrete.isSensitive &&
isExpanded == concrete.isExpanded &&
isShowingContent == concrete.isShowingContent &&
reblogsCount == concrete.reblogsCount &&
favouritesCount == concrete.favouritesCount &&
rebloggingEnabled == concrete.rebloggingEnabled &&
Objects.equals(id, concrete.id) &&
Objects.equals(content, concrete.content) &&
Objects.equals(spoilerText, concrete.spoilerText) &&
visibility == concrete.visibility &&
Objects.equals(attachments, concrete.attachments) &&
Objects.equals(rebloggedByUsername, concrete.rebloggedByUsername) &&
Objects.equals(rebloggedAvatar, concrete.rebloggedAvatar) &&
Objects.equals(userFullName, concrete.userFullName) &&
Objects.equals(nickname, concrete.nickname) &&
Objects.equals(avatar, concrete.avatar) &&
Objects.equals(createdAt, concrete.createdAt) &&
Objects.equals(inReplyToId, concrete.inReplyToId) &&
Arrays.equals(mentions, concrete.mentions) &&
Objects.equals(senderId, concrete.senderId) &&
Objects.equals(application, concrete.application) &&
favourited == concrete.favourited &&
isSensitive == concrete.isSensitive &&
isExpanded == concrete.isExpanded &&
isShowingContent == concrete.isShowingContent &&
reblogsCount == concrete.reblogsCount &&
favouritesCount == concrete.favouritesCount &&
rebloggingEnabled == concrete.rebloggingEnabled &&
Objects.equals(id, concrete.id) &&
Objects.equals(content, concrete.content) &&
Objects.equals(spoilerText, concrete.spoilerText) &&
visibility == concrete.visibility &&
Objects.equals(attachments, concrete.attachments) &&
Objects.equals(rebloggedByUsername, concrete.rebloggedByUsername) &&
Objects.equals(rebloggedAvatar, concrete.rebloggedAvatar) &&
Objects.equals(userFullName, concrete.userFullName) &&
Objects.equals(nickname, concrete.nickname) &&
Objects.equals(avatar, concrete.avatar) &&
Objects.equals(createdAt, concrete.createdAt) &&
Objects.equals(inReplyToId, concrete.inReplyToId) &&
Arrays.equals(mentions, concrete.mentions) &&
Objects.equals(senderId, concrete.senderId) &&
Objects.equals(application, concrete.application) &&
Objects.equals(statusEmojis, concrete.statusEmojis) &&
Objects.equals(accountEmojis, concrete.accountEmojis) &&
Objects.equals(card, concrete.card);
Objects.equals(card, concrete.card)
&& isCollapsed == concrete.isCollapsed;
}
}
@ -334,6 +360,8 @@ 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() {
}
@ -365,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) {
@ -497,6 +527,30 @@ 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.
*
* @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() {
if (this.statusEmojis == null) statusEmojis = Collections.emptyList();
if (this.accountEmojis == null) accountEmojis = Collections.emptyList();
@ -506,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);
statusEmojis, accountEmojis, card, isCollapsible, isCollapsed);
}
}
}