diff --git a/[refs] b/[refs] index d21bd6665087..8554a4f217a4 100644 --- a/[refs] +++ b/[refs] @@ -134,7 +134,7 @@ refs/heads/issue/4240-save-dialog: b02d622ba41af56ad7213d4ad890b0122ba3d359 refs/tags/5.5: 2f276be82e6edfa1f1029ef3d3e830fd63e66648 refs/tags/5.5.1: 620be461a975c50e7e4f2f4c1c808155ebcd9f30 refs/tags/5.6: c5bb11cac207f3d3f6e64d7dd1bc7a7091adaf0a -refs/heads/feature/sharing-design-review: 0472a99db459c3c3184187ac4aef7023be4b5080 +refs/heads/feature/sharing-design-review: 4a3ecfb56bb542b0989865dd5571a35bb35c8416 refs/heads/feature/wpstores-integration-sign-out: 4289b207c83f60f8db52d35d380cea578184a7de refs/tags/5.6.1: 130322279df98a658e560668cd7bae8520148f81 refs/heads/feature/bottom-bar: 07828a1a697d1822b5ddf9c91ac07297b31db74c diff --git a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/models/Role.java b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/models/Role.java index 4266ba56135a..38e0809e672d 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/models/Role.java +++ b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/models/Role.java @@ -4,6 +4,7 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.CrashlyticsUtils; @@ -13,7 +14,14 @@ public enum Role { AUTHOR(R.string.role_author), CONTRIBUTOR(R.string.role_contributor), FOLLOWER(R.string.role_follower), - VIEWER(R.string.role_viewer); + VIEWER(R.string.role_viewer), + SUBSCRIBER(R.string.role_subscriber); // Jetpack only + + private static final Role[] USER_ROLES_WPCOM = { ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + private static final Role[] USER_ROLES_JETPACK = { ADMIN, EDITOR, AUTHOR, CONTRIBUTOR, SUBSCRIBER }; + private static final Role[] INVITE_ROLES_WPCOM = { FOLLOWER, ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + private static final Role[] INVITE_ROLES_WPCOM_PRIVATE = { VIEWER, ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + private static final Role[] INVITE_ROLES_JETPACK = { FOLLOWER }; private final int mLabelResId; @@ -39,6 +47,8 @@ public static Role fromString(String role) { return FOLLOWER; case "viewer": return VIEWER; + case "subscriber": + return SUBSCRIBER; } Exception e = new IllegalArgumentException("All roles must be handled: " + role); CrashlyticsUtils.logException(e, CrashlyticsUtils.ExceptionType.SPECIFIC, AppLog.T.PEOPLE); @@ -63,6 +73,8 @@ public String toString() { return "follower"; case VIEWER: return "viewer"; + case SUBSCRIBER: + return "subscriber"; } throw new IllegalArgumentException("All roles must be handled"); } @@ -85,18 +97,27 @@ public String toRESTString() { case VIEWER: // the remote expects "follower" as the role parameter even if the role is "viewer" return "follower"; + case SUBSCRIBER: + return "subscriber"; } throw new IllegalArgumentException("All roles must be handled"); } - public static Role[] userRoles() { - return new Role[] { ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + public static Role[] userRoles(SiteModel site) { + if (site.isJetpackConnected()) { + return USER_ROLES_JETPACK; + } + return USER_ROLES_WPCOM; } - public static Role[] inviteRoles(boolean isPrivateSite) { - if (isPrivateSite) { - return new Role[] { VIEWER, ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + public static Role[] inviteRoles(SiteModel site) { + if (site.isJetpackConnected()) { + return INVITE_ROLES_JETPACK; + } + + if (site.isPrivate()) { + return INVITE_ROLES_WPCOM_PRIVATE; } - return new Role[] { FOLLOWER, ADMIN, EDITOR, AUTHOR, CONTRIBUTOR }; + return INVITE_ROLES_WPCOM; } } diff --git a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteFragment.java b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteFragment.java index b69dd7e2945d..cbd3b6fa3964 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteFragment.java +++ b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteFragment.java @@ -208,14 +208,6 @@ public void onFocusChange(View v, boolean hasFocus) { populateUsernameButtons(usernames); } - - view.findViewById(R.id.role_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - RoleSelectDialogFragment.show(PeopleInviteFragment.this, 0, mSite.isPrivate()); - } - }); - mRoleTextView = (TextView) view.findViewById(R.id.role); setRole(role); ImageView imgRoleInfo = (ImageView) view.findViewById(R.id.imgRoleInfo); @@ -226,6 +218,18 @@ public void onClick(View v) { } }); + if (Role.inviteRoles(mSite).length > 1) { + view.findViewById(R.id.role_container).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + RoleSelectDialogFragment.show(PeopleInviteFragment.this, 0, mSite); + } + }); + } else { + // Don't show drop-down arrow or role selector if there's only one role available + mRoleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + final int MAX_CHARS = getResources().getInteger(R.integer.invite_message_char_limit); final TextView remainingCharsTextView = (TextView) view.findViewById(R.id.message_remaining); @@ -285,7 +289,7 @@ private void resetEditTextContent(EditText editText) { } private Role getDefaultRole() { - Role[] inviteRoles = Role.inviteRoles(mSite.isPrivate()); + Role[] inviteRoles = Role.inviteRoles(mSite); return inviteRoles[0]; } diff --git a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PersonDetailFragment.java b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PersonDetailFragment.java index d1ff01a0807d..04a5f667e2ed 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PersonDetailFragment.java +++ b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/PersonDetailFragment.java @@ -189,7 +189,7 @@ private void showRoleChangeDialog() { } RoleChangeDialogFragment dialog = RoleChangeDialogFragment.newInstance(person.getPersonID(), - person.getLocalTableBlogId(), person.getRole()); + mSiteStore.getSiteByLocalId(mLocalTableBlogId), person.getRole()); dialog.show(getFragmentManager(), null); } diff --git a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleChangeDialogFragment.java b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleChangeDialogFragment.java index 438231fe37a4..cdb4fd8c1af2 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleChangeDialogFragment.java +++ b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleChangeDialogFragment.java @@ -13,13 +13,14 @@ import android.widget.TextView; import org.wordpress.android.R; +import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.Role; import de.greenrobot.event.EventBus; public class RoleChangeDialogFragment extends DialogFragment { private static final String PERSON_ID_TAG = "person_id"; - private static final String PERSON_LOCAL_TABLE_BLOG_ID_TAG = "local_table_blog_id"; private static final String ROLE_TAG = "role"; private RoleListAdapter mRoleListAdapter; @@ -31,15 +32,15 @@ public void onSaveInstanceState(Bundle outState) { outState.putSerializable(ROLE_TAG, role); } - public static RoleChangeDialogFragment newInstance(long personID, int localTableBlogId, Role role) { + public static RoleChangeDialogFragment newInstance(long personID, SiteModel site, Role role) { RoleChangeDialogFragment roleChangeDialogFragment = new RoleChangeDialogFragment(); Bundle args = new Bundle(); args.putLong(PERSON_ID_TAG, personID); - args.putInt(PERSON_LOCAL_TABLE_BLOG_ID_TAG, localTableBlogId); if (role != null) { args.putSerializable(ROLE_TAG, role); } + args.putSerializable(WordPress.SITE, site); roleChangeDialogFragment.setArguments(args); return roleChangeDialogFragment; @@ -47,6 +48,8 @@ public static RoleChangeDialogFragment newInstance(long personID, int localTable @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + final SiteModel site = (SiteModel) getArguments().getSerializable(WordPress.SITE); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Calypso_AlertDialog); builder.setTitle(R.string.role); builder.setNegativeButton(R.string.cancel, null); @@ -57,14 +60,15 @@ public void onClick(DialogInterface dialog, int which) { Bundle args = getArguments(); if (args != null) { long personID = args.getLong(PERSON_ID_TAG); - int localTableBlogId = args.getInt(PERSON_LOCAL_TABLE_BLOG_ID_TAG); - EventBus.getDefault().post(new RoleChangeEvent(personID, localTableBlogId, role)); + if (site != null) { + EventBus.getDefault().post(new RoleChangeEvent(personID, site.getId(), role)); + } } } }); if (mRoleListAdapter == null) { - final Role[] userRoles = Role.userRoles(); + final Role[] userRoles = Role.userRoles(site); mRoleListAdapter = new RoleListAdapter(getActivity(), R.layout.role_list_row, userRoles); } if (savedInstanceState != null) { diff --git a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleSelectDialogFragment.java b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleSelectDialogFragment.java index 9c39fc559b1d..fec861d2e869 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleSelectDialogFragment.java +++ b/branches/feature/sharing-design-review/WordPress/src/main/java/org/wordpress/android/ui/people/RoleSelectDialogFragment.java @@ -9,21 +9,20 @@ import android.os.Bundle; import org.wordpress.android.R; +import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.Role; public class RoleSelectDialogFragment extends DialogFragment { - private static final String IS_PRIVATE_TAG = "is_private"; - @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - boolean isPrivateSite = getArguments().getBoolean(IS_PRIVATE_TAG); - final Role[] roles = Role.inviteRoles(isPrivateSite); + SiteModel site = (SiteModel) getArguments().getSerializable(WordPress.SITE); + final Role[] roles = Role.inviteRoles(site); final String[] stringRoles = new String[roles.length]; for (int i = 0; i < roles.length; i++) { stringRoles[i] = roles[i].toDisplayString(); } - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Calypso_AlertDialog); builder.setTitle(R.string.role); builder.setItems(stringRoles, new DialogInterface.OnClickListener() { @@ -45,10 +44,10 @@ public void onClick(DialogInterface dialog, int which) { } public static void show(T parentFragment, int requestCode, - boolean isPrivateSite) { + SiteModel site) { RoleSelectDialogFragment roleChangeDialogFragment = new RoleSelectDialogFragment(); Bundle args = new Bundle(); - args.putBoolean(IS_PRIVATE_TAG, isPrivateSite); + args.putSerializable(WordPress.SITE, site); roleChangeDialogFragment.setArguments(args); roleChangeDialogFragment.setTargetFragment(parentFragment, requestCode); roleChangeDialogFragment.show(parentFragment.getFragmentManager(), null); diff --git a/branches/feature/sharing-design-review/WordPress/src/main/res/values/strings.xml b/branches/feature/sharing-design-review/WordPress/src/main/res/values/strings.xml index 68976531d376..a02b9a6626f9 100644 --- a/branches/feature/sharing-design-review/WordPress/src/main/res/values/strings.xml +++ b/branches/feature/sharing-design-review/WordPress/src/main/res/values/strings.xml @@ -1519,6 +1519,7 @@ Contributor Follower Viewer + Subscriber My Profile