Guard against empty strings in shared story content.

This commit is contained in:
sictiru 2023-02-06 18:39:14 -08:00
parent 3e19821489
commit 65b1f68dde

View file

@ -139,6 +139,8 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
private CharSequence getSharedStoryContent(ActivityDetails activity) { private CharSequence getSharedStoryContent(ActivityDetails activity) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
int usernameLength; int usernameLength;
int reSharedLength = 0;
int titleLength = 0;
if (activity.user != null) { if (activity.user != null) {
usernameLength = activity.user.username.length(); usernameLength = activity.user.username.length();
stringBuilder.append(activity.user.username); stringBuilder.append(activity.user.username);
@ -147,20 +149,25 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
stringBuilder.append(UNKNOWN_USERNAME); stringBuilder.append(UNKNOWN_USERNAME);
} }
stringBuilder.append(" "); stringBuilder.append(" ");
if (!TextUtils.isEmpty(reshared)) {
stringBuilder.append(reshared); stringBuilder.append(reshared);
stringBuilder.append(" "); stringBuilder.append(" ");
reSharedLength = reshared.length();
}
if (!TextUtils.isEmpty(activity.title)) {
stringBuilder.append(activity.title); stringBuilder.append(activity.title);
stringBuilder.append(" "); stringBuilder.append(" ");
titleLength = activity.title.length();
}
if (!TextUtils.isEmpty(activity.content)) { if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.append("\n\n\""); stringBuilder.append("\n\n\"");
stringBuilder.append(activity.content); stringBuilder.append(activity.content);
stringBuilder.append("\""); stringBuilder.append("\"");
} }
int titleSpanStart = usernameLength + 1 + reshared.length() + 1; int titleSpanStart = usernameLength + 1 + reSharedLength + 1;
int titleLength = activity.title.length();
stringBuilder.setSpan(linkColor, 0, titleSpanStart + titleLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(linkColor, 0, titleSpanStart + titleLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(contentColor, usernameLength + 1, usernameLength + 1 + reshared.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(contentColor, usernameLength + 1, usernameLength + 1 + reSharedLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!TextUtils.isEmpty(activity.content)) { if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.setSpan(quoteColor, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(quoteColor, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);