[QL-v2] Reset input state on scroll and restore state on scrolling back.

Bug: 261872461
Test: see video in bug
Change-Id: I18e1923bdd4c40e84e46579296b69268d46c9fa1
diff --git a/src/com/android/launcher3/ExtendedEditText.java b/src/com/android/launcher3/ExtendedEditText.java
index c59f25d..f94a3c5 100644
--- a/src/com/android/launcher3/ExtendedEditText.java
+++ b/src/com/android/launcher3/ExtendedEditText.java
@@ -159,4 +159,14 @@
             listener.onFocusChange(this, focused);
         }
     }
+
+    /**
+     * Save the input, suggestion, hint states when it's on focus, and set to unfocused states.
+     */
+    public void saveFocusedStateAndUpdateToUnfocusedState() {}
+
+    /**
+     * Restore to the previous saved focused state.
+     */
+    public void restoreToFocusedState() {}
 }
diff --git a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
index 92e29bb..229d8f8 100644
--- a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
@@ -41,12 +41,23 @@
                 public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                     int scrolledOffset = recyclerView.computeVerticalScrollOffset();
                     ExtendedEditText input = mSearchUiManager.getEditText();
-                    // Scroll up and scroll to top
-                    if (dy < 0 && scrolledOffset == 0 && input != null) {
-                        boolean isImeEnabledOnSwipeUp = Launcher.getLauncher(mActivityContext)
-                                .getSearchConfig().isImeEnabledOnSwipeUp();
-                        if (isImeEnabledOnSwipeUp || !TextUtils.isEmpty(input.getText())) {
-                            input.showKeyboard();
+                    if (input != null) {
+                        // Save the input box state on scroll down
+                        if (dy > 0) {
+                            input.saveFocusedStateAndUpdateToUnfocusedState();
+                        }
+
+                        // Scroll up and scroll to top
+                        if (dy < 0 && scrolledOffset == 0) {
+                            // Show keyboard
+                            boolean isImeEnabledOnSwipeUp = Launcher.getLauncher(mActivityContext)
+                                    .getSearchConfig().isImeEnabledOnSwipeUp();
+                            if (isImeEnabledOnSwipeUp || !TextUtils.isEmpty(input.getText())) {
+                                input.showKeyboard();
+                            }
+
+                            // Restore state in input box
+                            input.restoreToFocusedState();
                         }
                     }
                 }