diff --git a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt index 0325d69627..8dc6a83204 100644 --- a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt +++ b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt @@ -56,6 +56,8 @@ import app.lawnchair.search.algorithms.LawnchairSearchAlgorithm import app.lawnchair.theme.color.tokens.ColorTokens import app.lawnchair.ui.theme.LawnchairTheme import app.lawnchair.util.ProvideLifecycleState +import com.android.launcher3.DeviceProfile +import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener import com.android.launcher3.Insettable import com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener import com.android.launcher3.LauncherState @@ -77,6 +79,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs), Insettable, OnIDPChangeListener, + OnDeviceProfileChangeListener, SearchUiManager, SearchCallback, AllAppsStore.OnUpdateListener, @@ -118,6 +121,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : private var initialPaddingLeft: Int = 0 private var initialPaddingRight: Int = 0 + private var paddingAnimator: ValueAnimator? = null private var hideSearchBar = false override fun onFinishInflate() { @@ -260,9 +264,6 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } }) - val currentPaddingLeft = initialPaddingLeft - val currentPaddingRight = initialPaddingRight - // Activate zero search on tap @SuppressLint("ClickableViewAccessibility") input.setOnTouchListener { _, event -> @@ -287,7 +288,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : setBackgroundVisibility(false, 0f) animateHintVisibility(true) - animatePadding(currentPaddingLeft / 2, currentPaddingRight / 2) + animatePadding(initialPaddingLeft / 2, initialPaddingRight / 2) } else { setBackgroundVisibility(true, 1f) animateHintVisibility(false) @@ -297,7 +298,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } if (input.text.isNullOrEmpty()) { - animatePadding(currentPaddingLeft, currentPaddingRight) + animatePadding(initialPaddingLeft, initialPaddingRight) } focusedResultTitle = "" input.setHint("") @@ -326,7 +327,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val isEmpty = it.isNullOrEmpty() if (isEmpty && !input.hasFocus()) { - animatePadding(currentPaddingLeft, currentPaddingRight) + animatePadding(initialPaddingLeft, initialPaddingRight) } queryEmpty = isEmpty }, @@ -345,7 +346,11 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val padding = dp.getAllAppsIconStartMargin(context) initialPaddingLeft = padding initialPaddingRight = padding - setPadding(padding, paddingTop, padding, paddingBottom) + // Keep the narrower padding of an active search (see the focus and text listeners) + paddingAnimator?.cancel() + val isSearchActive = ::input.isInitialized && (input.hasFocus() || !input.text.isNullOrEmpty()) + val currentPadding = if (isSearchActive) padding / 2 else padding + setPadding(currentPadding, paddingTop, currentPadding, paddingBottom) } } @@ -372,7 +377,8 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val currentPaddingLeft = paddingLeft val currentPaddingRight = paddingRight - ValueAnimator.ofFloat(0f, 1f).apply { + paddingAnimator?.cancel() + paddingAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 300 interpolator = FastOutSlowInInterpolator() addUpdateListener { animation -> @@ -421,6 +427,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : override fun onAttachedToWindow() { super.onAttachedToWindow() launcher.deviceProfile.inv.addOnChangeListener(this) + launcher.addOnDeviceProfileChangeListener(this) if (::appsView.isInitialized) { appsView.appsStore?.addUpdateListener(this) } @@ -430,6 +437,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : override fun onDetachedFromWindow() { super.onDetachedFromWindow() launcher.deviceProfile.inv.removeOnChangeListener(this) + launcher.removeOnDeviceProfileChangeListener(this) if (::appsView.isInitialized) { appsView.appsStore?.removeUpdateListener(this) } @@ -548,6 +556,13 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : bgAlphaState = Utilities.mapRange(fraction, 0f, bgAlpha) } + override fun onDeviceProfileChanged(dp: DeviceProfile) { + // LC-Note: The paddings follow the device profile, which also changes without an IDP + // change, e.g. on rotation or when a foldable is folded or unfolded. + setupPadding() + requestLayout() + } + override fun onIdpChanged(modelPropertiesChanged: Boolean) { setupPadding() invalidate()