mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Check for null users for interactions such as likes, replies and follows.
This commit is contained in:
parent
6092570960
commit
585c46e168
3 changed files with 35 additions and 9 deletions
|
@ -95,25 +95,39 @@ public class ActivitiesAdapter extends ActivityDetailsAdapter {
|
||||||
|
|
||||||
private CharSequence getFollowContent(ActivityDetails activity, String userString) {
|
private CharSequence getFollowContent(ActivityDetails activity, String userString) {
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
|
int usernameLength;
|
||||||
stringBuilder.append(userString);
|
stringBuilder.append(userString);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(startedFollowing);
|
stringBuilder.append(startedFollowing);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.user.username);
|
if (activity.user != null) {
|
||||||
|
stringBuilder.append(activity.user.username);
|
||||||
|
usernameLength = activity.user.username.length();
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(UNKNOWN_USERNAME);
|
||||||
|
usernameLength = UNKNOWN_USERNAME.length();
|
||||||
|
}
|
||||||
|
|
||||||
int contentColorLength = userString.length() + startedFollowing.length() + 1;
|
int contentColorLength = userString.length() + startedFollowing.length() + 1;
|
||||||
stringBuilder.setSpan(contentColor, 0, contentColorLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(contentColor, 0, contentColorLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
stringBuilder.setSpan(linkColor, contentColorLength + 1, contentColorLength + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(linkColor, contentColorLength + 1, contentColorLength + 1 + usernameLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
return stringBuilder;
|
return stringBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getCommentLikeContent(ActivityDetails activity, String userString) {
|
private CharSequence getCommentLikeContent(ActivityDetails activity, String userString) {
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
|
int usernameLength;
|
||||||
stringBuilder.append(userString);
|
stringBuilder.append(userString);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(favorited);
|
stringBuilder.append(favorited);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.user.username);
|
if (activity.user != null) {
|
||||||
|
stringBuilder.append(activity.user.username);
|
||||||
|
usernameLength = activity.user.username.length();
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(UNKNOWN_USERNAME);
|
||||||
|
usernameLength = UNKNOWN_USERNAME.length();
|
||||||
|
}
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(commentsOn);
|
stringBuilder.append(commentsOn);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
|
@ -122,7 +136,6 @@ public class ActivitiesAdapter extends ActivityDetailsAdapter {
|
||||||
stringBuilder.append(activity.content);
|
stringBuilder.append(activity.content);
|
||||||
stringBuilder.append("\" ");
|
stringBuilder.append("\" ");
|
||||||
|
|
||||||
int usernameLength = activity.user.username.length();
|
|
||||||
stringBuilder.setSpan(contentColor, 0, userString.length() + favorited.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(contentColor, 0, userString.length() + favorited.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
int usernameSpanStart = userString.length() + favorited.length() + 2;
|
int usernameSpanStart = userString.length() + favorited.length() + 2;
|
||||||
stringBuilder.setSpan(linkColor, usernameSpanStart, usernameSpanStart + usernameLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(linkColor, usernameSpanStart, usernameSpanStart + usernameLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -138,17 +151,24 @@ public class ActivitiesAdapter extends ActivityDetailsAdapter {
|
||||||
|
|
||||||
private CharSequence getCommentReplyContent(ActivityDetails activity, String userString) {
|
private CharSequence getCommentReplyContent(ActivityDetails activity, String userString) {
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
|
int usernameLength;
|
||||||
stringBuilder.append(userString);
|
stringBuilder.append(userString);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(repliedTo);
|
stringBuilder.append(repliedTo);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.user.username);
|
if (activity.user != null) {
|
||||||
|
stringBuilder.append(activity.user.username);
|
||||||
|
usernameLength = activity.user.username.length();
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(UNKNOWN_USERNAME);
|
||||||
|
usernameLength = UNKNOWN_USERNAME.length();
|
||||||
|
}
|
||||||
stringBuilder.append("\n\n\"");
|
stringBuilder.append("\n\n\"");
|
||||||
stringBuilder.append(activity.content);
|
stringBuilder.append(activity.content);
|
||||||
stringBuilder.append("\"");
|
stringBuilder.append("\"");
|
||||||
|
|
||||||
stringBuilder.setSpan(contentColor, 0, userString.length() + repliedTo.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(contentColor, 0, userString.length() + repliedTo.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
stringBuilder.setSpan(linkColor, userString.length() + repliedTo.length() + 2, userString.length() + repliedTo.length() + 2 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(linkColor, userString.length() + repliedTo.length() + 2, userString.length() + repliedTo.length() + 2 + usernameLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
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);
|
||||||
return stringBuilder;
|
return stringBuilder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
|
||||||
protected ForegroundColorSpan linkColor, contentColor, quoteColor;
|
protected ForegroundColorSpan linkColor, contentColor, quoteColor;
|
||||||
protected final UserDetails currentUserDetails;
|
protected final UserDetails currentUserDetails;
|
||||||
protected final boolean userIsYou;
|
protected final boolean userIsYou;
|
||||||
|
protected final String UNKNOWN_USERNAME = "Unknown";
|
||||||
|
|
||||||
public ActivityDetailsAdapter(final Context context, UserDetails user, ImageLoader iconLoader) {
|
public ActivityDetailsAdapter(final Context context, UserDetails user, ImageLoader iconLoader) {
|
||||||
super(context, R.layout.row_activity); // final argument seems unused since we override getView()
|
super(context, R.layout.row_activity); // final argument seems unused since we override getView()
|
||||||
|
|
|
@ -17,7 +17,6 @@ import com.newsblur.util.ImageLoader;
|
||||||
public class InteractionsAdapter extends ActivityDetailsAdapter {
|
public class InteractionsAdapter extends ActivityDetailsAdapter {
|
||||||
|
|
||||||
private final String nowFollowingYou, repliedToYour, comment, reply, favoritedComments, reshared, your, you;
|
private final String nowFollowingYou, repliedToYour, comment, reply, favoritedComments, reshared, your, you;
|
||||||
private final String UNKNOWN_USERNAME = "Unknown";
|
|
||||||
|
|
||||||
public InteractionsAdapter(final Context context, UserDetails user, ImageLoader iconLoader) {
|
public InteractionsAdapter(final Context context, UserDetails user, ImageLoader iconLoader) {
|
||||||
super(context, user, iconLoader);
|
super(context, user, iconLoader);
|
||||||
|
@ -139,7 +138,14 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
|
||||||
|
|
||||||
private CharSequence getSharedStoryContent(ActivityDetails activity) {
|
private CharSequence getSharedStoryContent(ActivityDetails activity) {
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
stringBuilder.append(activity.user.username);
|
int usernameLength;
|
||||||
|
if (activity.user != null) {
|
||||||
|
usernameLength = activity.user.username.length();
|
||||||
|
stringBuilder.append(activity.user.username);
|
||||||
|
} else {
|
||||||
|
usernameLength = UNKNOWN_USERNAME.length();
|
||||||
|
stringBuilder.append(UNKNOWN_USERNAME);
|
||||||
|
}
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(reshared);
|
stringBuilder.append(reshared);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
|
@ -151,7 +157,6 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
|
||||||
stringBuilder.append("\"");
|
stringBuilder.append("\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
int usernameLength = activity.user.username.length();
|
|
||||||
int titleSpanStart = usernameLength + 1 + reshared.length() + 1;
|
int titleSpanStart = usernameLength + 1 + reshared.length() + 1;
|
||||||
int titleLength = activity.title.length();
|
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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue