-
Notifications
You must be signed in to change notification settings - Fork 1.3k
People management v1 wrap-up #4086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33818df
c44dc22
f7f834e
e52766b
2877a22
d925e88
51a3245
22e7fff
0aa2983
9f42d04
1442ec3
6761818
86a6ceb
2a24858
ebb1cf9
2fbf331
321ec04
4d92a89
3935713
b798904
9250010
493276f
90cb52d
688abd8
97005c7
7a7efd2
c27b3e1
d14121f
4a27fd2
22d6576
6b2977b
d1175e1
68feb3f
5ba685b
62f57ac
affa51e
c5333c3
8b323a2
d448784
b106066
59e8371
1f395a7
85e692f
2702f0f
bb09320
42b8b7b
dbdbd41
80c9d1b
fff6640
7f1cbef
f20e9e3
4f7ad0f
f36411b
941fe1f
73774da
5d1ff37
9cb4399
da32d11
60ce5cf
01dfa29
6538a35
d3de340
29182ed
f2c748b
2553772
907b0bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| package org.wordpress.android.ui.people; | ||
|
|
||
| import android.app.AlertDialog; | ||
| import android.app.FragmentManager; | ||
| import android.app.FragmentTransaction; | ||
| import android.content.DialogInterface; | ||
| import android.os.Bundle; | ||
| import android.support.v7.app.ActionBar; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.Toolbar; | ||
| import android.view.MenuItem; | ||
|
|
||
| import org.wordpress.android.R; | ||
|
|
@@ -15,23 +18,29 @@ | |
| import org.wordpress.android.ui.ActivityLauncher; | ||
| import org.wordpress.android.ui.accounts.BlogUtils; | ||
| import org.wordpress.android.ui.people.utils.PeopleUtils; | ||
| import org.wordpress.android.util.ToastUtils; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PeopleManagementActivity extends AppCompatActivity implements PeopleListFragment.OnPersonSelectedListener { | ||
| public class PeopleManagementActivity extends AppCompatActivity | ||
| implements PeopleListFragment.OnPersonSelectedListener, RoleChangeDialogFragment.OnChangeListener { | ||
| private static final String KEY_PEOPLE_LIST_FRAGMENT = "people-list-fragment"; | ||
| private static final String KEY_PERSON_DETAIL_FRAGMENT = "person-detail-fragment"; | ||
|
|
||
| @Override | ||
| public void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
|
|
||
| setContentView(R.layout.people_management_activity); | ||
|
|
||
| Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
| setSupportActionBar(toolbar); | ||
| ActionBar actionBar = getSupportActionBar(); | ||
| if (actionBar != null) { | ||
| actionBar.setTitle(R.string.people); | ||
| actionBar.setHomeButtonEnabled(true); | ||
| actionBar.setDisplayHomeAsUpEnabled(true); | ||
| } | ||
| setContentView(R.layout.people_management_activity); | ||
|
|
||
| int localBlogId = BlogUtils.getBlogLocalId(WordPress.getCurrentBlog()); | ||
| Blog blog = WordPress.getBlog(localBlogId); | ||
|
|
@@ -57,9 +66,7 @@ public void finish() { | |
|
|
||
| @Override | ||
| public void onBackPressed() { | ||
| if (getFragmentManager().getBackStackEntryCount() > 0 ){ | ||
| getFragmentManager().popBackStack(); | ||
| } else { | ||
| if (!navigateBackToPeopleListFragment()) { | ||
| super.onBackPressed(); | ||
| } | ||
| } | ||
|
|
@@ -69,6 +76,9 @@ public boolean onOptionsItemSelected(final MenuItem item) { | |
| if (item.getItemId() == android.R.id.home) { | ||
| onBackPressed(); | ||
| return true; | ||
| } else if (item.getItemId() == R.id.remove_person) { | ||
| confirmRemovePerson(); | ||
| return true; | ||
| } | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
@@ -77,25 +87,15 @@ private void refreshUsersList(String dotComBlogId, final int localTableBlogId) { | |
| PeopleUtils.fetchUsers(dotComBlogId, localTableBlogId, new PeopleUtils.FetchUsersCallback() { | ||
| @Override | ||
| public void onSuccess(List<Person> peopleList) { | ||
| PeopleTable.savePeople(peopleList); | ||
|
|
||
| FragmentManager fragmentManager = getFragmentManager(); | ||
| PeopleListFragment peopleListFragment = (PeopleListFragment) fragmentManager | ||
| .findFragmentByTag(KEY_PEOPLE_LIST_FRAGMENT); | ||
| PersonDetailFragment personDetailFragment = (PersonDetailFragment) fragmentManager | ||
| .findFragmentByTag(KEY_PERSON_DETAIL_FRAGMENT); | ||
|
|
||
| if (peopleListFragment != null) { | ||
| peopleListFragment.refreshPeopleList(); | ||
| } | ||
| if (personDetailFragment != null) { | ||
| personDetailFragment.refreshPersonDetails(); | ||
| } | ||
| PeopleTable.savePeople(peopleList, localTableBlogId); | ||
| refreshOnScreenFragmentDetails(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError() { | ||
| //TODO: show some kind of error to the user | ||
| ToastUtils.showToast(PeopleManagementActivity.this, | ||
| R.string.error_fetch_people_list, | ||
| ToastUtils.Duration.LONG); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -120,4 +120,124 @@ public void onPersonSelected(Person person) { | |
| fragmentTransaction.commit(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onRoleChanged(long personID, int localTableBlogId, String newRole) { | ||
| Person person = PeopleTable.getPerson(personID, localTableBlogId); | ||
| if (person == null || newRole == null || newRole.equalsIgnoreCase(person.getRole())) { | ||
| return; | ||
| } | ||
| PeopleUtils.updateRole(person.getBlogId(), person.getPersonID(), newRole, localTableBlogId, | ||
| new PeopleUtils.UpdateUserCallback() { | ||
| @Override | ||
| public void onSuccess(Person person) { | ||
| PeopleTable.save(person); | ||
| refreshOnScreenFragmentDetails(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError() { | ||
| ToastUtils.showToast(PeopleManagementActivity.this, | ||
| R.string.error_update_role, | ||
| ToastUtils.Duration.LONG); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void confirmRemovePerson() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we're not checking for current user when removing. Should that be allowed? If not, perhaps we can put out a message explaining why it cannot be done, or more simply remove the "remove" button completely. Cheers! |
||
| Person person = getCurrentPerson(); | ||
| if (person == null) { | ||
| return; | ||
| } | ||
|
|
||
| AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Calypso_AlertDialog); | ||
| builder.setTitle(getString(R.string.person_remove_confirmation_title, person.getDisplayName())); | ||
| builder.setMessage(getString(R.string.person_remove_confirmation_message, person.getDisplayName())); | ||
| builder.setNegativeButton(R.string.cancel, null); | ||
| builder.setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() { | ||
| @Override | ||
| public void onClick(DialogInterface dialog, int which) { | ||
| removeSelectedPerson(); | ||
| } | ||
| }); | ||
| builder.show(); | ||
| } | ||
|
|
||
| private void removeSelectedPerson() { | ||
| Person person = getCurrentPerson(); | ||
| if (person == null) { | ||
| return; | ||
| } | ||
| PeopleUtils.removePerson(person.getBlogId(), | ||
| person.getPersonID(), | ||
| person.getLocalTableBlogId(), | ||
| new PeopleUtils.RemoveUserCallback() { | ||
| @Override | ||
| public void onSuccess(long personID, int localTableBlogId) { | ||
| // remove the person from db, navigate back to list fragment and refresh it | ||
| Person person = PeopleTable.getPerson(personID, localTableBlogId); | ||
| String text; | ||
| if (person != null) { | ||
| PeopleTable.deletePerson(personID, localTableBlogId); | ||
| text = getString(R.string.person_removed, person.getUsername()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is by design but, since we are asking for remove confirmation using the Person's display name, I think it makes sense to use the same in the Toast as well. Cheers!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's by design. Although I agree with you, we want to match what Calypso does, and Calypso uses the exact same strings. |
||
| } else { | ||
| text = getString(R.string.person_removed_general); | ||
| } | ||
|
|
||
| ToastUtils.showToast(PeopleManagementActivity.this, text, ToastUtils.Duration.LONG); | ||
|
|
||
| navigateBackToPeopleListFragment(); | ||
| refreshPeopleListFragment(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError() { | ||
| ToastUtils.showToast(PeopleManagementActivity.this, | ||
| R.string.error_remove_user, | ||
| ToastUtils.Duration.LONG); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // This helper method is used after a successful network request | ||
| private void refreshOnScreenFragmentDetails() { | ||
| FragmentManager fragmentManager = getFragmentManager(); | ||
| PersonDetailFragment personDetailFragment = (PersonDetailFragment) fragmentManager | ||
| .findFragmentByTag(KEY_PERSON_DETAIL_FRAGMENT); | ||
|
|
||
| if (personDetailFragment != null) { | ||
| personDetailFragment.refreshPersonDetails(); | ||
| } | ||
|
|
||
| refreshPeopleListFragment(); | ||
| } | ||
|
|
||
| private void refreshPeopleListFragment() { | ||
| FragmentManager fragmentManager = getFragmentManager(); | ||
| PeopleListFragment peopleListFragment = (PeopleListFragment) fragmentManager | ||
| .findFragmentByTag(KEY_PEOPLE_LIST_FRAGMENT); | ||
| if (peopleListFragment != null) { | ||
| peopleListFragment.refreshPeopleList(); | ||
| } | ||
| } | ||
|
|
||
| private boolean navigateBackToPeopleListFragment() { | ||
| if (getFragmentManager().getBackStackEntryCount() > 0) { | ||
| getFragmentManager().popBackStack(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private Person getCurrentPerson() { | ||
| FragmentManager fragmentManager = getFragmentManager(); | ||
| PersonDetailFragment personDetailFragment = (PersonDetailFragment) fragmentManager | ||
| .findFragmentByTag(KEY_PERSON_DETAIL_FRAGMENT); | ||
|
|
||
| if (personDetailFragment == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return personDetailFragment.loadPerson(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in this changeset but, there are a couple of lines below this one that could use the same treatment and be wrapped at 120chars. Cheers!