Merge "Refactor bindPreferenceToTile to properly handle multi-user"

This commit is contained in:
Fan Zhang
2016-11-02 21:05:30 +00:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 8 deletions

View File

@@ -98,16 +98,17 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
}
if (!TextUtils.isEmpty(clsName)) {
pref.setFragment(clsName);
} else if (tile.userHandle != null && tile.userHandle.size() > 1) {
pref.setOnPreferenceClickListener(preference -> {
ProfileSelectDialog.updateUserHandlesIfNeeded(activity, tile);
ProfileSelectDialog.show(activity.getFragmentManager(), tile);
return true;
});
} else if (tile.intent != null) {
final Intent intent = new Intent(tile.intent);
pref.setOnPreferenceClickListener(preference -> {
activity.startActivityForResult(intent, 0);
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
if (tile.userHandle == null) {
activity.startActivityForResult(intent, 0);
} else if (tile.userHandle.size() == 1) {
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
ProfileSelectDialog.show(activity.getFragmentManager(), tile);
}
return true;
});
}

View File

@@ -112,7 +112,9 @@ public class DashboardFeatureProviderImplTest {
tile.userHandle.add(mock(UserHandle.class));
tile.userHandle.add(mock(UserHandle.class));
tile.intent = new Intent();
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123");
preference.getOnPreferenceClickListener().onPreferenceClick(null);