You vs username for interactions view.

This commit is contained in:
Mark Anderson 2015-06-22 23:10:42 +01:00
parent 4f7fc797d0
commit fd7c0e8fe8
4 changed files with 36 additions and 18 deletions

View file

@ -84,9 +84,11 @@
<string name="profile_recent_interactions">Interactions</string>
<string name="profile_started_following">followed</string>
<string name="profile_you">You</string>
<string name="profile_now_following">is now following you</string>
<string name="profile_you_lower">you</string>
<string name="profile_your">your</string>
<string name="profile_now_following">is now following %1$s</string>
<string name="profile_replied_to">Replied to</string>
<string name="profile_replied_to_your">replied to your</string>
<string name="profile_replied_to_your">replied to %1$s</string>
<string name="profile_shared_story">shared</string>
<string name="profile_comment">comment</string>
<string name="profile_reply">reply</string>
@ -96,7 +98,7 @@
<string name="profile_saved">saved</string>
<string name="profile_reshared">re-shared</string>
<string name="profile_favorited">favorited</string>
<string name="profile_favorited_comments">favorited your comments on</string>
<string name="profile_favorited_comments">favorited %1$s comments on</string>
<string name="profile_signup">signed up for Newsblur</string>
<string name="profile_comments_on">comments on</string>
<string name="profile_feed_not_available">You are no longer subscribed to this feed</string>

View file

@ -16,7 +16,6 @@ import com.newsblur.domain.UserDetails;
public class ActivitiesAdapter extends ActivityDetailsAdapter {
private final String startedFollowing, repliedTo, favorited, subscribedTo, saved, signup, commentsOn, sharedStory, you;
private final boolean userIsYou;
public ActivitiesAdapter(final Context context, UserDetails user) {
super(context, user);
@ -32,7 +31,6 @@ public class ActivitiesAdapter extends ActivityDetailsAdapter {
sharedStory = resources.getString(R.string.profile_shared_story);
you = resources.getString(R.string.profile_you);
userIsYou = user.userId == null;
}
@Override

View file

@ -28,7 +28,8 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
private String TAG = "ActivitiesAdapter";
private Context context;
protected UserDetails currentUserDetails;
protected final boolean userIsYou;
public ActivityDetailsAdapter(final Context context, UserDetails user) {
super(context, R.id.row_activity_text);
inflater = LayoutInflater.from(context);
@ -49,6 +50,8 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
contentColor = new ForegroundColorSpan(resources.getColor(R.color.white));
quoteColor = new ForegroundColorSpan(resources.getColor(R.color.lightgray));
}
userIsYou = user.userId == null;
}
@Override

View file

@ -15,7 +15,7 @@ import com.newsblur.domain.UserDetails;
*/
public class InteractionsAdapter extends ActivityDetailsAdapter {
private final String nowFollowingYou, repliedToYour, comment, reply, favoritedComments, reshared;
private final String nowFollowingYou, repliedToYour, comment, reply, favoritedComments, reshared, your, you;
public InteractionsAdapter(final Context context, UserDetails user) {
super(context, user);
@ -27,38 +27,53 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
reply = resources.getString(R.string.profile_reply);
favoritedComments = resources.getString(R.string.profile_favorited_comments);
reshared = resources.getString(R.string.profile_reshared);
your = resources.getString(R.string.profile_your);
you = resources.getString(R.string.profile_you_lower);
}
@Override
protected CharSequence getTextForActivity(ActivityDetails activity) {
if (activity.category == ActivityDetails.Category.FOLLOW) {
return getFollowContent(activity);
String userString = you;
if (!userIsYou) {
userString = currentUserDetails.username;
}
return getFollowContent(activity, userString);
} else if (activity.category == ActivityDetails.Category.COMMENT_LIKE) {
return getCommentLikeContent(activity);
String userString = your;
if (!userIsYou) {
userString = currentUserDetails.username + "'s";
}
return getCommentLikeContent(activity, userString);
} else if (activity.category == ActivityDetails.Category.COMMENT_REPLY ||
activity.category == ActivityDetails.Category.REPLY_REPLY) {
return getCommentReplyContent(activity);
String userString = your;
if (!userIsYou) {
userString = currentUserDetails.username + "'s";
}
return getCommentReplyContent(activity, userString);
} else {
return getSharedStoryContent(activity);
}
}
private CharSequence getFollowContent(ActivityDetails activity) {
private CharSequence getFollowContent(ActivityDetails activity, String userString) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(activity.user.username);
stringBuilder.append(" ");
stringBuilder.append(nowFollowingYou);
stringBuilder.append(String.format(nowFollowingYou, userString));
stringBuilder.setSpan(linkColor, 0, activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(contentColor, activity.user.username.length() + 1, activity.user.username.length() + 1 + nowFollowingYou.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return stringBuilder;
}
private CharSequence getCommentLikeContent(ActivityDetails activity) {
private CharSequence getCommentLikeContent(ActivityDetails activity, String userString) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(activity.user.username);
stringBuilder.append(" ");
stringBuilder.append(favoritedComments);
String favoritedString = String.format(favoritedComments, userString);
stringBuilder.append(favoritedString );
stringBuilder.append(" ");
stringBuilder.append(activity.title);
stringBuilder.append("\n\n\"");
@ -66,21 +81,21 @@ public class InteractionsAdapter extends ActivityDetailsAdapter {
stringBuilder.append("\" ");
int usernameLength = activity.user.username.length();
int titleSpanStart = usernameLength + 1 + favoritedComments.length() + 1;
int titleSpanStart = usernameLength + 1 + favoritedString.length() + 1;
int titleLength = activity.title.length();
stringBuilder.setSpan(linkColor, 0, titleSpanStart + titleLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(contentColor, usernameLength + 1, usernameLength + 1 + favoritedComments.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(contentColor, usernameLength + 1, usernameLength + 1 + favoritedString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int quoteSpanStart = titleSpanStart + titleLength;
stringBuilder.setSpan(quoteColor, quoteSpanStart, quoteSpanStart + activity.content.length() + 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return stringBuilder;
}
private CharSequence getCommentReplyContent(ActivityDetails activity) {
private CharSequence getCommentReplyContent(ActivityDetails activity, String userString) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(activity.user.username);
stringBuilder.append(" ");
stringBuilder.append(repliedToYour);
stringBuilder.append(String.format(repliedToYour, userString));
stringBuilder.append(" ");
int commentReplyLength = 0;
if (activity.category == ActivityDetails.Category.COMMENT_REPLY) {