mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Replace activity details from profile with activities endpoint. Start integrating into adapter.
This commit is contained in:
parent
8efd14ea27
commit
c94d75f90c
6 changed files with 111 additions and 51 deletions
|
@ -92,6 +92,7 @@
|
||||||
<string name="profile_shared_story">Shared the story</string>
|
<string name="profile_shared_story">Shared the story</string>
|
||||||
<string name="profile_button_follow">Follow</string>
|
<string name="profile_button_follow">Follow</string>
|
||||||
<string name="profile_button_unfollow">Following</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_profile">Profile</string>
|
||||||
<string name="menu_refresh">Refresh</string>
|
<string name="menu_refresh">Refresh</string>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.newsblur.fragment.ProfileActivityFragment;
|
||||||
import com.newsblur.fragment.ProfileDetailsFragment;
|
import com.newsblur.fragment.ProfileDetailsFragment;
|
||||||
import com.newsblur.network.APIManager;
|
import com.newsblur.network.APIManager;
|
||||||
import com.newsblur.domain.ActivityDetails;
|
import com.newsblur.domain.ActivityDetails;
|
||||||
|
import com.newsblur.network.domain.ActivitiesResponse;
|
||||||
import com.newsblur.network.domain.ProfileResponse;
|
import com.newsblur.network.domain.ProfileResponse;
|
||||||
import com.newsblur.util.PrefsUtils;
|
import com.newsblur.util.PrefsUtils;
|
||||||
|
|
||||||
|
@ -84,9 +85,10 @@ public class Profile extends NbActivity {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
if (!TextUtils.isEmpty(userId)) {
|
if (!TextUtils.isEmpty(userId)) {
|
||||||
profileResponse = apiManager.getUser(getIntent().getStringExtra(USER_ID));
|
String intentUserId = getIntent().getStringExtra(USER_ID);
|
||||||
|
profileResponse = apiManager.getUser(intentUserId);
|
||||||
user = profileResponse.user;
|
user = profileResponse.user;
|
||||||
activities = profileResponse.activities;
|
activities = apiManager.getActivities(intentUserId).activities;
|
||||||
} else {
|
} else {
|
||||||
apiManager.updateUserProfile();
|
apiManager.updateUserProfile();
|
||||||
user = PrefsUtils.getUserDetails(Profile.this);
|
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
|
// have failed then user.id == null would cause a force close
|
||||||
if (user.id != null) {
|
if (user.id != null) {
|
||||||
profileResponse = apiManager.getUser(user.id);
|
profileResponse = apiManager.getUser(user.id);
|
||||||
if (profileResponse != null) {
|
ActivitiesResponse activitiesResponse = apiManager.getActivities(user.id);
|
||||||
activities = profileResponse.activities;
|
if (activitiesResponse != null) {
|
||||||
|
activities = activitiesResponse.activities;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class APIConstants {
|
||||||
public static final String URL_FOLLOW = NEWSBLUR_URL + "/social/follow";
|
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_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_USER_INTERACTIONS = NEWSBLUR_URL + "/social/interactions";
|
||||||
public static final String URL_RIVER_STORIES = NEWSBLUR_URL + "/reader/river_stories";
|
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";
|
public static final String URL_SHARED_RIVER_STORIES = NEWSBLUR_URL + "/social/river_stories";
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.newsblur.domain.Feed;
|
||||||
import com.newsblur.domain.FeedResult;
|
import com.newsblur.domain.FeedResult;
|
||||||
import com.newsblur.domain.Story;
|
import com.newsblur.domain.Story;
|
||||||
import com.newsblur.domain.ValueMultimap;
|
import com.newsblur.domain.ValueMultimap;
|
||||||
|
import com.newsblur.network.domain.ActivitiesResponse;
|
||||||
import com.newsblur.network.domain.FeedFolderResponse;
|
import com.newsblur.network.domain.FeedFolderResponse;
|
||||||
import com.newsblur.network.domain.NewsBlurResponse;
|
import com.newsblur.network.domain.NewsBlurResponse;
|
||||||
import com.newsblur.network.domain.ProfileResponse;
|
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) {
|
public StoryTextResponse getStoryText(String feedId, String storyId) {
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(APIConstants.PARAMETER_FEEDID, feedId);
|
values.put(APIConstants.PARAMETER_FEEDID, feedId);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
|
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
private ImageLoader imageLoader;
|
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 ForegroundColorSpan highlight, darkgray;
|
||||||
private String TAG = "ActivitiesAdapter";
|
private String TAG = "ActivitiesAdapter";
|
||||||
private Context context;
|
private Context context;
|
||||||
|
@ -52,6 +52,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
likedComment = resources.getString(R.string.profile_liked_comment);
|
likedComment = resources.getString(R.string.profile_liked_comment);
|
||||||
sharedStory = resources.getString(R.string.profile_shared_story);
|
sharedStory = resources.getString(R.string.profile_shared_story);
|
||||||
withComment = resources.getString(R.string.profile_with_comment);
|
withComment = resources.getString(R.string.profile_with_comment);
|
||||||
|
subscribedTo = resources.getString(R.string.profile_subscribed_to);
|
||||||
ago = resources.getString(R.string.profile_ago);
|
ago = resources.getString(R.string.profile_ago);
|
||||||
|
|
||||||
if (PrefsUtils.isLightThemeSelected(context)) {
|
if (PrefsUtils.isLightThemeSelected(context)) {
|
||||||
|
@ -88,6 +89,7 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
|
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
|
||||||
|
|
||||||
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
|
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
|
||||||
|
// TODO images for each category type
|
||||||
if (activity.user != null) {
|
if (activity.user != null) {
|
||||||
imageLoader.displayImage(activity.user.photoUrl, imageView);
|
imageLoader.displayImage(activity.user.photoUrl, imageView);
|
||||||
} else if (TextUtils.equals(activity.category, "sharedstory")) {
|
} else if (TextUtils.equals(activity.category, "sharedstory")) {
|
||||||
|
@ -96,15 +98,45 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
imageView.setImageResource(R.drawable.logo);
|
imageView.setImageResource(R.drawable.logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.equals(activity.category, "follow")) {
|
// 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")) {
|
||||||
|
addCommentLikeContent(activity, stringBuilder, usernameClick);
|
||||||
|
} else if (TextUtils.equals(activity.category, "comment_reply")) {
|
||||||
|
addCommentReplyContent(activity, stringBuilder, usernameClick);
|
||||||
|
} else if (TextUtils.equals(activity.category, "sharedstory")) {
|
||||||
|
addSharedStoryContent(activity, stringBuilder, usernameClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
activityText.setText(stringBuilder);
|
||||||
|
activityText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
|
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(startedFollowing);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.user.username);
|
stringBuilder.append(activity.user.username);
|
||||||
stringBuilder.setSpan(darkgray, 0, startedFollowing.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
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(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);
|
||||||
stringBuilder.setSpan(highlight, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
}
|
||||||
} else if (TextUtils.equals(activity.category, "comment_like")) {
|
|
||||||
|
private void addCommentLikeContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
|
||||||
stringBuilder.append(likedComment);
|
stringBuilder.append(likedComment);
|
||||||
stringBuilder.append(" \"");
|
stringBuilder.append(" \"");
|
||||||
stringBuilder.append(activity.content);
|
stringBuilder.append(activity.content);
|
||||||
|
@ -115,7 +147,9 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
stringBuilder.setSpan(highlight, likedComment.length() + 1, likedComment.length() + 3 + activity.content.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(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);
|
stringBuilder.setSpan(usernameClick, likedComment.length() + 3 + activity.content.length() + 4, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
} else if (TextUtils.equals(activity.category, "comment_reply")) {
|
}
|
||||||
|
|
||||||
|
private void addCommentReplyContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
|
||||||
stringBuilder.append(repliedTo);
|
stringBuilder.append(repliedTo);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.user.username);
|
stringBuilder.append(activity.user.username);
|
||||||
|
@ -127,7 +161,9 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
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(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);
|
stringBuilder.setSpan(darkgray, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
} else if (TextUtils.equals(activity.category, "sharedstory")) {
|
}
|
||||||
|
|
||||||
|
private void addSharedStoryContent(ActivityDetails activity, SpannableStringBuilder stringBuilder, ClickableSpan usernameClick) {
|
||||||
stringBuilder.append(sharedStory);
|
stringBuilder.append(sharedStory);
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
stringBuilder.append(activity.title);
|
stringBuilder.append(activity.title);
|
||||||
|
@ -144,11 +180,4 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivityDetails> {
|
||||||
stringBuilder.setSpan(darkgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
stringBuilder.setSpan(darkgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activityText.setText(stringBuilder);
|
|
||||||
activityText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue