diff --git a/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsTask.java b/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsTask.java index 936b3fe..6b73567 100644 --- a/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsTask.java +++ b/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsTask.java @@ -36,7 +36,7 @@ abstract class BaseSuggestionsTask { static final int MAX_RESULTS = 5; private static final long INTERVAL_DAY = TimeUnit.DAYS.toMillis(1); - private static final String DEFAULT_LANGUAGE = "en"; + @NonNull private static final String DEFAULT_LANGUAGE = "en"; @Nullable private static String sLanguage; @NonNull private final SuggestionsResult mResultCallback; @NonNull private final Application mApplication; @@ -46,7 +46,7 @@ abstract class BaseSuggestionsTask { @NonNull private String mQuery; @NonNull - protected abstract String getQueryUrl(@NonNull String query, @NonNull String language); + protected abstract String createQueryUrl(@NonNull String query, @NonNull String language); protected abstract void parseResults(@NonNull FileInputStream inputStream, @NonNull List results) throws Exception; @@ -113,7 +113,7 @@ abstract class BaseSuggestionsTask { */ @NonNull private File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) { - String queryUrl = getQueryUrl(query, language); + String queryUrl = createQueryUrl(query, language); File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + SuggestionsAdapter.CACHE_FILE_TYPE); if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { return cacheFile; @@ -126,15 +126,15 @@ abstract class BaseSuggestionsTask { try { URL url = new URL(queryUrl); Request suggestionsRequest = new Request.Builder().url(url) - .addHeader("Accept-Encoding", "gzip") - .addHeader("Accept-Charset", getEncoding()) - .cacheControl(mCacheControl) - .build(); + .addHeader("Accept-Encoding", "gzip") + .addHeader("Accept-Charset", getEncoding()) + .cacheControl(mCacheControl) + .build(); Response suggestionsResponse = mHttpClient.newCall(suggestionsRequest).execute(); if (suggestionsResponse.code() >= HttpURLConnection.HTTP_MULT_CHOICE || - suggestionsResponse.code() < HttpURLConnection.HTTP_OK) { + suggestionsResponse.code() < HttpURLConnection.HTTP_OK) { Log.e(TAG, "Search API Responded with code: " + suggestionsResponse.code()); suggestionsResponse.body().close(); return cacheFile; @@ -171,8 +171,8 @@ abstract class BaseSuggestionsTask { @NonNull private static ConnectivityManager getConnectivityManager(@NonNull Context context) { return (ConnectivityManager) context - .getApplicationContext() - .getSystemService(Context.CONNECTIVITY_SERVICE); + .getApplicationContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); } } diff --git a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java b/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java index 7d4748d..4758404 100644 --- a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java +++ b/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java @@ -15,7 +15,7 @@ import acr.browser.lightning.utils.FileUtils; final class DuckSuggestionsTask extends BaseSuggestionsTask { - private static final String ENCODING = "UTF-8"; + @NonNull private static final String ENCODING = "UTF-8"; @NonNull private final String mSearchSubtitle; DuckSuggestionsTask(@NonNull String query, @@ -27,7 +27,7 @@ final class DuckSuggestionsTask extends BaseSuggestionsTask { @NonNull @Override - protected String getQueryUrl(@NonNull String query, @NonNull String language) { + protected String createQueryUrl(@NonNull String query, @NonNull String language) { return "https://duckduckgo.com/ac/?q=" + query; } diff --git a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java b/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java index f9db50e..2a4b91d 100644 --- a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java +++ b/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java @@ -17,7 +17,7 @@ import acr.browser.lightning.database.HistoryItem; class GoogleSuggestionsTask extends BaseSuggestionsTask { - private static final String ENCODING = "ISO-8859-1"; + @NonNull private static final String ENCODING = "ISO-8859-1"; @Nullable private static XmlPullParser sXpp; @NonNull private final String mSearchSubtitle; @@ -29,7 +29,7 @@ class GoogleSuggestionsTask extends BaseSuggestionsTask { } @NonNull - protected String getQueryUrl(@NonNull String query, @NonNull String language) { + protected String createQueryUrl(@NonNull String query, @NonNull String language) { return "https://suggestqueries.google.com/complete/search?output=toolbar&hl=" + language + "&q=" + query; }