Bug 1170824 - Hide search engine bar if no non-primary search engine is available. r=mcomella
authorSebastian Kaspari <s.kaspari@gmail.com>
Tue, 02 Jun 2015 17:19:58 -0700
changeset 248405 b7eecbd81f1b6067d9aedf417a0331ba1834a12c
parent 248404 7517bf3c8b5ceb4830c7955d9c34ed2fa72769f0
child 248406 32c21104e02c89d794e5c21dd493eb70c99fcf4f
push id28894
push userkwierso@gmail.com
push dateFri, 12 Jun 2015 00:30:17 +0000
treeherdermozilla-central@74ac345e777a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1170824
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170824 - Hide search engine bar if no non-primary search engine is available. r=mcomella
mobile/android/base/home/BrowserSearch.java
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -340,19 +340,17 @@ public class BrowserSearch extends HomeF
 
         registerForContextMenu(mList);
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
             "SearchEngines:Data");
 
         // If the view backed by this Fragment is being recreated, we will not receive
         // a new search engine data event so refresh the new search engine bar's data
         // & Views with the data we have.
-        mSearchEngineBar.setSearchEngines(
-                mSearchEngines.subList(getPrimaryEngineCount(), mSearchEngines.size())
-        );
+        updateSearchEngineBar();
         mSearchEngineBar.setOnSearchBarClickListener(this);
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
         // Initialize the search adapter
@@ -581,32 +579,43 @@ public class BrowserSearch extends HomeF
 
             mSearchEngines = Collections.unmodifiableList(searchEngines);
             mLastLocale = Locale.getDefault();
 
             if (mAdapter != null) {
                 mAdapter.notifyDataSetChanged();
             }
 
-            mSearchEngineBar.setSearchEngines(
-                    mSearchEngines.subList(getPrimaryEngineCount(), mSearchEngines.size())
-            );
+            updateSearchEngineBar();
 
             // 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.
             if (!mSuggestionsEnabled && !suggestionsPrompted && mSuggestClient != null) {
                 showSuggestionsOptIn();
             }
         } catch (JSONException e) {
             Log.e(LOGTAG, "Error getting search engine JSON", e);
         }
 
         filterSuggestions();
     }
 
+    private void updateSearchEngineBar() {
+        final int primaryEngineCount = getPrimaryEngineCount();
+
+        if (primaryEngineCount < mSearchEngines.size()) {
+            mSearchEngineBar.setSearchEngines(
+                    mSearchEngines.subList(primaryEngineCount, mSearchEngines.size())
+            );
+            mSearchEngineBar.setVisibility(View.VISIBLE);
+        } else {
+            mSearchEngineBar.setVisibility(View.GONE);
+        }
+    }
+
     @Override
     public void onSearchBarClickListener(final SearchEngine searchEngine) {
         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM,
                 "searchenginebar");
 
         mSearchListener.onSearch(searchEngine, mSearchTerm);
     }