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

Commit 88b89d68 authored by fbaron's avatar fbaron Committed by Federico Baron
Browse files

Restore state of widget picker on fold/unfold

Specifically:
-keep selected tab (personal/work)
-keep search results

Fix: 323406345
Test: WidgetPickerImageTest
Flag: ACONFIG com.android.launcher3.enable_unfolded_two_pane_picker TRUNKFOOD
Change-Id: I919e59484f3af7a2b3b007f5c234055a0f7276b3
parent e5451b10
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -20,15 +20,16 @@ import static android.view.View.MeasureSpec.makeMeasureSpec;
import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_DIALOG_SEEN;
import static com.android.launcher3.allapps.ActivityAllAppsContainerView.AdapterHolder.SEARCH;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_SEARCHED;
import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL;

import android.animation.Animator;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.os.Parcelable;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
@@ -99,7 +100,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    // resolution or landscape on phone. This ratio defines the max percentage of content area that
    // the table can display.
    private static final float RECOMMENDATION_TABLE_HEIGHT_RATIO = 0.75f;

    private final UserCache mUserCache;
    private final UserManagerState mUserManagerState = new UserManagerState();
    private final UserHandle mCurrentUser = Process.myUserHandle();
@@ -522,12 +522,14 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    }

    @Override
    public void enterSearchMode() {
    public void enterSearchMode(boolean shouldLog) {
        if (mIsInSearchMode) return;
        setViewVisibilityBasedOnSearch(/*isInSearchMode= */ true);
        attachScrollbarToRecyclerView(mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView);
        if (shouldLog) {
            mActivityContext.getStatsLogManager().logger().log(LAUNCHER_WIDGETSTRAY_SEARCHED);
        }
    }

    @Override
    public void exitSearchMode() {
@@ -789,16 +791,28 @@ public class WidgetsFullSheet extends BaseWidgetSheet
                + marginLayoutParams.topMargin;
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    private int getCurrentAdapterHolderType() {
        if (mIsInSearchMode) {
            mSearchBar.reset();
            return SEARCH;
        } else if (mViewPager != null) {
            return mViewPager.getCurrentPage();
        } else {
            return AdapterHolder.PRIMARY;
        }
    }

    private void restorePreviousAdapterHolderType(int previousAdapterHolderType) {
        if (previousAdapterHolderType == AdapterHolder.WORK && mViewPager != null) {
            mViewPager.setCurrentPage(previousAdapterHolderType);
        } else if (previousAdapterHolderType == AdapterHolder.SEARCH) {
            enterSearchMode(false);
        }
    }

    @Override
    public void onDeviceProfileChanged(DeviceProfile dp) {
        super.onDeviceProfileChanged(dp);

        if (mDeviceProfile.isLandscape != dp.isLandscape && dp.isTablet && !dp.isTwoPanels) {
            handleClose(false);
            show(BaseActivity.fromContext(getContext()), false);
@@ -810,8 +824,12 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        // When folding/unfolding the foldables, we need to switch between the regular widget picker
        // and the two pane picker, so we rebuild the picker with the correct layout.
        if (mDeviceProfile.isTwoPanels != dp.isTwoPanels && enableUnfoldedTwoPanePicker()) {
            SparseArray<Parcelable> widgetsState = new SparseArray<>();
            saveHierarchyState(widgetsState);
            handleClose(false);
            show(BaseActivity.fromContext(getContext()), false);
            WidgetsFullSheet sheet = show(BaseActivity.fromContext(getContext()), false);
            sheet.restoreHierarchyState(widgetsState);
            sheet.restorePreviousAdapterHolderType(getCurrentAdapterHolderType());
        }

        mDeviceProfile = dp;
+0 −5
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.launcher3.widget.picker;
import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Process;
@@ -127,10 +126,6 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
        mFastScroller.setVisibility(GONE);
    }

    /** Overrides onConfigurationChanged method from WidgetsFullSheet. Needed for b/319150904 */
    @Override
    protected void onConfigurationChanged(Configuration newConfig) {}

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ public interface SearchModeListener {
    /**
     * Notifies the subscriber when user enters widget picker search mode.
     */
    void enterSearchMode();
    void enterSearchMode(boolean shouldLog);

    /**
     * Notifies the subscriber when user exits widget picker search mode.
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class WidgetsSearchBarController implements TextWatcher,
            mCancelButton.setVisibility(GONE);
        } else {
            mSearchAlgorithm.cancel(/* interruptActiveRequests= */ false);
            mSearchModeListener.enterSearchMode();
            mSearchModeListener.enterSearchMode(true);
            mSearchAlgorithm.doSearch(mQuery, this);
            mCancelButton.setVisibility(VISIBLE);
        }
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class WidgetsSearchBarControllerTest {
    public void afterTextChanged_shouldInformSearchModeListenerToEnterSearch() {
        mEditText.setText("abc");

        verify(mSearchModeListener).enterSearchMode();
        verify(mSearchModeListener).enterSearchMode(true);
        verifyNoMoreInteractions(mSearchModeListener);
    }