When calculating share sheet height, account for empty state screens.

As we calculate the share sheet height only for the current profile,
there is a rare case when the current profile may have no results.
For that case, we need to adjust the share sheet offset so that
it includes the empty state screen height.

In addition, this CL also does an early return if we are
in the non-main profile (e.g. personal tab in work profile)
to prevent the height from being recalculated upon tab switch.

Fixes: 150939637
Test: manual
Change-Id: Ia465f53d7a2006e1b7c67ad1e95729ed79e2c3a0
This commit is contained in:
arangelov
2020-03-11 18:33:26 +00:00
parent 5527ace031
commit a30787b8fa
2 changed files with 45 additions and 31 deletions

View File

@@ -452,7 +452,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
mEmptyStateView = rootView.findViewById(R.id.resolver_empty_state);
}
private ViewGroup getEmptyStateView() {
protected ViewGroup getEmptyStateView() {
return mEmptyStateView;
}
}

View File

@@ -2411,6 +2411,8 @@ public class ChooserActivity extends ResolverActivity implements
mChooserMultiProfilePagerAdapter.getActiveAdapterView()
.setAdapter(mChooserMultiProfilePagerAdapter.getCurrentRootAdapter());
return;
} else if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() != getUser()) {
return;
}
getMainThreadHandler().post(() -> {
@@ -2455,39 +2457,46 @@ public class ChooserActivity extends ResolverActivity implements
offset += tabDivider.getHeight();
}
int directShareHeight = 0;
rowsToShow = Math.min(4, rowsToShow);
mLastNumberOfChildren = recyclerView.getChildCount();
for (int i = 0, childCount = recyclerView.getChildCount();
i < childCount && rowsToShow > 0; i++) {
View child = recyclerView.getChildAt(i);
if (((GridLayoutManager.LayoutParams)
child.getLayoutParams()).getSpanIndex() != 0) {
continue;
if (recyclerView.getVisibility() == View.VISIBLE) {
int directShareHeight = 0;
rowsToShow = Math.min(4, rowsToShow);
mLastNumberOfChildren = recyclerView.getChildCount();
for (int i = 0, childCount = recyclerView.getChildCount();
i < childCount && rowsToShow > 0; i++) {
View child = recyclerView.getChildAt(i);
if (((GridLayoutManager.LayoutParams)
child.getLayoutParams()).getSpanIndex() != 0) {
continue;
}
int height = child.getHeight();
offset += height;
if (gridAdapter.getTargetType(
recyclerView.getChildAdapterPosition(child))
== ChooserListAdapter.TARGET_SERVICE) {
directShareHeight = height;
}
rowsToShow--;
}
int height = child.getHeight();
offset += height;
if (gridAdapter.getTargetType(
recyclerView.getChildAdapterPosition(child))
== ChooserListAdapter.TARGET_SERVICE) {
directShareHeight = height;
boolean isExpandable = getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT && !isInMultiWindowMode();
if (directShareHeight != 0 && isSendAction(getTargetIntent())
&& isExpandable) {
// make sure to leave room for direct share 4->8 expansion
int requiredExpansionHeight =
(int) (directShareHeight / DIRECT_SHARE_EXPANSION_RATE);
int topInset = mSystemWindowInsets != null ? mSystemWindowInsets.top : 0;
int minHeight = bottom - top - mResolverDrawerLayout.getAlwaysShowHeight()
- requiredExpansionHeight - topInset - bottomInset;
offset = Math.min(offset, minHeight);
}
} else {
ViewGroup currentEmptyStateView = getCurrentEmptyStateView();
if (currentEmptyStateView.getVisibility() == View.VISIBLE) {
offset += currentEmptyStateView.getHeight();
}
rowsToShow--;
}
boolean isExpandable = getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT && !isInMultiWindowMode();
if (directShareHeight != 0 && isSendAction(getTargetIntent())
&& isExpandable) {
// make sure to leave room for direct share 4->8 expansion
int requiredExpansionHeight =
(int) (directShareHeight / DIRECT_SHARE_EXPANSION_RATE);
int topInset = mSystemWindowInsets != null ? mSystemWindowInsets.top : 0;
int minHeight = bottom - top - mResolverDrawerLayout.getAlwaysShowHeight()
- requiredExpansionHeight - topInset - bottomInset;
offset = Math.min(offset, minHeight);
}
mResolverDrawerLayout.setCollapsibleHeightReserved(Math.min(offset, bottom - top));
@@ -2495,6 +2504,11 @@ public class ChooserActivity extends ResolverActivity implements
}
}
private ViewGroup getCurrentEmptyStateView() {
int currentPage = mChooserMultiProfilePagerAdapter.getCurrentPage();
return mChooserMultiProfilePagerAdapter.getItem(currentPage).getEmptyStateView();
}
static class BaseChooserTargetComparator implements Comparator<ChooserTarget> {
@Override
public int compare(ChooserTarget lhs, ChooserTarget rhs) {