Fix overlapping tool bar and action bar in groups view

When the group action is removing a member from the group
call switchToOrUpdateGroupView so it uses the previous instance.
We need to remember that the fragment was in edit mode.

Test: Checked removing a contact from label using the delete icon
  * Shows the correct toast
  * Updates the list
  * Doesn't show overlapping bars
  * Allows the user to continue deleting contacts.
Also checked correct behavior for:
  * Multiselect removals
  * Multiselect additions
  * Renaming the label

Bug: 32431977

Change-Id: I5597cc5e0ca0a5e0a54dfc3180352fbb90d403d9
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 513109c..fd6ee89 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -272,7 +272,8 @@
 
     @Override
     protected void onNewIntent(Intent intent) {
-        if (GroupUtil.ACTION_CREATE_GROUP.equals(intent.getAction())) {
+        final String action = intent.getAction();
+        if (GroupUtil.ACTION_CREATE_GROUP.equals(action)) {
             mGroupUri = intent.getData();
             if (mGroupUri == null) {
                 toast(R.string.groupSavedErrorToast);
@@ -280,19 +281,19 @@
             }
             if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri);
             switchView(ContactsView.GROUP_VIEW);
-            mMembersFragment.toastForSaveAction(intent.getAction());
+            mMembersFragment.toastForSaveAction(action);
             return;
         }
 
-        if (isGroupDeleteAction(intent.getAction())) {
+        if (isGroupDeleteAction(action)) {
             popSecondLevel();
-            mMembersFragment.toastForSaveAction(intent.getAction());
+            mMembersFragment.toastForSaveAction(action);
             mCurrentView = ContactsView.ALL_CONTACTS;
             showFabWithAnimation(/* showFab */ true);
             return;
         }
 
-        if (isGroupSaveAction(intent.getAction())) {
+        if (isGroupSaveAction(action)) {
             mGroupUri = intent.getData();
             if (mGroupUri == null) {
                 popSecondLevel();
@@ -300,8 +301,15 @@
                 return;
             }
             if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri);
-            switchView(ContactsView.GROUP_VIEW);
-            mMembersFragment.toastForSaveAction(intent.getAction());
+            // ACTION_REMOVE_FROM_GROUP doesn't reload data, so it shouldn't cause b/32223934
+            // but it's necessary to use the previous fragment since
+            // GroupMembersFragment#mIsEditMode needs to be persisted between remove actions.
+            if (GroupUtil.ACTION_REMOVE_FROM_GROUP.equals(action)) {
+                switchToOrUpdateGroupView(action);
+            } else {
+                switchView(ContactsView.GROUP_VIEW);
+            }
+            mMembersFragment.toastForSaveAction(action);
         }
 
         setIntent(intent);
@@ -747,7 +755,7 @@
         mGroupUri = savedInstanceState.getParcelable(KEY_GROUP_URI);
     }
 
-    private void onGroupDeleted(Intent intent) {
+    private void onGroupDeleted(final Intent intent) {
         if (!ContactSaveService.canUndo(intent)) return;
 
         Snackbar.make(mLayoutRoot, getString(R.string.groupDeletedToast), Snackbar.LENGTH_LONG)
@@ -822,7 +830,7 @@
             mMembersFragment = GroupMembersFragment.newInstance(mGroupUri);
             transaction.replace(
                     R.id.contacts_list_container, mMembersFragment, TAG_GROUP_VIEW);
-        } else if(isAssistantView()) {
+        } else if (isAssistantView()) {
             String fragmentTag;
             if (Flags.getInstance().getBoolean(Experiments.ASSISTANT)) {
                 fragmentTag = TAG_ASSISTANT;
diff --git a/src/com/android/contacts/group/GroupMembersFragment.java b/src/com/android/contacts/group/GroupMembersFragment.java
index 4f8f6a8..e71b3a4 100644
--- a/src/com/android/contacts/group/GroupMembersFragment.java
+++ b/src/com/android/contacts/group/GroupMembersFragment.java
@@ -398,7 +398,7 @@
     }
 
     private void sendToGroup(long[] ids, String sendScheme, String title) {
-        if(ids == null || ids.length == 0) return;
+        if (ids == null || ids.length == 0) return;
 
         // Get emails or phone numbers
         // contactMap <contact_id, contact_data>