Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c3ed4de authored by Antoan Angelov's avatar Antoan Angelov Committed by Android (Google) Code Review
Browse files

Merge "Fix sharesheet height expansion." into rvc-dev

parents bed09965 c4dbdbd2
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -154,7 +154,6 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
    @Override
    public ViewGroup instantiateItem(ViewGroup container, int position) {
        final ProfileDescriptor profileDescriptor = getItem(position);
        setupListAdapter(position);
        container.addView(profileDescriptor.rootView);
        return profileDescriptor.rootView;
    }
@@ -208,8 +207,8 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
    abstract int getItemCount();

    /**
     * Responsible for assigning an adapter to the list view for the relevant page, specified by
     * <code>pageIndex</code>, and other list view-related initialization procedures.
     * Performs view-related initialization procedures for the adapter specified
     * by <code>pageIndex</code>.
     */
    abstract void setupListAdapter(int pageIndex);

+51 −14
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ public class ChooserActivity extends ResolverActivity implements
    private int mChooserRowServiceSpacing;

    private int mCurrAvailableWidth = 0;
    private int mLastNumberOfChildren = -1;

    private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment";
    // TODO: Update to handle landscape instead of using static value
@@ -967,6 +968,7 @@ public class ChooserActivity extends ResolverActivity implements
        super.onConfigurationChanged(newConfig);

        adjustPreviewWidth(newConfig.orientation, null);
        updateStickyContentPreview();
    }

    private boolean shouldDisplayLandscape(int orientation) {
@@ -987,8 +989,6 @@ public class ChooserActivity extends ResolverActivity implements
        updateLayoutWidth(R.id.content_preview_text_layout, width, parent);
        updateLayoutWidth(R.id.content_preview_title_layout, width, parent);
        updateLayoutWidth(R.id.content_preview_file_layout, width, parent);
        findViewById(R.id.content_preview_container)
                .setVisibility(shouldShowStickyContentPreview() ? View.VISIBLE : View.GONE);
    }

    private void updateLayoutWidth(int layoutResourceId, int width, View parent) {
@@ -2398,14 +2398,17 @@ public class ChooserActivity extends ResolverActivity implements
        }

        final int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight();
        if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() != getUser()) {
            gridAdapter.calculateChooserTargetWidth(availableWidth);
            return;
        }

        if (gridAdapter.consumeLayoutRequest()
                || gridAdapter.calculateChooserTargetWidth(availableWidth)
                || recyclerView.getAdapter() == null
                || mLastNumberOfChildren != recyclerView.getChildCount()
                || availableWidth != mCurrAvailableWidth) {
            mCurrAvailableWidth = availableWidth;
            recyclerView.setAdapter(gridAdapter);
            ((GridLayoutManager) recyclerView.getLayoutManager())
                    .setSpanCount(gridAdapter.getMaxTargetsPerRow());

            getMainThreadHandler().post(() -> {
                if (mResolverDrawerLayout == null || gridAdapter == null) {
@@ -2415,7 +2418,8 @@ public class ChooserActivity extends ResolverActivity implements
                final int bottomInset = mSystemWindowInsets != null
                                            ? mSystemWindowInsets.bottom : 0;
                int offset = bottomInset;
                int rowsToShow = gridAdapter.getProfileRowCount()
                int rowsToShow = gridAdapter.getContentPreviewRowCount()
                        + gridAdapter.getProfileRowCount()
                        + gridAdapter.getServiceTargetRowCount()
                        + gridAdapter.getCallerAndRankedTargetRowCount();

@@ -2434,8 +2438,9 @@ public class ChooserActivity extends ResolverActivity implements
                    return;
                }

                if (shouldShowStickyContentPreview()) {
                    offset += findViewById(R.id.content_preview_container).getHeight();
                View stickyContentPreview = findViewById(R.id.content_preview_container);
                if (shouldShowStickyContentPreview() && isStickyContentPreviewShowing()) {
                    offset += stickyContentPreview.getHeight();
                }

                if (shouldShowTabs()) {
@@ -2444,6 +2449,7 @@ public class ChooserActivity extends ResolverActivity implements

                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);
@@ -2526,6 +2532,14 @@ public class ChooserActivity extends ResolverActivity implements
        setupScrollListener();

        ChooserListAdapter chooserListAdapter = (ChooserListAdapter) listAdapter;
        if (chooserListAdapter.getUserHandle()
                == mChooserMultiProfilePagerAdapter.getCurrentUserHandle()) {
            mChooserMultiProfilePagerAdapter.getActiveAdapterView()
                    .setAdapter(mChooserMultiProfilePagerAdapter.getCurrentRootAdapter());
            mChooserMultiProfilePagerAdapter
                    .setupListAdapter(mChooserMultiProfilePagerAdapter.getCurrentPage());
        }

        if (chooserListAdapter.mDisplayList == null
                || chooserListAdapter.mDisplayList.isEmpty()) {
            chooserListAdapter.notifyDataSetChanged();
@@ -2617,14 +2631,29 @@ public class ChooserActivity extends ResolverActivity implements
     * we instead show the content preview as a regular list item.
     */
    private boolean shouldShowStickyContentPreview() {
        return shouldShowStickyContentPreviewNoOrientationCheck()
                && getResources().getBoolean(R.bool.sharesheet_show_content_preview);
    }

    private boolean shouldShowStickyContentPreviewNoOrientationCheck() {
        return shouldShowTabs()
                && mMultiProfilePagerAdapter.getListAdapterForUserHandle(
                UserHandle.of(UserHandle.myUserId())).getCount() > 0
                && isSendAction(getTargetIntent())
                && getResources().getBoolean(R.bool.sharesheet_show_content_preview);
                && isSendAction(getTargetIntent());
    }

    private void updateStickyContentPreview() {
        if (shouldShowStickyContentPreviewNoOrientationCheck()) {
            // The sticky content preview is only shown when we show the work and personal tabs.
            // We don't show it in landscape as otherwise there is no room for scrolling.
            // If the sticky content preview will be shown at some point with orientation change,
            // then always preload it to avoid subsequent resizing of the share sheet.
            ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
            if (contentPreviewContainer.getChildCount() == 0) {
                ViewGroup contentPreviewView = createContentPreviewView(contentPreviewContainer);
                contentPreviewContainer.addView(contentPreviewView);
            }
        }
        if (shouldShowStickyContentPreview()) {
            showStickyContentPreview();
        } else {
@@ -2633,15 +2662,23 @@ public class ChooserActivity extends ResolverActivity implements
    }

    private void showStickyContentPreview() {
        if (isStickyContentPreviewShowing()) {
            return;
        }
        ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
        contentPreviewContainer.setVisibility(View.VISIBLE);
        ViewGroup contentPreviewView = createContentPreviewView(contentPreviewContainer);
        contentPreviewContainer.addView(contentPreviewView);
    }

    private boolean isStickyContentPreviewShowing() {
        ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
        return contentPreviewContainer.getVisibility() == View.VISIBLE;
    }

    private void hideStickyContentPreview() {
        if (!isStickyContentPreviewShowing()) {
            return;
        }
        ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
        contentPreviewContainer.removeAllViews();
        contentPreviewContainer.setVisibility(View.GONE);
    }

+0 −1
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
        final RecyclerView recyclerView = getItem(pageIndex).recyclerView;
        ChooserActivity.ChooserGridAdapter chooserGridAdapter =
                getItem(pageIndex).chooserGridAdapter;
        recyclerView.setAdapter(chooserGridAdapter);
        GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
        glm.setSpanCount(chooserGridAdapter.getMaxTargetsPerRow());
        glm.setSpanSizeLookup(
+9 −0
Original line number Diff line number Diff line
@@ -396,6 +396,11 @@ public class ResolverActivity extends Activity implements
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets);

            if (shouldShowTabs() && isIntentPicker()) {
                rdl.setMaxCollapsedHeight(getResources()
                        .getDimensionPixelSize(R.dimen.resolver_max_collapsed_height_with_tabs));
            }

            mResolverDrawerLayout = rdl;
        }

@@ -413,6 +418,10 @@ public class ResolverActivity extends Activity implements
                        + (categories != null ? Arrays.toString(categories.toArray()) : ""));
    }

    private boolean isIntentPicker() {
        return getClass().equals(ResolverActivity.class);
    }

    protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter(
            Intent[] initialIntents,
            List<ResolveInfo> rList,
+6 −0
Original line number Diff line number Diff line
@@ -93,6 +93,12 @@ public class ResolverMultiProfilePagerAdapter extends AbstractMultiProfilePagerA
        return mItems[pageIndex].resolverListAdapter;
    }

    @Override
    public ViewGroup instantiateItem(ViewGroup container, int position) {
        setupListAdapter(position);
        return super.instantiateItem(container, position);
    }

    @Override
    @Nullable
    ResolverListAdapter getListAdapterForUserHandle(UserHandle userHandle) {
Loading