Bug 1207340 - Pref/Search Engine Suggestions UI can get out of sync. r=mcomella
authorPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>
Fri, 13 Nov 2015 02:20:00 +0100
changeset 308708 d70d6466d7eb490018c47ed2a2f3c9f457209999
parent 308707 fda060cdf44aaa98116d4ed21d6043155ef81892
child 308709 2164981a754ebace64225a68f79e67eba09f9fce
push id7514
push users.kaspari@gmail.com
push dateFri, 13 Nov 2015 14:12:41 +0000
reviewersmcomella
bugs1207340
milestone45.0a1
Bug 1207340 - Pref/Search Engine Suggestions UI can get out of sync. r=mcomella
mobile/android/base/home/BrowserSearch.java
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -630,19 +630,25 @@ public class BrowserSearch extends HomeF
                 mLastLocale = Locale.getDefault();
                 updateSearchEngineBar();
 
                 mAdapter.notifyDataSetChanged();
             }
 
             // Show suggestions opt-in prompt only if suggestions are not enabled yet,
             // user hasn't been prompted and we're not on a private browsing tab.
+            // The prompt might have been inflated already when this view was previously called.
+            // Remove the opt-in prompt if it has been inflated in the view and dealt with by the user,
+            // or if we're on a private browsing tab
             if (!mSuggestionsEnabled && !suggestionsPrompted && mSuggestClient != null) {
                 showSuggestionsOptIn();
+            } else {
+                removeSuggestionsOptIn();
             }
+
         } catch (JSONException e) {
             Log.e(LOGTAG, "Error getting search engine JSON", e);
         }
 
         filterSuggestions();
     }
 
     private void updateSearchEngineBar() {
@@ -662,17 +668,22 @@ public class BrowserSearch extends HomeF
     public void onSearchBarClickListener(final SearchEngine searchEngine) {
         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM,
                 "searchenginebar");
 
         mSearchListener.onSearch(searchEngine, mSearchTerm);
     }
 
     private void maybeSetSuggestClient(final String suggestTemplate, final boolean isPrivate) {
-        if (mSuggestClient != null || isPrivate) {
+        if (isPrivate) {
+            mSuggestClient = null;
+            return;
+        }
+
+        if (mSuggestClient != null) {
             return;
         }
 
         mSuggestClient = sSuggestClientFactory.getSuggestClient(getActivity(), suggestTemplate, SUGGESTION_TIMEOUT, NETWORK_SUGGESTION_MAX);
     }
 
     private void showSuggestionsOptIn() {
         // Return if the ViewStub was already inflated - an inflated ViewStub is removed from the
@@ -711,16 +722,24 @@ public class BrowserSearch extends HomeF
             public void onFocusChange(View v, boolean hasFocus) {
                 if (hasFocus) {
                     yesButton.requestFocus();
                 }
             }
         });
     }
 
+    private void removeSuggestionsOptIn() {
+        if (mSuggestionsOptInPrompt == null) {
+            return;
+        }
+
+        mSuggestionsOptInPrompt.setVisibility(View.GONE);
+    }
+
     private void setSuggestionsEnabled(final boolean enabled) {
         // Clicking the yes/no buttons quickly can cause the click events be
         // queued before the listeners are removed above, so it's possible
         // setSuggestionsEnabled() can be called twice. mSuggestionsOptInPrompt
         // can be null if this happens (bug 828480).
         if (mSuggestionsOptInPrompt == null) {
             return;
         }