Add backstack tag for assistant helpers
Fixes a bug in Android O. Pop the helper tag and then pop the second
level tag afterwards. Let super.onBackPressed handle the singular
case of third level.
Unsure why doing it in two steps fixes the problem but it should
effectively be the same.
Test:
Manually verified navigation situations on Nexus 5X running O,
Nexus 6P running 7.1, Nexus 5 running 5.1.1, and Samsung
Galaxy S7 running 6.0.1:
* all contacts to suggestions and pressing back
* all contacts to suggestions to group and pressing back
* all to group and press back
* all to group to suggestions and press back
* all to suggestion to duplicates press back twice
* mixes of the above with rotations and going to a specific
account view, verifying the list is displayed properly
* the above but using the Contacts menu item instead of pressing
back
Bug:33922405
Change-Id: Idb9421be79038b112eb0012e8be17e5692935c70
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 34b4f40..52065c4 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -69,7 +69,6 @@
import com.android.contacts.group.GroupMembersFragment;
import com.android.contacts.group.GroupNameEditDialogFragment;
import com.android.contacts.group.GroupUtil;
-import com.android.contacts.interactions.ContactDeletionInteraction;
import com.android.contacts.list.AccountFilterActivity;
import com.android.contacts.list.ContactListFilter;
import com.android.contacts.list.ContactListFilterController;
@@ -98,6 +97,7 @@
import com.android.contactsbind.FeatureHighlightHelper;
import com.android.contactsbind.HelpUtils;
import com.android.contactsbind.ObjectFactory;
+
import com.google.common.util.concurrent.Futures;
import java.util.Collections;
@@ -130,6 +130,7 @@
public static final String TAG_ASSISTANT = "contacts-assistant";
public static final String TAG_SECOND_LEVEL = "second-level";
public static final String TAG_THIRD_LEVEL = "third-level";
+ public static final String TAG_ASSISTANT_HELPER = "assistant-helper";
public static final String TAG_DUPLICATES = "DuplicatesFragment";
public static final String TAG_DUPLICATES_UTIL = "DuplicatesUtilFragment";
@@ -821,10 +822,11 @@
}
private void onBackPressedAssistantView() {
- if (!popThirdLevel()) {
+ if (!isInThirdLevel()) {
switchToAllContacts();
} else {
setDrawerLockMode(/* enabled */ true);
+ super.onBackPressed();
}
}
@@ -974,6 +976,7 @@
final FragmentManager fragmentManager = getFragmentManager();
final FragmentTransaction transaction = fragmentManager.beginTransaction();
+ popSecondLevel();
if (isGroupView()) {
mMembersFragment = GroupMembersFragment.newInstance(mGroupUri);
transaction.replace(
@@ -998,9 +1001,7 @@
}
public void switchToAllContacts() {
- if (isInSecondLevel()) {
- popSecondLevel();
- }
+ popSecondLevel();
mShouldSwitchToAllContacts = false;
mCurrentView = ContactsView.ALL_CONTACTS;
mDrawerFragment.setNavigationItemChecked(ContactsView.ALL_CONTACTS);
@@ -1018,18 +1019,6 @@
mContactListFilterController, AppCompatActivity.RESULT_OK, intent);
}
- private boolean popThirdLevel() {
- return getFragmentManager().popBackStackImmediate(
- TAG_THIRD_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE);
- }
-
- private void popSecondLevel() {
- getFragmentManager().popBackStackImmediate(
- TAG_SECOND_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE);
- mMembersFragment = null;
- resetToolBarStatusBarColor();
- }
-
// Reset toolbar and status bar color to Contacts theme color.
private void resetToolBarStatusBarColor() {
findViewById(R.id.toolbar_frame).setBackgroundColor(
@@ -1223,7 +1212,33 @@
}
public boolean isInSecondLevel() {
- return isGroupView() || isAssistantView();
+ return isLastBackStackTag(TAG_SECOND_LEVEL);
+ }
+
+ private boolean isInThirdLevel() {
+ return isLastBackStackTag(TAG_THIRD_LEVEL);
+ }
+
+ private boolean isLastBackStackTag(String tag) {
+ final int count = getFragmentManager().getBackStackEntryCount();
+ if (count > 0) {
+ final FragmentManager.BackStackEntry last =
+ getFragmentManager().getBackStackEntryAt(count - 1);
+ if (tag == null) {
+ return last.getName() == null;
+ }
+ return tag.equals(last.getName());
+ }
+ return false;
+ }
+
+ private void popSecondLevel() {
+ getFragmentManager().popBackStackImmediate(
+ TAG_ASSISTANT_HELPER, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+ getFragmentManager().popBackStackImmediate(
+ TAG_SECOND_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+ mMembersFragment = null;
+ resetToolBarStatusBarColor();
}
public void closeDrawer() {