From 7ccbefcc569ac341bae84bf4c18bae44dcedd80d Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Thu, 11 Jan 2018 15:29:50 +0000 Subject: [PATCH] Fix work tab is gone when leaving search mode 1. onSearchResultsChanged is not called if the query is empty. Introduce onClearSearchResult and restore the tab there 2. rebindAdapters should only perform the actual logic if showTabs != mShowTabs, except the first time when we init the layout in onFinishInflate. Fix: 71737947 Change-Id: I5485d6be0fc33b73aa6e0709be66cef8d43b4dbd --- .../allapps/AllAppsContainerView.java | 27 +++++++++++-------- .../search/AppsSearchContainerLayout.java | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index a40f8b3809..b88efddf93 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -27,7 +27,6 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Selection; import android.text.SpannableStringBuilder; -import android.text.TextUtils; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -149,9 +148,7 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, */ public void setApps(List apps) { boolean hasWorkProfileApp = hasWorkProfileApp(apps); - if (mUsingTabs != hasWorkProfileApp) { - rebindAdapters(hasWorkProfileApp); - } + rebindAdapters(hasWorkProfileApp); mComponentToAppMap.clear(); addOrUpdateApps(apps); } @@ -261,7 +258,7 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, }); mHeader = findViewById(R.id.all_apps_header); - rebindAdapters(mUsingTabs); + rebindAdapters(mUsingTabs, true /* force */); mSearchContainer = findViewById(R.id.search_container_all_apps); mSearchUiManager = (SearchUiManager) mSearchContainer; @@ -385,9 +382,14 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, } private void rebindAdapters(boolean showTabs) { - if (showTabs != mUsingTabs) { - replaceRVContainer(showTabs); + rebindAdapters(showTabs, false /* force */); + } + + private void rebindAdapters(boolean showTabs, boolean force) { + if (showTabs == mUsingTabs && !force) { + return; } + replaceRVContainer(showTabs); mUsingTabs = showTabs; if (mUsingTabs) { @@ -529,13 +531,16 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, for (int i = 0; i < mAH.length; i++) { mAH[i].adapter.setLastSearchQuery(query); } - boolean hasQuery = !TextUtils.isEmpty(query); - if (mUsingTabs && hasQuery) { + if (mUsingTabs) { mSearchModeWhileUsingTabs = true; rebindAdapters(false); // hide tabs - } else if (mSearchModeWhileUsingTabs && !hasQuery) { - mSearchModeWhileUsingTabs = false; + } + } + + public void onClearSearchResult() { + if (mSearchModeWhileUsingTabs) { rebindAdapters(true); // show tabs + mSearchModeWhileUsingTabs = false; } } diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index e65a2c4eac..ed41f133a2 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -184,6 +184,7 @@ public class AppsSearchContainerLayout extends FrameLayout mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); + mAppsView.onClearSearchResult(); } @Override