mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Formatting
This commit is contained in:
parent
68d2e63d85
commit
e6b3e4a419
4 changed files with 175 additions and 174 deletions
|
@ -3,33 +3,33 @@ package com.newsblur.domain;
|
|||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ActivityDetails {
|
||||
|
||||
public Category category;
|
||||
public String content;
|
||||
public String title;
|
||||
|
||||
@SerializedName("feed_id")
|
||||
public String feedId;
|
||||
|
||||
@SerializedName("time_since")
|
||||
public String timeSince;
|
||||
|
||||
@SerializedName("with_user")
|
||||
public WithUser user;
|
||||
|
||||
@SerializedName("with_user_id")
|
||||
public String withUserId;
|
||||
public Category category;
|
||||
public String content;
|
||||
public String title;
|
||||
|
||||
@SerializedName("feed_id")
|
||||
public String feedId;
|
||||
|
||||
@SerializedName("time_since")
|
||||
public String timeSince;
|
||||
|
||||
@SerializedName("with_user")
|
||||
public WithUser user;
|
||||
|
||||
@SerializedName("with_user_id")
|
||||
public String withUserId;
|
||||
|
||||
@SerializedName("story_hash")
|
||||
public String storyHash;
|
||||
|
||||
public class WithUser {
|
||||
public String username;
|
||||
|
||||
@SerializedName("photo_url")
|
||||
public String photoUrl;
|
||||
|
||||
}
|
||||
|
||||
public class WithUser {
|
||||
public String username;
|
||||
|
||||
@SerializedName("photo_url")
|
||||
public String photoUrl;
|
||||
|
||||
}
|
||||
|
||||
public enum Category {
|
||||
@SerializedName("feedsub")
|
||||
|
|
|
@ -37,23 +37,23 @@ import com.newsblur.view.ProgressThrobber;
|
|||
|
||||
public abstract class ProfileActivityDetailsFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
|
||||
private ListView activityList;
|
||||
private ActivityDetailsAdapter adapter;
|
||||
protected APIManager apiManager;
|
||||
private UserDetails user;
|
||||
private ListView activityList;
|
||||
private ActivityDetailsAdapter adapter;
|
||||
protected APIManager apiManager;
|
||||
private UserDetails user;
|
||||
private ProgressThrobber footerProgressView;
|
||||
private ProgressThrobber loadingProgressView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
apiManager = new APIManager(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View v = inflater.inflate(R.layout.fragment_profileactivity, null);
|
||||
activityList = (ListView) v.findViewById(R.id.profile_details_activitylist);
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
apiManager = new APIManager(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View v = inflater.inflate(R.layout.fragment_profileactivity, null);
|
||||
activityList = (ListView) v.findViewById(R.id.profile_details_activitylist);
|
||||
|
||||
loadingProgressView = (ProgressThrobber) v.findViewById(R.id.empty_view_loading_throb);
|
||||
loadingProgressView.setColors(getResources().getColor(R.color.refresh_1),
|
||||
|
@ -71,29 +71,29 @@ public abstract class ProfileActivityDetailsFragment extends Fragment implements
|
|||
getResources().getColor(R.color.refresh_4));
|
||||
activityList.addFooterView(footerView, null, false);
|
||||
|
||||
if (adapter != null) {
|
||||
displayActivities();
|
||||
}
|
||||
activityList.setOnScrollListener(new EndlessScrollListener());
|
||||
if (adapter != null) {
|
||||
displayActivities();
|
||||
}
|
||||
activityList.setOnScrollListener(new EndlessScrollListener());
|
||||
activityList.setOnItemClickListener(this);
|
||||
return v;
|
||||
}
|
||||
|
||||
public void setUser(Context context, UserDetails user) {
|
||||
this.user = user;
|
||||
adapter = createAdapter(context, user);
|
||||
displayActivities();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public void setUser(Context context, UserDetails user) {
|
||||
this.user = user;
|
||||
adapter = createAdapter(context, user);
|
||||
displayActivities();
|
||||
}
|
||||
|
||||
protected abstract ActivityDetailsAdapter createAdapter(Context context, UserDetails user);
|
||||
|
||||
private void displayActivities() {
|
||||
activityList.setAdapter(adapter);
|
||||
loadPage(1);
|
||||
}
|
||||
|
||||
private void loadPage(final int pageNumber) {
|
||||
new AsyncTask<Void, Void, ActivityDetails[]>() {
|
||||
private void displayActivities() {
|
||||
activityList.setAdapter(adapter);
|
||||
loadPage(1);
|
||||
}
|
||||
|
||||
private void loadPage(final int pageNumber) {
|
||||
new AsyncTask<Void, Void, ActivityDetails[]>() {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
|
@ -102,32 +102,32 @@ public abstract class ProfileActivityDetailsFragment extends Fragment implements
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ActivityDetails[] doInBackground(Void... voids) {
|
||||
// For the logged in user user.userId is null.
|
||||
// From the user intent user.userId is the number while user.id is prefixed with social:
|
||||
String id = user.userId;
|
||||
if (id == null) {
|
||||
id = user.id;
|
||||
}
|
||||
return loadActivityDetails(id, pageNumber);
|
||||
}
|
||||
protected ActivityDetails[] doInBackground(Void... voids) {
|
||||
// For the logged in user user.userId is null.
|
||||
// From the user intent user.userId is the number while user.id is prefixed with social:
|
||||
String id = user.userId;
|
||||
if (id == null) {
|
||||
id = user.id;
|
||||
}
|
||||
return loadActivityDetails(id, pageNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ActivityDetails[] result) {
|
||||
@Override
|
||||
protected void onPostExecute(ActivityDetails[] result) {
|
||||
if (pageNumber == 1 && result.length == 0) {
|
||||
View emptyView = activityList.getEmptyView();
|
||||
TextView textView = (TextView) emptyView.findViewById(R.id.empty_view_text);
|
||||
textView.setText(R.string.profile_no_interactions);
|
||||
}
|
||||
for (ActivityDetails activity : result) {
|
||||
adapter.add(activity);
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
for (ActivityDetails activity : result) {
|
||||
adapter.add(activity);
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
loadingProgressView.setVisibility(View.GONE);
|
||||
footerProgressView.setVisibility(View.GONE);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
protected abstract ActivityDetails[] loadActivityDetails(String id, int pageNumber);
|
||||
|
||||
|
@ -179,47 +179,48 @@ public abstract class ProfileActivityDetailsFragment extends Fragment implements
|
|||
}
|
||||
|
||||
/**
|
||||
* Detects when user is close to the end of the current page and starts loading the next page
|
||||
* so the user will not have to wait (that much) for the next entries.
|
||||
*
|
||||
* @author Ognyan Bankov
|
||||
*
|
||||
* https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/Act_NetworkListView.java
|
||||
*/
|
||||
public class EndlessScrollListener implements AbsListView.OnScrollListener {
|
||||
// how many entries earlier to start loading next page
|
||||
private int visibleThreshold = 5;
|
||||
private int currentPage = 1;
|
||||
private int previousTotal = 0;
|
||||
private boolean loading = true;
|
||||
* Detects when user is close to the end of the current page and starts loading the next page
|
||||
* so the user will not have to wait (that much) for the next entries.
|
||||
*
|
||||
* @author Ognyan Bankov
|
||||
* <p/>
|
||||
* https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/Act_NetworkListView.java
|
||||
*/
|
||||
public class EndlessScrollListener implements AbsListView.OnScrollListener {
|
||||
// how many entries earlier to start loading next page
|
||||
private int visibleThreshold = 5;
|
||||
private int currentPage = 1;
|
||||
private int previousTotal = 0;
|
||||
private boolean loading = true;
|
||||
|
||||
public EndlessScrollListener() {
|
||||
}
|
||||
public EndlessScrollListener(int visibleThreshold) {
|
||||
this.visibleThreshold = visibleThreshold;
|
||||
}
|
||||
public EndlessScrollListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||
int visibleItemCount, int totalItemCount) {
|
||||
if (loading) {
|
||||
if (totalItemCount > previousTotal) {
|
||||
loading = false;
|
||||
previousTotal = totalItemCount;
|
||||
currentPage++;
|
||||
}
|
||||
}
|
||||
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
|
||||
// I load the next page of gigs using a background task,
|
||||
// but you can call any function here.
|
||||
loadPage(currentPage);
|
||||
loading = true;
|
||||
}
|
||||
}
|
||||
public EndlessScrollListener(int visibleThreshold) {
|
||||
this.visibleThreshold = visibleThreshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||
int visibleItemCount, int totalItemCount) {
|
||||
if (loading) {
|
||||
if (totalItemCount > previousTotal) {
|
||||
loading = false;
|
||||
previousTotal = totalItemCount;
|
||||
currentPage++;
|
||||
}
|
||||
}
|
||||
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
|
||||
// I load the next page of gigs using a background task,
|
||||
// but you can call any function here.
|
||||
loadPage(currentPage);
|
||||
loading = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -449,19 +449,19 @@ public class APIManager {
|
|||
}
|
||||
}
|
||||
|
||||
public ActivitiesResponse getActivities(String userId, int pageNumber) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_USER_ID, userId);
|
||||
values.put(APIConstants.PARAMETER_LIMIT, "10");
|
||||
values.put(APIConstants.PARAMETER_PAGE_NUMBER, Integer.toString(pageNumber));
|
||||
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 ActivitiesResponse getActivities(String userId, int pageNumber) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(APIConstants.PARAMETER_USER_ID, userId);
|
||||
values.put(APIConstants.PARAMETER_LIMIT, "10");
|
||||
values.put(APIConstants.PARAMETER_PAGE_NUMBER, Integer.toString(pageNumber));
|
||||
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 InteractionsResponse getInteractions(String userId, int pageNumber) {
|
||||
final ContentValues values = new ContentValues();
|
||||
|
|
|
@ -21,27 +21,27 @@ import com.newsblur.util.PrefsUtils;
|
|||
|
||||
public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetails> {
|
||||
|
||||
private LayoutInflater inflater;
|
||||
private ImageLoader imageLoader;
|
||||
protected final String ago;
|
||||
protected ForegroundColorSpan linkColor, contentColor, quoteColor;
|
||||
private String TAG = "ActivitiesAdapter";
|
||||
private Context context;
|
||||
protected UserDetails currentUserDetails;
|
||||
private LayoutInflater inflater;
|
||||
private ImageLoader imageLoader;
|
||||
protected final String ago;
|
||||
protected ForegroundColorSpan linkColor, contentColor, quoteColor;
|
||||
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);
|
||||
imageLoader = ((NewsBlurApplication) context.getApplicationContext()).getImageLoader();
|
||||
this.context = context;
|
||||
|
||||
currentUserDetails = user;
|
||||
|
||||
Resources resources = context.getResources();
|
||||
ago = resources.getString(R.string.profile_ago);
|
||||
public ActivityDetailsAdapter(final Context context, UserDetails user) {
|
||||
super(context, R.id.row_activity_text);
|
||||
inflater = LayoutInflater.from(context);
|
||||
imageLoader = ((NewsBlurApplication) context.getApplicationContext()).getImageLoader();
|
||||
this.context = context;
|
||||
|
||||
if (PrefsUtils.isLightThemeSelected(context)) {
|
||||
currentUserDetails = user;
|
||||
|
||||
Resources resources = context.getResources();
|
||||
ago = resources.getString(R.string.profile_ago);
|
||||
|
||||
if (PrefsUtils.isLightThemeSelected(context)) {
|
||||
linkColor = new ForegroundColorSpan(resources.getColor(R.color.linkblue));
|
||||
contentColor = new ForegroundColorSpan(resources.getColor(R.color.darkgray));
|
||||
quoteColor = new ForegroundColorSpan(resources.getColor(R.color.midgray));
|
||||
|
@ -52,38 +52,38 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
|
|||
}
|
||||
|
||||
userIsYou = user.userId == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = null;
|
||||
if (convertView == null) {
|
||||
view = inflater.inflate(R.layout.row_activity, null);
|
||||
} else {
|
||||
view = convertView;
|
||||
}
|
||||
final ActivityDetails activity = getItem(position);
|
||||
|
||||
TextView activityText = (TextView) view.findViewById(R.id.row_activity_text);
|
||||
TextView activityTime = (TextView) view.findViewById(R.id.row_activity_time);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
|
||||
|
||||
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
|
||||
if (activity.category == Category.FEED_SUBSCRIPTION) {
|
||||
imageLoader.displayImage(APIConstants.S3_URL_FEED_ICONS + activity.feedId + ".png", imageView);
|
||||
} else if (activity.category == Category.SHARED_STORY) {
|
||||
imageLoader.displayImage(currentUserDetails.photoUrl, imageView, 10f);
|
||||
} else if (activity.category == Category.STAR) {
|
||||
imageView.setImageResource(R.drawable.clock);
|
||||
} else if (activity.user != null) {
|
||||
imageLoader.displayImage(activity.user.photoUrl, imageView);
|
||||
} else {
|
||||
imageView.setImageResource(R.drawable.logo);
|
||||
}
|
||||
}
|
||||
|
||||
activityText.setText(getTextForActivity(activity));
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = null;
|
||||
if (convertView == null) {
|
||||
view = inflater.inflate(R.layout.row_activity, null);
|
||||
} else {
|
||||
view = convertView;
|
||||
}
|
||||
final ActivityDetails activity = getItem(position);
|
||||
|
||||
TextView activityText = (TextView) view.findViewById(R.id.row_activity_text);
|
||||
TextView activityTime = (TextView) view.findViewById(R.id.row_activity_time);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
|
||||
|
||||
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
|
||||
if (activity.category == Category.FEED_SUBSCRIPTION) {
|
||||
imageLoader.displayImage(APIConstants.S3_URL_FEED_ICONS + activity.feedId + ".png", imageView);
|
||||
} else if (activity.category == Category.SHARED_STORY) {
|
||||
imageLoader.displayImage(currentUserDetails.photoUrl, imageView, 10f);
|
||||
} else if (activity.category == Category.STAR) {
|
||||
imageView.setImageResource(R.drawable.clock);
|
||||
} else if (activity.user != null) {
|
||||
imageLoader.displayImage(activity.user.photoUrl, imageView);
|
||||
} else {
|
||||
imageView.setImageResource(R.drawable.logo);
|
||||
}
|
||||
|
||||
activityText.setText(getTextForActivity(activity));
|
||||
return view;
|
||||
}
|
||||
|
||||
protected abstract CharSequence getTextForActivity(ActivityDetails activity);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue