Merge "Return the correct position for the profile tab" into main
This commit is contained in:
@@ -230,7 +230,8 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
|
||||
if (bundle != null) {
|
||||
final int extraTab = bundle.getInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, -1);
|
||||
if (extraTab != -1) {
|
||||
return ((ViewPagerAdapter) mViewPager.getAdapter()).getTabForPosition(extraTab);
|
||||
return ((ViewPagerAdapter) mViewPager.getAdapter())
|
||||
.getPositionForProfileTab(extraTab);
|
||||
}
|
||||
final int userId = bundle.getInt(EXTRA_USER_ID, UserHandle.SYSTEM.getIdentifier());
|
||||
final boolean isWorkProfile = UserManager.get(activity).isManagedProfile(userId);
|
||||
@@ -410,7 +411,22 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
|
||||
}
|
||||
@ProfileType
|
||||
int profileType = mChildFragments[position].getArguments().getInt(EXTRA_PROFILE);
|
||||
return profileTypeToTab(profileType);
|
||||
}
|
||||
|
||||
private int getPositionForProfileTab(int profileTab) {
|
||||
for (int i = 0; i < mChildFragments.length; ++i) {
|
||||
Bundle arguments = mChildFragments[i].getArguments();
|
||||
if (arguments != null
|
||||
&& profileTypeToTab(arguments.getInt(EXTRA_PROFILE)) == profileTab) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "position requested for an unknown profile tab " + profileTab);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int profileTypeToTab(@ProfileType int profileType) {
|
||||
if (profileType == ProfileType.WORK) {
|
||||
return WORK_TAB;
|
||||
}
|
||||
|
@@ -118,7 +118,9 @@ public class ProfileSelectFragmentTest {
|
||||
profileSelectFragment.setViewPager(viewPager);
|
||||
mFragmentManager.beginTransaction().add(profileSelectFragment, "tag");
|
||||
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(WORK_TAB);
|
||||
// The expected position '2' comes from the order in which fragments are added in
|
||||
// TestProfileSelectFragment#getFragments()
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +138,9 @@ public class ProfileSelectFragmentTest {
|
||||
profileSelectFragment.setViewPager(viewPager);
|
||||
mFragmentManager.beginTransaction().add(profileSelectFragment, "tag");
|
||||
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(PRIVATE_TAB);
|
||||
// The expected position '1' comes from the order in which fragments are added in
|
||||
// TestProfileSelectFragment#getFragments()
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -343,10 +347,25 @@ public class ProfileSelectFragmentTest {
|
||||
|
||||
@Override
|
||||
public Fragment[] getFragments() {
|
||||
Fragment personalFragment = new SettingsPreferenceFragmentTest.TestFragment();
|
||||
Bundle personalBundle = new Bundle();
|
||||
personalBundle.putInt(EXTRA_PROFILE, ProfileType.PERSONAL);
|
||||
personalFragment.setArguments(personalBundle);
|
||||
|
||||
Fragment workFragment = new SettingsPreferenceFragmentTest.TestFragment();
|
||||
Bundle workBundle = new Bundle();
|
||||
workBundle.putInt(EXTRA_PROFILE, ProfileType.WORK);
|
||||
workFragment.setArguments(workBundle);
|
||||
|
||||
Fragment privateFragment = new SettingsPreferenceFragmentTest.TestFragment();
|
||||
Bundle privateBundle = new Bundle();
|
||||
privateBundle.putInt(EXTRA_PROFILE, ProfileType.PRIVATE);
|
||||
privateFragment.setArguments(privateBundle);
|
||||
|
||||
return new Fragment[]{
|
||||
new SettingsPreferenceFragmentTest.TestFragment(), //0
|
||||
new SettingsPreferenceFragmentTest.TestFragment(),
|
||||
new SettingsPreferenceFragmentTest.TestFragment()
|
||||
personalFragment, //0
|
||||
privateFragment,
|
||||
workFragment
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user