Show switch profile button only if multiple profiles exist
Bug: 210998442
Test: manual and atest com.android.providers.media.photopicker.espresso
Change-Id: I9b49827c293b52858444fc989bf31644d3a0ed87
diff --git a/src/com/android/providers/media/photopicker/ui/TabFragment.java b/src/com/android/providers/media/photopicker/ui/TabFragment.java
index 6efda0b..c5626ab 100644
--- a/src/com/android/providers/media/photopicker/ui/TabFragment.java
+++ b/src/com/android/providers/media/photopicker/ui/TabFragment.java
@@ -137,13 +137,7 @@
}
mRecyclerView.setPadding(0, 0, 0, dimen);
- if (mUserIdManager.isMultiUserProfiles()) {
- if (shouldShowProfileButton()) {
- mProfileButton.show();
- } else {
- mProfileButton.hide();
- }
- }
+ updateProfileButtonVisibility();
});
}
@@ -154,8 +148,8 @@
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
mProfileButton.hide();
- } else if (shouldShowProfileButton()) {
- mProfileButton.show();
+ } else {
+ updateProfileButtonVisibility();
}
}
});
@@ -184,22 +178,17 @@
}
private void setUpProfileButton() {
+ updateProfileButtonVisibility();
if (!mUserIdManager.isMultiUserProfiles()) {
- if (mProfileButton.getVisibility() == View.VISIBLE) {
- mProfileButton.setVisibility(View.GONE);
- }
return;
}
- if (shouldShowProfileButton()) {
- mProfileButton.setVisibility(View.VISIBLE);
- }
updateProfileButtonContent(mUserIdManager.isManagedUserSelected());
updateProfileButtonColor(/* isDisabled */ !mUserIdManager.isCrossProfileAllowed());
}
private boolean shouldShowProfileButton() {
- return !mHideProfileButton &&
+ return mUserIdManager.isMultiUserProfiles() && !mHideProfileButton &&
(!mSelection.canSelectMultiple() ||
mSelection.getSelectedItemCount().getValue() == 0);
}
@@ -261,10 +250,14 @@
protected void hideProfileButton(boolean hide) {
mHideProfileButton = hide;
- if (hide) {
- mProfileButton.hide();
- } else if (mUserIdManager.isMultiUserProfiles() && shouldShowProfileButton()) {
+ updateProfileButtonVisibility();
+ }
+
+ private void updateProfileButtonVisibility() {
+ if (shouldShowProfileButton()) {
mProfileButton.show();
+ } else {
+ mProfileButton.hide();
}
}
diff --git a/tests/src/com/android/providers/media/photopicker/espresso/MultiSelectTest.java b/tests/src/com/android/providers/media/photopicker/espresso/MultiSelectTest.java
index afa4594..2dda726 100644
--- a/tests/src/com/android/providers/media/photopicker/espresso/MultiSelectTest.java
+++ b/tests/src/com/android/providers/media/photopicker/espresso/MultiSelectTest.java
@@ -53,6 +53,11 @@
= new ActivityScenarioRule<>(PhotoPickerBaseTest.getMultiSelectionIntent());
@Test
+ public void testMultiSelectDoesNotShowProfileButton() {
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+ }
+
+ @Test
public void testMultiselect_showDragBar() {
onView(withId(DRAG_BAR_ID)).check(matches(isDisplayed()));
}
diff --git a/tests/src/com/android/providers/media/photopicker/espresso/PhotoPickerActivityTest.java b/tests/src/com/android/providers/media/photopicker/espresso/PhotoPickerActivityTest.java
index 161bc52..c7567bb 100644
--- a/tests/src/com/android/providers/media/photopicker/espresso/PhotoPickerActivityTest.java
+++ b/tests/src/com/android/providers/media/photopicker/espresso/PhotoPickerActivityTest.java
@@ -75,6 +75,48 @@
}
@Test
+ public void testDoesNotShowProfileButton() {
+ // Register bottom sheet idling resource so that we don't read bottom sheet state when
+ // in between changing states
+ registerBottomSheetStateIdlingResource();
+
+ // Single select PhotoPicker is launched in partial screen mode
+ onView(withId(DRAG_BAR_ID)).check(matches(isDisplayed()));
+ mRule.getScenario().onActivity(activity -> {
+ assertBottomSheetState(activity, STATE_COLLAPSED);
+ });
+ // Partial screen does not show profile button
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+
+ // Swipe up and check that the PhotoPicker is in full screen mode
+ onView(withId(DRAG_BAR_ID)).perform(ViewActions.swipeUp());
+ mRule.getScenario().onActivity(activity -> {
+ assertBottomSheetState(activity, STATE_EXPANDED);
+ });
+ // Full screen does not show profile button as well
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+
+ // Navigate to Albums tab
+ onView(allOf(withText(PICKER_ALBUMS_STRING_ID), withParent(withId(CHIP_CONTAINER_ID))))
+ .perform(click());
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+
+ final int cameraStringId = R.string.picker_category_camera;
+ // Navigate to photos in Camera album
+ onView(allOf(withText(cameraStringId),
+ isDescendantOfA(withId(PICKER_TAB_RECYCLERVIEW_ID)))).perform(click());
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+
+ // Click back button
+ onView(withContentDescription("Navigate up")).perform(click());
+
+ // on clicking back button we are back to Album grid
+ onView(allOf(withText(PICKER_ALBUMS_STRING_ID), withParent(withId(CHIP_CONTAINER_ID))))
+ .check(matches(isSelected()));
+ onView(withId(R.id.profile_button)).check(matches(not(isDisplayed())));
+ }
+
+ @Test
public void testBottomSheetState() {
// Register bottom sheet idling resource so that we don't read bottom sheet state when
// in between changing states