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

Commit 2b15d71b authored by arangelov's avatar arangelov Committed by Antoan Angelov
Browse files

Synchronize direct share expansion between work and personal tabs

For example, if share sheet is fully expanded in personal profile,
when we go to the work tab, the direct share targets should
also be expanded there.

Fixes: 154523836
Test: manual
Test: atest ChooserActivityTest
Change-Id: I9346d7485f7498fc038c86bf5f8550c8ea6d0b48
parent 2688e223
Loading
Loading
Loading
Loading
+47 −9
Original line number Diff line number Diff line
@@ -2885,6 +2885,13 @@ public class ChooserActivity extends ResolverActivity implements
        return METRICS_CATEGORY_CHOOSER;
    }

    @Override
    protected void onProfileTabSelected() {
        ChooserGridAdapter currentRootAdapter =
                mChooserMultiProfilePagerAdapter.getCurrentRootAdapter();
        currentRootAdapter.updateDirectShareExpansion();
    }

    /**
     * Adapter for all types of items and targets in ShareSheet.
     * Note that ranked sections like Direct Share - while appearing grid-like - are handled on the
@@ -3357,15 +3364,7 @@ public class ChooserActivity extends ResolverActivity implements
        }

        public void handleScroll(View v, int y, int oldy) {
            // Only expand direct share area if there is a minimum number of shortcuts,
            // which will help reduce the amount of visible shuffling due to older-style
            // direct share targets.
            int orientation = getResources().getConfiguration().orientation;
            boolean canExpandDirectShare =
                    mChooserListAdapter.getNumShortcutResults() > getMaxTargetsPerRow()
                    && orientation == Configuration.ORIENTATION_PORTRAIT
                    && !isInMultiWindowMode();

            boolean canExpandDirectShare = canExpandDirectShare();
            if (mDirectShareViewHolder != null && canExpandDirectShare) {
                mDirectShareViewHolder.handleScroll(
                        mChooserMultiProfilePagerAdapter.getActiveAdapterView(), y, oldy,
@@ -3373,6 +3372,18 @@ public class ChooserActivity extends ResolverActivity implements
            }
        }

        /**
         * Only expand direct share area if there is a minimum number of shortcuts,
         * which will help reduce the amount of visible shuffling due to older-style
         * direct share targets.
         */
        private boolean canExpandDirectShare() {
            int orientation = getResources().getConfiguration().orientation;
            return mChooserListAdapter.getNumShortcutResults() > getMaxTargetsPerRow()
                    && orientation == Configuration.ORIENTATION_PORTRAIT
                    && !isInMultiWindowMode();
        }

        public ChooserListAdapter getListAdapter() {
            return mChooserListAdapter;
        }
@@ -3380,6 +3391,19 @@ public class ChooserActivity extends ResolverActivity implements
        boolean shouldCellSpan(int position) {
            return getItemViewType(position) == VIEW_TYPE_NORMAL;
        }

        void updateDirectShareExpansion() {
            if (mDirectShareViewHolder == null || !canExpandDirectShare()) {
                return;
            }
            RecyclerView activeAdapterView =
                    mChooserMultiProfilePagerAdapter.getActiveAdapterView();
            if (mResolverDrawerLayout.isCollapsed()) {
                mDirectShareViewHolder.collapse(activeAdapterView);
            } else {
                mDirectShareViewHolder.expand(activeAdapterView);
            }
        }
    }

    /**
@@ -3577,6 +3601,20 @@ public class ChooserActivity extends ResolverActivity implements
            newHeight = Math.max(newHeight, mDirectShareMinHeight);
            yDiff = newHeight - prevHeight;

            updateDirectShareRowHeight(view, yDiff, newHeight);
        }

        void expand(RecyclerView view) {
            updateDirectShareRowHeight(view, mDirectShareMaxHeight - mDirectShareCurrHeight,
                    mDirectShareMaxHeight);
        }

        void collapse(RecyclerView view) {
            updateDirectShareRowHeight(view, mDirectShareMinHeight - mDirectShareCurrHeight,
                    mDirectShareMinHeight);
        }

        private void updateDirectShareRowHeight(RecyclerView view, int yDiff, int newHeight) {
            if (view == null || view.getChildCount() == 0 || yDiff == 0) {
                return;
            }
+7 −0
Original line number Diff line number Diff line
@@ -1622,6 +1622,7 @@ public class ResolverActivity extends Activity implements
            }
            setupViewVisibilities();
            maybeLogProfileChange();
            onProfileTabSelected();
            DevicePolicyEventLogger
                    .createEvent(DevicePolicyEnums.RESOLVER_SWITCH_TABS)
                    .setInt(viewPager.getCurrentItem())
@@ -1640,6 +1641,12 @@ public class ResolverActivity extends Activity implements
        findViewById(R.id.resolver_tab_divider).setVisibility(View.VISIBLE);
    }

    /**
     * Callback called when user changes the profile tab.
     * <p>This method is intended to be overridden by subclasses.
     */
    protected void onProfileTabSelected() { }

    private void resetCheckedItem() {
        if (!isIntentPicker()) {
            return;