Merge "Autolaunch when active tab has 1 target and inactive tab has 0 targets."

This commit is contained in:
Antoan Angelov
2020-02-13 14:33:24 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 8 deletions

View File

@@ -1278,10 +1278,9 @@ public class ResolverActivity extends Activity implements
throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() "
+ "cannot be null.");
}
boolean rebuildCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true);
// We partially rebuild the inactive adapter to determine if we should auto launch
mMultiProfilePagerAdapter.rebuildInactiveTab(false);
boolean rebuildActiveCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true);
boolean rebuildInactiveCompleted = mMultiProfilePagerAdapter.rebuildInactiveTab(false);
if (useLayoutWithDefault()) {
mLayoutId = R.layout.resolver_list_with_default;
@@ -1290,7 +1289,7 @@ public class ResolverActivity extends Activity implements
}
setContentView(mLayoutId);
mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager));
return postRebuildList(rebuildCompleted);
return postRebuildList(rebuildActiveCompleted && rebuildInactiveCompleted);
}
/**
@@ -1338,10 +1337,11 @@ public class ResolverActivity extends Activity implements
int numberOfProfiles = mMultiProfilePagerAdapter.getItemCount();
if (numberOfProfiles == 1 && maybeAutolaunchIfSingleTarget()) {
return true;
} else if (numberOfProfiles == 2 && maybeAutolaunchIfCrossProfileSupported()) {
// note that autolaunching when we have 2 profiles, 1 resolved target on the active
// tab and 0 resolved targets on the inactive tab, is already handled before launching
// ResolverActivity
} else if (numberOfProfiles == 2
&& mMultiProfilePagerAdapter.getActiveListAdapter().isListLoaded()
&& mMultiProfilePagerAdapter.getInactiveListAdapter().isListLoaded()
&& (maybeAutolaunchIfNoAppsOnInactiveTab()
|| maybeAutolaunchIfCrossProfileSupported())) {
return true;
}
return false;
@@ -1364,6 +1364,23 @@ public class ResolverActivity extends Activity implements
return false;
}
private boolean maybeAutolaunchIfNoAppsOnInactiveTab() {
int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount();
if (count != 1) {
return false;
}
ResolverListAdapter inactiveListAdapter =
mMultiProfilePagerAdapter.getInactiveListAdapter();
if (inactiveListAdapter.getUnfilteredCount() != 0) {
return false;
}
TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter()
.targetInfoForPosition(0, false);
safelyStartActivity(target);
finish();
return true;
}
/**
* When we have a personal and a work profile, we auto launch in the following scenario:
* - There is 1 resolved target on each profile

View File

@@ -87,6 +87,7 @@ public class ResolverListAdapter extends BaseAdapter {
private final ResolverListCommunicator mResolverListCommunicator;
private Runnable mPostListReadyRunnable;
private final boolean mIsAudioCaptureDevice;
private boolean mIsListLoaded;
public ResolverListAdapter(Context context, List<Intent> payloadIntents,
Intent[] initialIntents, List<ResolveInfo> rList,
@@ -191,6 +192,7 @@ public class ResolverListAdapter extends BaseAdapter {
mLastChosenPosition = -1;
mAllTargetsAreBrowsers = false;
mDisplayList.clear();
mIsListLoaded = false;
if (mBaseResolveList != null) {
currentResolveList = mUnfilteredResolveList = new ArrayList<>();
@@ -352,6 +354,7 @@ public class ResolverListAdapter extends BaseAdapter {
mResolverListCommunicator.sendVoiceChoicesIfNeeded();
postListReadyRunnable(doPostProcessing);
mIsListLoaded = true;
}
/**
@@ -611,6 +614,10 @@ public class ResolverListAdapter extends BaseAdapter {
return mIntents;
}
protected boolean isListLoaded() {
return mIsListLoaded;
}
/**
* Necessary methods to communicate between {@link ResolverListAdapter}
* and {@link ResolverActivity}.