Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.wordpress.android.WordPress;
import org.wordpress.android.models.Person;
import org.wordpress.android.models.Role;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.SqlUtils;

Expand All @@ -26,6 +25,7 @@ private static SQLiteDatabase getWritableDb() {
public static void createTables(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + PEOPLE_TABLE + " ("
+ "person_id INTEGER DEFAULT 0,"
+ "blog_id TEXT,"
+ "local_blog_id INTEGER DEFAULT 0,"
+ "user_name TEXT,"
+ "first_name TEXT,"
Expand Down Expand Up @@ -54,13 +54,14 @@ public static void save(Person person) {
public static void save(Person person, SQLiteDatabase database) {
ContentValues values = new ContentValues();
values.put("person_id", person.getPersonID());
values.put("blog_id", person.getBlogId());
values.put("local_blog_id", person.getLocalTableBlogId());
values.put("user_name", person.getUsername());
values.put("first_name", person.getFirstName());
values.put("last_name", person.getLastName());
values.put("display_name", person.getDisplayName());
values.put("avatar_url", person.getAvatarUrl());
values.put("role", Role.toKey(person.getRole()));
values.put("role", person.getRole());
database.insertWithOnConflict(PEOPLE_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
}

Expand Down Expand Up @@ -95,7 +96,7 @@ public static List<Person> getPeople(int localTableBlogId) {

/**
* retrieve a single person
* @param personId - id of a person in a particular site
* @param personId - id of a person in a particular blog
* @param localTableBlogId - the local blog id the user belongs to
* @return Person if found, null otherwise
*/
Expand All @@ -114,13 +115,14 @@ public static Person getPerson(long personId, int localTableBlogId) {

private static Person getPersonFromCursor(Cursor c, int localTableBlogId) {
long personId = c.getInt(c.getColumnIndex("person_id"));
String blogId = c.getString(c.getColumnIndex("blog_id"));
String username = c.getString(c.getColumnIndex("user_name"));
String firstName = c.getString(c.getColumnIndex("first_name"));
String lastName = c.getString(c.getColumnIndex("last_name"));
String displayName = c.getString(c.getColumnIndex("display_name"));
String avatarUrl = c.getString(c.getColumnIndex("avatar_url"));
Role role = Role.fromKey(c.getString(c.getColumnIndex("role")));
String role = c.getString(c.getColumnIndex("role"));

return new Person(personId, localTableBlogId, username, firstName, lastName, displayName, avatarUrl, role);
return new Person(personId, blogId, localTableBlogId, username, firstName, lastName, displayName, avatarUrl, role);
}
}
26 changes: 16 additions & 10 deletions WordPress/src/main/java/org/wordpress/android/models/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@

public class Person {
private long personID;
private String blogId;
private int localTableBlogId;

private String username;
private String firstName;
private String lastName;
private String displayName;
private String avatarUrl;
private Role role;
private String role;

public Person(long personID,
String blogId,
int localTableBlogId,
String username,
String firstName,
String lastName,
String displayName,
String avatarUrl,
Role role) {
String role) {
this.personID = personID;
this.blogId = blogId;
this.localTableBlogId = localTableBlogId;
this.username = username;
this.firstName = firstName;
Expand All @@ -36,12 +39,12 @@ public Person(long personID,
}

@Nullable
public static Person fromJSON(JSONObject json, int localTableBlogId) {
public static Person fromJSON(JSONObject json, String blogId, int localTableBlogId) throws JSONException {
if (json == null) {
return null;
}

// Response parameters can be found in https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/users/%24user_id/
// Response parameters are in: https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/users/%24user_id/
try {
long personID = Long.parseLong(json.getString("ID"));
String username = json.optString("login");
Expand All @@ -50,11 +53,10 @@ public static Person fromJSON(JSONObject json, int localTableBlogId) {
String displayName = json.optString("nice_name");
String avatarUrl = json.optString("avatar_URL");
// We don't support multiple roles, so the first role is picked just as it's in Calypso
Role role = Role.fromKey(json.optJSONArray("roles").optString(0));
String role = json.getJSONArray("roles").optString(0);

return new Person(personID, localTableBlogId, username, firstName, lastName, displayName, avatarUrl, role);
} catch (JSONException e) {
AppLog.e(AppLog.T.PEOPLE, "JSON exception occurred while parsing the user json: " + e);
return new Person(personID, blogId, localTableBlogId, username,
firstName, lastName, displayName, avatarUrl, role);
} catch (NumberFormatException e) {
AppLog.e(AppLog.T.PEOPLE, "The ID parsed from the JSON couldn't be converted to long: " + e);
}
Expand All @@ -66,6 +68,10 @@ public long getPersonID() {
return personID;
}

public String getBlogId() {
return blogId;
}

public int getLocalTableBlogId() {
return localTableBlogId;
}
Expand Down Expand Up @@ -102,11 +108,11 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public Role getRole() {
public String getRole() {
return role;
}

public void setRole(Role role) {
public void setRole(String role) {
this.role = role;
}

Expand Down
75 changes: 0 additions & 75 deletions WordPress/src/main/java/org/wordpress/android/models/Role.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@

import org.wordpress.android.R;
import org.wordpress.android.models.Person;
import org.wordpress.android.models.Role;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.widgets.WPNetworkImageView;

import java.util.List;

public class PeopleAdapter extends BaseAdapter {
private final Context mContext;
private final LayoutInflater mInflater;
private List<Person> mPeopleList;
private int mAvatarSz;

public PeopleAdapter(Context context, List<Person> peopleList) {
mContext = context;
mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_medium);
mInflater = LayoutInflater.from(context);
mPeopleList = peopleList;
Expand Down Expand Up @@ -77,8 +75,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
holder.txtDisplayName.setText(person.getDisplayName());
holder.txtUsername.setText(String.format("@%s", person.getUsername()));
holder.txtRole.setText(Role.getLabel(mContext, person.getRole()));
holder.txtRole.setBackgroundColor(Role.backgroundColor(mContext, person.getRole()));
holder.txtRole.setText(StringUtils.capitalize(person.getRole()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest doing the capitalisation in xml instead? I'm referring to using the textAllCaps attribute in the layout file. U? Unless capitalize does something smarter/suitable in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize changes the first letter, textAllCaps changes all. So, we can't use that ;)

}

return convertView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.android.volley.VolleyError;

import org.json.JSONException;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.datasets.PeopleTable;
Expand Down Expand Up @@ -77,7 +74,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}

private void refreshUsersList(String dotComBlogId, final int localTableBlogId) {
PeopleUtils.fetchUsers(dotComBlogId, localTableBlogId, new PeopleUtils.Callback() {
PeopleUtils.fetchUsers(dotComBlogId, localTableBlogId, new PeopleUtils.FetchUsersCallback() {
@Override
public void onSuccess(List<Person> peopleList) {
PeopleTable.savePeople(peopleList);
Expand All @@ -97,12 +94,7 @@ public void onSuccess(List<Person> peopleList) {
}

@Override
public void onError(VolleyError error) {
//TODO: show some kind of error to the user
}

@Override
public void onJSONException(JSONException exception) {
public void onError() {
//TODO: show some kind of error to the user
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.wordpress.android.R;
import org.wordpress.android.datasets.PeopleTable;
import org.wordpress.android.models.Person;
import org.wordpress.android.models.Role;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.widgets.WPNetworkImageView;

public class PersonDetailFragment extends Fragment {
Expand Down Expand Up @@ -86,7 +86,7 @@ public void refreshPersonDetails() {
mAvatarImageView.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
mDisplayNameTextView.setText(person.getDisplayName());
mUsernameTextView.setText(person.getUsername());
mRoleTextView.setText(Role.getLabel(getActivity(), person.getRole()));
mRoleTextView.setText(StringUtils.capitalize(person.getRole()));
mRemoveTextView.setText(String.format(getString(R.string.remove_user), person.getFirstName().toUpperCase()));

mRemoveTextView.setOnClickListener(new View.OnClickListener() {
Expand Down
Loading