Bug 1269481 - Update suggestClient if suggestTemplate changes r?mkaply
MozReview-Commit-ID: LmsgSFda6Nv
--- a/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java
@@ -52,16 +52,20 @@ public class SuggestClient {
public SuggestClient(Context context, String suggestTemplate, int timeout, int maxResults, boolean checkNetwork) {
mContext = context;
mMaxResults = maxResults;
mSuggestTemplate = suggestTemplate;
mTimeout = timeout;
mCheckNetwork = checkNetwork;
}
+ public String getSuggestTemplate() {
+ return mSuggestTemplate;
+ }
+
/**
* Queries for a given search term and returns an ArrayList of suggestions.
*/
public ArrayList<String> query(String query) {
if (query.equals(mPrevQuery))
return mPrevResults;
ArrayList<String> suggestions = new ArrayList<String>();
--- a/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
@@ -731,17 +731,18 @@ 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 ensureSuggestClientIsSet(final String suggestTemplate) {
- if (mSuggestClient != null) {
+ // Don't update the suggestClient if we already have a client with the correct template
+ if (mSuggestClient != null && suggestTemplate.equals(mSuggestClient.getSuggestTemplate())) {
return;
}
mSuggestClient = sSuggestClientFactory.getSuggestClient(getActivity(), suggestTemplate, SUGGESTION_TIMEOUT, NETWORK_SUGGESTION_MAX);
}
private void showSuggestionsOptIn() {
// Only make the ViewStub visible again if it has already previously been shown.