From bde80682bda8a24c8c63869b1f0ffe8ea301a4be Mon Sep 17 00:00:00 2001 From: Prabhjyot Singh Sodhi Date: Fri, 13 Nov 2015 02:20:00 +0100 Subject: [PATCH] Bug 1207340 - Pref/Search Engine Suggestions UI can get out of sync. r=mcomella --- mobile/android/base/home/BrowserSearch.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/home/BrowserSearch.java b/mobile/android/base/home/BrowserSearch.java index 00f903891376..e9d87e3fe544 100644 --- a/mobile/android/base/home/BrowserSearch.java +++ b/mobile/android/base/home/BrowserSearch.java @@ -635,9 +635,15 @@ public class BrowserSearch extends HomeFragment // 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); } @@ -667,7 +673,12 @@ public class BrowserSearch extends HomeFragment } private void maybeSetSuggestClient(final String suggestTemplate, final boolean isPrivate) { - if (mSuggestClient != null || isPrivate) { + if (isPrivate) { + mSuggestClient = null; + return; + } + + if (mSuggestClient != null) { return; } @@ -716,6 +727,14 @@ public class BrowserSearch extends HomeFragment }); } + 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