Replace activity details from profile with activities endpoint. Start integrating into adapter.

This commit is contained in:
Mark Anderson 2015-05-24 23:29:43 +01:00
parent 8efd14ea27
commit c94d75f90c
6 changed files with 111 additions and 51 deletions

View file

@ -92,6 +92,7 @@
<string name="profile_shared_story">Shared the story</string>
<string name="profile_button_follow">Follow</string>
<string name="profile_button_unfollow">Following</string>
<string name="profile_subscribed_to">You subcribed to</string>
<string name="menu_profile">Profile</string>
<string name="menu_refresh">Refresh</string>

View file

@ -13,6 +13,7 @@ import com.newsblur.fragment.ProfileActivityFragment;
import com.newsblur.fragment.ProfileDetailsFragment;
import com.newsblur.network.APIManager;
import com.newsblur.domain.ActivityDetails;
import com.newsblur.network.domain.ActivitiesResponse;
import com.newsblur.network.domain.ProfileResponse;
import com.newsblur.util.PrefsUtils;
@ -84,9 +85,10 @@ public class Profile extends NbActivity {
@Override
protected Void doInBackground(Void... params) {
if (!TextUtils.isEmpty(userId)) {
profileResponse = apiManager.getUser(getIntent().getStringExtra(USER_ID));
String intentUserId = getIntent().getStringExtra(USER_ID);
profileResponse = apiManager.getUser(intentUserId);
user = profileResponse.user;
activities = profileResponse.activities;
activities = apiManager.getActivities(intentUserId).activities;
} else {
apiManager.updateUserProfile();
user = PrefsUtils.getUserDetails(Profile.this);
@ -94,8 +96,9 @@ public class Profile extends NbActivity {
// have failed then user.id == null would cause a force close
if (user.id != null) {
profileResponse = apiManager.getUser(user.id);
if (profileResponse != null) {
activities = profileResponse.activities;
ActivitiesResponse activitiesResponse = apiManager.getActivities(user.id);
if (activitiesResponse != null) {
activities = activitiesResponse.activities;
}
}
}

View file

@ -16,7 +16,8 @@ public class APIConstants {
public static final String URL_MY_PROFILE = NEWSBLUR_URL + "/social/load_user_profile";
public static final String URL_FOLLOW = NEWSBLUR_URL + "/social/follow";
public static final String URL_UNFOLLOW = NEWSBLUR_URL + "/social/unfollow";
public static final String URL_USER_ACTIVITIES = NEWSBLUR_URL + "/social/activities";
public static final String URL_USER_INTERACTIONS = NEWSBLUR_URL + "/social/interactions";
public static final String URL_RIVER_STORIES = NEWSBLUR_URL + "/reader/river_stories";
public static final String URL_SHARED_RIVER_STORIES = NEWSBLUR_URL + "/social/river_stories";

View file

@ -26,6 +26,7 @@ import com.newsblur.domain.Feed;
import com.newsblur.domain.FeedResult;
import com.newsblur.domain.Story;
import com.newsblur.domain.ValueMultimap;
import com.newsblur.network.domain.ActivitiesResponse;
import com.newsblur.network.domain.FeedFolderResponse;
import com.newsblur.network.domain.NewsBlurResponse;
import com.newsblur.network.domain.ProfileResponse;
@ -437,6 +438,18 @@ public class APIManager {
}
}
public ActivitiesResponse getActivities(String userId) {
final ContentValues values = new ContentValues();
values.put(APIConstants.PARAMETER_USER_ID, userId);
final APIResponse response = get(APIConstants.URL_USER_ACTIVITIES, values);
if (!response.isError()) {
ActivitiesResponse activitiesResponse = (ActivitiesResponse) response.getResponse(gson, ActivitiesResponse.class);
return activitiesResponse;
} else {
return null;
}
}
public StoryTextResponse getStoryText(String feedId, String storyId) {
final ContentValues values = new ContentValues();
values.put(APIConstants.PARAMETER_FEEDID, feedId);

View file

@ -0,0 +1,13 @@
package com.newsblur.network.domain;
import com.google.gson.annotations.SerializedName;
import com.newsblur.domain.ActivityDetails;
/**
* Response for /social/activities endpoint
*/
public class ActivitiesResponse extends NewsBlurResponse {
@SerializedName("activities")
public ActivityDetails[] activities;
}

View file

@ -28,7 +28,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
private LayoutInflater inflater;
private ImageLoader imageLoader;
private final String startedFollowing, ago, repliedTo, sharedStory, withComment, likedComment;
private final String startedFollowing, ago, repliedTo, sharedStory, withComment, likedComment, subscribedTo;
private ForegroundColorSpan highlight, darkgray;
private String TAG = "ActivitiesAdapter";
private Context context;
@ -52,6 +52,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
likedComment = resources.getString(R.string.profile_liked_comment);
sharedStory = resources.getString(R.string.profile_shared_story);
withComment = resources.getString(R.string.profile_with_comment);
subscribedTo = resources.getString(R.string.profile_subscribed_to);
ago = resources.getString(R.string.profile_ago);
if (PrefsUtils.isLightThemeSelected(context)) {
@ -88,6 +89,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
// TODO images for each category type
if (activity.user != null) {
imageLoader.displayImage(activity.user.photoUrl, imageView);
} else if (TextUtils.equals(activity.category, "sharedstory")) {
@ -95,54 +97,19 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
} else {
imageView.setImageResource(R.drawable.logo);
}
if (TextUtils.equals(activity.category, "follow")) {
stringBuilder.append(startedFollowing);
stringBuilder.append(" ");
stringBuilder.append(activity.user.username);
stringBuilder.setSpan(darkgray, 0, startedFollowing.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// TODO signup
// TODO star
if (TextUtils.equals(activity.category, "feedsub")) {
addFeedsubscriptionContent(activity, stringBuilder, usernameClick);
} else if (TextUtils.equals(activity.category, "follow")) {
addFollowContent(activity, stringBuilder, usernameClick);
} else if (TextUtils.equals(activity.category, "comment_like")) {
stringBuilder.append(likedComment);
stringBuilder.append(" \"");
stringBuilder.append(activity.content);
stringBuilder.append("\" ");
stringBuilder.append("by ");
stringBuilder.append(activity.user.username);
stringBuilder.setSpan(darkgray, 0, likedComment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, likedComment.length() + 1, likedComment.length() + 3 + activity.content.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(darkgray, stringBuilder.length() - activity.user.username.length() - 4, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, likedComment.length() + 3 + activity.content.length() + 4, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
addCommentLikeContent(activity, stringBuilder, usernameClick);
} else if (TextUtils.equals(activity.category, "comment_reply")) {
stringBuilder.append(repliedTo);
stringBuilder.append(" ");
stringBuilder.append(activity.user.username);
stringBuilder.append(": \"");
stringBuilder.append(activity.content);
stringBuilder.append("\"");
stringBuilder.setSpan(darkgray, 0, repliedTo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(darkgray, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
addCommentReplyContent(activity, stringBuilder, usernameClick);
} else if (TextUtils.equals(activity.category, "sharedstory")) {
stringBuilder.append(sharedStory);
stringBuilder.append(" ");
stringBuilder.append(activity.title);
stringBuilder.append(" ");
if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.append(withComment);
stringBuilder.append(": \"");
stringBuilder.append(activity.content);
stringBuilder.append("\"");
}
stringBuilder.setSpan(darkgray, 0, sharedStory.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, sharedStory.length() + 1, sharedStory.length() + 1 + activity.title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.setSpan(darkgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
addSharedStoryContent(activity, stringBuilder, usernameClick);
}
activityText.setText(stringBuilder);
@ -151,4 +118,66 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
return view;
}
private void addFeedsubscriptionContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
stringBuilder.append(subscribedTo);
stringBuilder.append(" ");
stringBuilder.append(activity.content);
stringBuilder.setSpan(darkgray, 0, subscribedTo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, subscribedTo.length() + 1, subscribedTo.length() + 1 + activity.content.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, subscribedTo.length() + 1, subscribedTo.length() + 1 + activity.content.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void addFollowContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
stringBuilder.append(startedFollowing);
stringBuilder.append(" ");
stringBuilder.append(activity.user.username);
stringBuilder.setSpan(darkgray, 0, startedFollowing.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void addCommentLikeContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
stringBuilder.append(likedComment);
stringBuilder.append(" \"");
stringBuilder.append(activity.content);
stringBuilder.append("\" ");
stringBuilder.append("by ");
stringBuilder.append(activity.user.username);
stringBuilder.setSpan(darkgray, 0, likedComment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, likedComment.length() + 1, likedComment.length() + 3 + activity.content.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(darkgray, stringBuilder.length() - activity.user.username.length() - 4, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, likedComment.length() + 3 + activity.content.length() + 4, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void addCommentReplyContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
stringBuilder.append(repliedTo);
stringBuilder.append(" ");
stringBuilder.append(activity.user.username);
stringBuilder.append(": \"");
stringBuilder.append(activity.content);
stringBuilder.append("\"");
stringBuilder.setSpan(darkgray, 0, repliedTo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(usernameClick, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(darkgray, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void addSharedStoryContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
stringBuilder.append(sharedStory);
stringBuilder.append(" ");
stringBuilder.append(activity.title);
stringBuilder.append(" ");
if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.append(withComment);
stringBuilder.append(": \"");
stringBuilder.append(activity.content);
stringBuilder.append("\"");
}
stringBuilder.setSpan(darkgray, 0, sharedStory.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(highlight, sharedStory.length() + 1, sharedStory.length() + 1 + activity.title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!TextUtils.isEmpty(activity.content)) {
stringBuilder.setSpan(darkgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}