Skip to content

Commit ee722c4

Browse files
committed
Merge pull request #3364 from wordpress-mobile/feature/3286-team-management
Team Management UI
2 parents 32a8ba1 + cbd57d3 commit ee722c4

File tree

16 files changed

+607
-0
lines changed

16 files changed

+607
-0
lines changed

WordPress/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@
316316
android:theme="@style/CalypsoTheme"
317317
android:windowSoftInputMode="stateHidden"/>
318318

319+
<!--People Management-->
320+
<activity
321+
android:name="org.wordpress.android.ui.people.PeopleManagementActivity"
322+
android:theme="@style/CalypsoTheme"/>
323+
324+
<activity
325+
android:name="org.wordpress.android.ui.people.PersonActivity"
326+
android:theme="@style/CalypsoTheme"/>
327+
319328
<!-- Services -->
320329
<service
321330
android:name=".ui.posts.services.PostUploadService"

WordPress/src/main/java/org/wordpress/android/WordPressDB.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.wordpress.android.datasets.SuggestionTable;
2020
import org.wordpress.android.models.Account;
2121
import org.wordpress.android.models.Blog;
22+
import org.wordpress.android.models.Person;
2223
import org.wordpress.android.models.Post;
2324
import org.wordpress.android.models.PostLocation;
2425
import org.wordpress.android.models.PostsListPost;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.wordpress.android.datasets;
2+
3+
import org.wordpress.android.models.Person;
4+
import org.wordpress.android.models.Role;
5+
6+
public class PersonTable {
7+
/**
8+
* retrieve a single person
9+
* @param personId - unique id in person table
10+
* @return Person if found, null otherwise
11+
*/
12+
public static Person getPerson(int personId) {
13+
// This is a stub method for now so it returns a mock object, once implemented it will query the db
14+
return new Person(4, "oguzkocer", "Oguz", "Kocer", "Oguz", "http://lorempixum.com/76/76", Role.EDITOR);
15+
}
16+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.wordpress.android.models;
2+
3+
public class Person {
4+
public long personID;
5+
6+
private String username;
7+
private String firstName;
8+
private String lastName;
9+
private String displayName;
10+
private String imageUrl;
11+
private Role role;
12+
13+
public Person(long personID,
14+
String username,
15+
String firstName,
16+
String lastName,
17+
String displayName,
18+
String imageUrl,
19+
Role role) {
20+
this.personID = personID;
21+
this.username = username;
22+
this.firstName = firstName;
23+
this.lastName = lastName;
24+
this.displayName = displayName;
25+
this.imageUrl = imageUrl;
26+
this.role = role;
27+
}
28+
29+
public String getUsername() {
30+
return "@" + username;
31+
}
32+
33+
public void setUsername(String username) {
34+
this.username = username;
35+
}
36+
37+
public String getFirstName() {
38+
return firstName;
39+
}
40+
41+
public void setFirstName(String firstName) {
42+
this.firstName = firstName;
43+
}
44+
45+
public String getLastName() {
46+
return lastName;
47+
}
48+
49+
public void setLastName(String lastName) {
50+
this.lastName = lastName;
51+
}
52+
53+
public String getDisplayName() {
54+
return displayName;
55+
}
56+
57+
public void setDisplayName(String displayName) {
58+
this.displayName = displayName;
59+
}
60+
61+
public Role getRole() {
62+
return role;
63+
}
64+
65+
public void setRole(Role role) {
66+
this.role = role;
67+
}
68+
69+
public String getImageUrl() {
70+
return imageUrl;
71+
}
72+
73+
public void setImageUrl(String imageUrl) {
74+
this.imageUrl = imageUrl;
75+
}
76+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.wordpress.android.models;
2+
3+
import android.content.Context;
4+
import android.support.v4.content.ContextCompat;
5+
6+
import org.wordpress.android.R;
7+
8+
public enum Role {
9+
SUPER_ADMIN(R.string.role_super_admin, R.color.orange_fire),
10+
ADMIN(R.string.role_admin, R.color.grey_dark),
11+
EDITOR(R.string.role_editor, R.color.blue_dark),
12+
AUTHOR(R.string.role_author, R.color.blue_wordpress),
13+
CONTRIBUTOR(R.string.role_contributor, R.color.blue_wordpress),
14+
UNSUPPORTED(R.string.role_unsupported, R.color.blue_wordpress);
15+
16+
private final int label;
17+
private final int backgroundColor;
18+
19+
Role(int label, int backgroundColor) {
20+
this.label = label;
21+
this.backgroundColor = backgroundColor;
22+
}
23+
24+
public static String toString(Context context, Role role) {
25+
return context.getString(role.label);
26+
}
27+
28+
// This method will be used to determine the role of the user from network request
29+
public static Role fromString(String value) {
30+
if (value == null)
31+
return Role.UNSUPPORTED;
32+
if (value.equals("administrator"))
33+
return Role.ADMIN;
34+
if (value.equals("editor"))
35+
return Role.EDITOR;
36+
if (value.equals("author"))
37+
return Role.AUTHOR;
38+
if (value.equals("contributor"))
39+
return Role.CONTRIBUTOR;
40+
return Role.UNSUPPORTED;
41+
}
42+
43+
public static int backgroundColor(Context context, Role role) {
44+
return ContextCompat.getColor(context, role.backgroundColor);
45+
}
46+
}

WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.wordpress.android.WordPress;
1212
import org.wordpress.android.analytics.AnalyticsTracker;
1313
import org.wordpress.android.models.Blog;
14+
import org.wordpress.android.models.Person;
1415
import org.wordpress.android.models.Post;
1516
import org.wordpress.android.networking.SSLCertsViewActivity;
1617
import org.wordpress.android.networking.SelfSignedSSLCertsManager;
@@ -22,6 +23,8 @@
2223
import org.wordpress.android.ui.main.SitePickerActivity;
2324
import org.wordpress.android.ui.media.MediaBrowserActivity;
2425
import org.wordpress.android.ui.media.WordPressMediaUtils;
26+
import org.wordpress.android.ui.people.PeopleManagementActivity;
27+
import org.wordpress.android.ui.people.PersonActivity;
2528
import org.wordpress.android.ui.posts.EditPostActivity;
2629
import org.wordpress.android.ui.posts.PostPreviewActivity;
2730
import org.wordpress.android.ui.posts.PostsListActivity;
@@ -102,6 +105,12 @@ public static void viewCurrentBlogThemes(Context context) {
102105
}
103106
}
104107

108+
public static void viewCurrentBlogPeople(Context context) {
109+
Intent intent = new Intent(context, PeopleManagementActivity.class);
110+
slideInFromRight(context, intent);
111+
// TODO: add -> AnalyticsTracker.track(AnalyticsTracker.Stat.OPENED_PEOPLE_MANAGEMENT);
112+
}
113+
105114
public static void viewBlogSettingsForResult(Activity activity, Blog blog) {
106115
if (blog == null) return;
107116

@@ -250,6 +259,12 @@ public static void addSelfHostedSiteForResult(Activity activity) {
250259
activity.startActivityForResult(intent, RequestCodes.ADD_ACCOUNT);
251260
}
252261

262+
public static void viewPersonDetails(Context context, Person person) {
263+
Intent intent = new Intent(context, PersonActivity.class);
264+
intent.putExtra(PersonActivity.EXTRA_PERSON_ID, person.personID);
265+
slideInFromRight(context, intent);
266+
}
267+
253268
public static void slideInFromRight(Context context, Intent intent) {
254269
if (context instanceof Activity) {
255270
intent.putExtra(ARG_DID_SLIDE_IN_FROM_RIGHT, true);

WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ public void onClick(View v) {
186186
}
187187
});
188188

189+
rootView.findViewById(R.id.row_people).setOnClickListener(new View.OnClickListener() {
190+
@Override
191+
public void onClick(View v) {
192+
ActivityLauncher.viewCurrentBlogPeople(getActivity());
193+
}
194+
});
195+
189196
rootView.findViewById(R.id.row_settings).setOnClickListener(new View.OnClickListener() {
190197
@Override
191198
public void onClick(View v) {
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.wordpress.android.ui.people;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.BaseAdapter;
8+
import android.widget.TextView;
9+
10+
import org.wordpress.android.R;
11+
import org.wordpress.android.models.Person;
12+
import org.wordpress.android.models.Role;
13+
import org.wordpress.android.util.GravatarUtils;
14+
import org.wordpress.android.widgets.WPNetworkImageView;
15+
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
public class PeopleAdapter extends BaseAdapter {
20+
private final Context mContext;
21+
private final LayoutInflater mInflater;
22+
private List<Person> mPersonList;
23+
private int mAvatarSz;
24+
25+
public PeopleAdapter(Context context) {
26+
mContext = context;
27+
mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_medium);
28+
mInflater = LayoutInflater.from(context);
29+
mPersonList = new ArrayList<>();
30+
mPersonList.add(new Person(1, "beaulebens", "Beau", "Lebens", "Beau", "http://lorempixum.com/76/76", Role.ADMIN));
31+
mPersonList.add(new Person(2, "ebinnion", "Eric", "Binnion", "Eric", "http://lorempixum.com/76/76", Role.AUTHOR));
32+
mPersonList.add(new Person(3, "javialvarez", "Javi", "Alvarez", "Javi", "http://lorempixum.com/76/76", Role.CONTRIBUTOR));
33+
mPersonList.add(new Person(4, "oguzkocer", "Oguz", "Kocer", "Oguz", "http://lorempixum.com/76/76", Role.EDITOR));
34+
}
35+
36+
@Override
37+
public int getCount() {
38+
if (mPersonList == null) {
39+
return 0;
40+
}
41+
return mPersonList.size();
42+
}
43+
44+
@Override
45+
public Person getItem(int position) {
46+
if (mPersonList == null) {
47+
return null;
48+
}
49+
return mPersonList.get(position);
50+
}
51+
52+
@Override
53+
public long getItemId(int position) {
54+
Person person = getItem(position);
55+
if (person == null) {
56+
return 0;
57+
}
58+
return person.personID;
59+
}
60+
61+
@Override
62+
public View getView(int position, View convertView, ViewGroup parent) {
63+
final PeopleViewHolder holder;
64+
65+
if (convertView == null || convertView.getTag() == null) {
66+
convertView = mInflater.inflate(R.layout.people_list_row, parent, false);
67+
holder = new PeopleViewHolder(convertView);
68+
convertView.setTag(holder);
69+
} else {
70+
holder = (PeopleViewHolder) convertView.getTag();
71+
}
72+
73+
Person person = getItem(position);
74+
75+
if (person != null) {
76+
String avatarUrl = GravatarUtils.fixGravatarUrl(person.getImageUrl(), mAvatarSz);
77+
holder.imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
78+
holder.txtDisplayName.setText(person.getDisplayName());
79+
holder.txtUsername.setText(person.getUsername());
80+
holder.txtRole.setText(Role.toString(mContext, person.getRole()));
81+
holder.txtRole.setBackgroundColor(Role.backgroundColor(mContext, person.getRole()));
82+
}
83+
84+
return convertView;
85+
}
86+
87+
private class PeopleViewHolder {
88+
private final WPNetworkImageView imgAvatar;
89+
private final TextView txtDisplayName;
90+
private final TextView txtUsername;
91+
private final TextView txtRole;
92+
93+
PeopleViewHolder(View row) {
94+
imgAvatar = (WPNetworkImageView) row.findViewById(R.id.people_list_row_avatar);
95+
txtDisplayName = (TextView) row.findViewById(R.id.people_list_row_display_name);
96+
txtUsername = (TextView) row.findViewById(R.id.people_list_row_username);
97+
txtRole = (TextView) row.findViewById(R.id.people_list_row_role);
98+
}
99+
}
100+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.wordpress.android.ui.people;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.support.v7.app.ActionBar;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.MenuItem;
8+
import android.view.View;
9+
import android.widget.AdapterView;
10+
import android.widget.ListView;
11+
12+
import org.wordpress.android.R;
13+
import org.wordpress.android.models.Person;
14+
import org.wordpress.android.ui.ActivityLauncher;
15+
16+
public class PeopleManagementActivity extends AppCompatActivity {
17+
18+
@Override
19+
public void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
22+
ActionBar actionBar = getSupportActionBar();
23+
if (actionBar != null) {
24+
actionBar.setHomeButtonEnabled(true);
25+
actionBar.setDisplayHomeAsUpEnabled(true);
26+
}
27+
setContentView(R.layout.people_management_activity);
28+
29+
setTitle(R.string.people);
30+
31+
ListView listView = (ListView)findViewById(android.R.id.list);
32+
listView.setAdapter(new PeopleAdapter(this));
33+
34+
final Activity context = this;
35+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
36+
@Override
37+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
38+
Person person = (Person) parent.getItemAtPosition(position);
39+
ActivityLauncher.viewPersonDetails(context, person);
40+
}
41+
});
42+
}
43+
44+
@Override
45+
public void finish() {
46+
super.finish();
47+
ActivityLauncher.slideOutToRight(this);
48+
}
49+
50+
@Override
51+
public boolean onOptionsItemSelected(final MenuItem item) {
52+
if (item.getItemId() == android.R.id.home) {
53+
onBackPressed();
54+
return true;
55+
}
56+
return super.onOptionsItemSelected(item);
57+
}
58+
}

0 commit comments

Comments
 (0)