Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 172860
b: refs/heads/feature/sharing-design-review
c: 4a3ecfb
h: refs/heads/develop
  • Loading branch information
maxme authored Mar 10, 2017
1 parent b59dcd0 commit eeadafe
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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");
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,22 +32,24 @@ 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;
}

@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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -45,10 +44,10 @@ public void onClick(DialogInterface dialog, int which) {
}

public static <T extends Fragment & OnRoleSelectListener> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@
<string name="role_contributor">Contributor</string>
<string name="role_follower">Follower</string>
<string name="role_viewer">Viewer</string>
<string name="role_subscriber">Subscriber</string>

<!--My profile-->
<string name="my_profile">My Profile</string>
Expand Down

0 comments on commit eeadafe

Please sign in to comment.