mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Added ability to navigate between profiles and dynamically load profiles.
This commit is contained in:
parent
c752f0c148
commit
e20d58a949
7 changed files with 91 additions and 43 deletions
|
@ -18,7 +18,7 @@
|
|||
android:id="@+id/profile_details_activitylist"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@color/lightgray"
|
||||
android:background="@drawable/list_background"
|
||||
android:divider="@drawable/divider_dark"
|
||||
android:dividerHeight="1px" />
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
@ -28,18 +28,19 @@ public class Profile extends SherlockFragmentActivity {
|
|||
private ProfileDetailsFragment detailsFragment;
|
||||
private ProfileResponse profileResponse;
|
||||
private ProfileActivityFragment activitiesFragment;
|
||||
|
||||
private String userId = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_profile);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
apiManager = new APIManager(this);
|
||||
|
||||
userId = getIntent().getStringExtra(USER_ID);
|
||||
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
|
||||
if (fragmentManager.findFragmentByTag(detailsTag) == null) {
|
||||
Log.d(TAG , "Adding current new fragment");
|
||||
FragmentTransaction detailsTransaction = fragmentManager.beginTransaction();
|
||||
detailsFragment = new ProfileDetailsFragment();
|
||||
detailsFragment.setRetainInstance(true);
|
||||
|
@ -70,26 +71,24 @@ public class Profile extends SherlockFragmentActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private class LoadUserTask extends AsyncTask<Void, Void, ProfileResponse> {
|
||||
private class LoadUserTask extends AsyncTask<Void, Void, Void> {
|
||||
private UserProfile user;
|
||||
private ActivitiesResponse[] activities;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (getIntent().getStringExtra(USER_ID) == null) {
|
||||
detailsFragment.setUser(PrefsUtil.getUserDetails(Profile.this));
|
||||
if (TextUtils.isEmpty(userId)) {
|
||||
detailsFragment.setUser(PrefsUtil.getUserDetails(Profile.this), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProfileResponse doInBackground(Void... params) {
|
||||
if (getIntent().getStringExtra(USER_ID) != null) {
|
||||
Log.d(TAG, "Viewing a user.");
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (!TextUtils.isEmpty(userId)) {
|
||||
profileResponse = apiManager.getUser(getIntent().getStringExtra(USER_ID));
|
||||
user = profileResponse.user;
|
||||
activities = profileResponse.activities;
|
||||
} else {
|
||||
Log.d(TAG, "Viewing our own profile");
|
||||
apiManager.updateUserProfile();
|
||||
user = PrefsUtil.getUserDetails(Profile.this);
|
||||
profileResponse = apiManager.getUser(user.id);
|
||||
|
@ -101,15 +100,11 @@ public class Profile extends SherlockFragmentActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ProfileResponse result) {
|
||||
protected void onPostExecute(Void result) {
|
||||
if (user != null) {
|
||||
detailsFragment.setUser(user);
|
||||
detailsFragment.setUser(user, TextUtils.isEmpty(userId));
|
||||
activitiesFragment.setActivities(activities);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -53,9 +53,20 @@ public class UserProfile {
|
|||
public String feedLink;
|
||||
|
||||
@SerializedName("popular_publishers")
|
||||
public String popularPublishers;
|
||||
public Publisher[] popularPublishers;
|
||||
|
||||
@SerializedName("photo_url")
|
||||
public String photoUrl;
|
||||
|
||||
public class Publisher {
|
||||
|
||||
@SerializedName("story_count")
|
||||
int storyCount;
|
||||
|
||||
@SerializedName("feed_title")
|
||||
String feedTitle;
|
||||
|
||||
int id;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.domain.UserProfile;
|
||||
import com.newsblur.util.ImageLoader;
|
||||
import com.newsblur.util.PrefsUtil;
|
||||
import com.newsblur.util.UIUtils;
|
||||
|
||||
|
@ -21,16 +22,20 @@ public class ProfileDetailsFragment extends Fragment {
|
|||
private TextView username, bio, location, sharedCount, followerCount, followingCount, website;
|
||||
private ImageView imageView;
|
||||
private String noBio, noLocation;
|
||||
private boolean viewingSelf = false;
|
||||
private ImageLoader imageLoader;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
noBio = getString(R.string.profile_no_bio);
|
||||
noLocation = getActivity().getResources().getString(R.string.profile_no_location);
|
||||
imageLoader = new ImageLoader(getActivity());
|
||||
}
|
||||
|
||||
public void setUser(final UserProfile user) {
|
||||
public void setUser(final UserProfile user, final boolean viewingSelf) {
|
||||
this.user = user;
|
||||
this.viewingSelf = viewingSelf;
|
||||
if (username != null) {
|
||||
setUserFields();
|
||||
}
|
||||
|
@ -82,9 +87,13 @@ public class ProfileDetailsFragment extends Fragment {
|
|||
|
||||
followingCount.setText("" + user.followingCount);
|
||||
|
||||
Bitmap userPicture = PrefsUtil.getUserImage(getActivity());
|
||||
userPicture = UIUtils.roundCorners(userPicture, 10f);
|
||||
imageView.setImageBitmap(userPicture);
|
||||
if (!viewingSelf) {
|
||||
imageLoader.DisplayImage(user.photoUrl, imageView);
|
||||
} else {
|
||||
Bitmap userPicture = PrefsUtil.getUserImage(getActivity());
|
||||
userPicture = UIUtils.roundCorners(userPicture, 10f);
|
||||
imageView.setImageBitmap(userPicture);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ public class ActivitiesResponse {
|
|||
@SerializedName("with_user")
|
||||
public WithUser user;
|
||||
|
||||
@SerializedName("with_userid")
|
||||
public String withUserId;
|
||||
@SerializedName("with_user_id")
|
||||
public String id;
|
||||
|
||||
|
||||
public class WithUser {
|
||||
|
|
|
@ -38,7 +38,6 @@ public class PrefsUtil {
|
|||
edit.putString(PrefConstants.USER_LOCATION, profile.location);
|
||||
edit.putString(PrefConstants.USER_PHOTO_SERVICE, profile.photoService);
|
||||
edit.putString(PrefConstants.USER_PHOTO_URL, profile.photoUrl);
|
||||
edit.putString(PrefConstants.USER_POPULAR_PUBLISHERS, profile.popularPublishers);
|
||||
edit.putInt(PrefConstants.USER_SHARED_STORIES_COUNT, profile.sharedStoriesCount);
|
||||
edit.putInt(PrefConstants.USER_STORIES_LAST_MONTH, profile.storiesLastMonth);
|
||||
edit.putInt(PrefConstants.USER_SUBSCRIBER_COUNT, profile.subscriptionCount);
|
||||
|
@ -62,7 +61,6 @@ public class PrefsUtil {
|
|||
user.location = preferences.getString(PrefConstants.USER_LOCATION, null);
|
||||
user.photoService = preferences.getString(PrefConstants.USER_PHOTO_SERVICE, null);
|
||||
user.photoUrl = preferences.getString(PrefConstants.USER_PHOTO_URL, null);
|
||||
user.popularPublishers = preferences.getString(PrefConstants.USER_POPULAR_PUBLISHERS, null);
|
||||
user.sharedStoriesCount = preferences.getInt(PrefConstants.USER_SHARED_STORIES_COUNT, 0);
|
||||
user.storiesLastMonth = preferences.getInt(PrefConstants.USER_STORIES_LAST_MONTH, 0);
|
||||
user.subscriptionCount = preferences.getInt(PrefConstants.USER_SUBSCRIBER_COUNT, 0);
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package com.newsblur.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -14,6 +17,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.activity.Profile;
|
||||
import com.newsblur.network.domain.ActivitiesResponse;
|
||||
import com.newsblur.util.ImageLoader;
|
||||
|
||||
|
@ -23,11 +27,14 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivitiesResponse> {
|
|||
private ImageLoader imageLoader;
|
||||
private final String startedFollowing, ago, repliedTo, sharedStory, withComment;
|
||||
private ForegroundColorSpan midgray, highlight, darkgray;
|
||||
private String TAG = "ActivitiesAdapter";
|
||||
private Context context;
|
||||
|
||||
public ActivitiesAdapter(Context context, final ActivitiesResponse[] activities) {
|
||||
public ActivitiesAdapter(final Context context, final ActivitiesResponse[] activities) {
|
||||
super(context, R.id.row_activity_text);
|
||||
inflater = LayoutInflater.from(context);
|
||||
imageLoader = new ImageLoader(context);
|
||||
this.context = context;
|
||||
|
||||
for (ActivitiesResponse response : activities) {
|
||||
add(response);
|
||||
|
@ -53,23 +60,50 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivitiesResponse> {
|
|||
} else {
|
||||
view = convertView;
|
||||
}
|
||||
ActivitiesResponse activity = getItem(position);
|
||||
Spannable activityUpdate = null;
|
||||
final ActivitiesResponse activity = getItem(position);
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||
|
||||
if (TextUtils.equals(activity.category, "follow")) {
|
||||
activityUpdate = new SpannableString(startedFollowing + " " + activity.user.username);
|
||||
activityUpdate.setSpan(darkgray, 0, startedFollowing.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
activityUpdate.setSpan(highlight, startedFollowing.length() + 1, startedFollowing.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
stringBuilder.append(startedFollowing);
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append(activity.user.username);
|
||||
ClickableSpan usernameClick = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
Intent i = new Intent(context, Profile.class);
|
||||
i.putExtra(Profile.USER_ID, activity.id);
|
||||
context.startActivity(i);
|
||||
}
|
||||
};
|
||||
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);
|
||||
} else if (TextUtils.equals(activity.category, "comment_reply")) {
|
||||
activityUpdate = new SpannableString(repliedTo + " " + activity.user.username + ": \"" + activity.content + "\"");
|
||||
activityUpdate.setSpan(darkgray, 0, repliedTo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
activityUpdate.setSpan(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
activityUpdate.setSpan(midgray, activityUpdate.length() - activity.content.length() - 2, activityUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
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(highlight, repliedTo.length() + 1, repliedTo.length() + 1 + activity.user.username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
stringBuilder.setSpan(midgray, stringBuilder.length() - activity.content.length() - 2, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else if (TextUtils.equals(activity.category, "sharedstory")) {
|
||||
activityUpdate = new SpannableString(sharedStory + " \"" + activity.title + "\" " + withComment + ": \"" + activity.content + "\"");
|
||||
activityUpdate.setSpan(darkgray, 0, sharedStory.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
activityUpdate.setSpan(highlight, sharedStory.length() + 1, sharedStory.length() + 2 + activity.title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
activityUpdate.setSpan(midgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), activityUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
stringBuilder.append(sharedStory);
|
||||
stringBuilder.append(" \"");
|
||||
stringBuilder.append(activity.title);
|
||||
stringBuilder.append("\" ");
|
||||
if (activity.content != null) {
|
||||
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() + 2 + activity.title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (activity.content != null) {
|
||||
stringBuilder.setSpan(midgray, sharedStory.length() + 4 + activity.title.length() + withComment.length(), stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
TextView activityText = (TextView) view.findViewById(R.id.row_activity_text);
|
||||
|
@ -79,7 +113,8 @@ public class ActivitiesAdapter extends ArrayAdapter<ActivitiesResponse> {
|
|||
activityTime.setText(activity.timeSince + " " + ago);
|
||||
imageLoader.DisplayImage(activity.user.photoUrl, imageView);
|
||||
|
||||
activityText.setText(activityUpdate);
|
||||
activityText.setText(stringBuilder);
|
||||
activityText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue