Browse Source

Move language initialization to constructor

master
Anthony Restaino 9 years ago
parent
commit
7354e354db
  1. 13
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

13
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -72,6 +72,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private final Drawable mSearchDrawable; private final Drawable mSearchDrawable;
private final Drawable mHistoryDrawable; private final Drawable mHistoryDrawable;
private final Drawable mBookmarkDrawable; private final Drawable mBookmarkDrawable;
private String mLanguage;
@Inject @Inject
HistoryDatabase mDatabaseHandler; HistoryDatabase mDatabaseHandler;
@ -96,6 +97,10 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme); mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
delete.setPriority(Thread.MIN_PRIORITY); delete.setPriority(Thread.MIN_PRIORITY);
delete.start(); delete.start();
mLanguage = Locale.getDefault().getLanguage();
if (mLanguage.isEmpty()) {
mLanguage = DEFAULT_LANGUAGE;
}
} }
private static void deleteOldCacheFiles() { private static void deleteOldCacheFiles() {
@ -303,7 +308,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
} }
File cache = downloadSuggestionsForQuery(query); File cache = downloadSuggestionsForQuery(query, mLanguage);
if (!cache.exists()) { if (!cache.exists()) {
return filter; return filter;
} }
@ -365,7 +370,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
* @param query the query to get suggestions for * @param query the query to get suggestions for
* @return the cache file containing the suggestions * @return the cache file containing the suggestions
*/ */
private static File downloadSuggestionsForQuery(String query) { private static File downloadSuggestionsForQuery(String query, String language) {
File cacheFile = new File(BrowserApp.getAppContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE); File cacheFile = new File(BrowserApp.getAppContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
return cacheFile; return cacheFile;
@ -375,10 +380,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
InputStream in = null; InputStream in = null;
FileOutputStream fos = null; FileOutputStream fos = null;
String language = Locale.getDefault().getLanguage();
if (language.isEmpty()) {
language = DEFAULT_LANGUAGE;
}
try { try {
// Old API that doesn't support HTTPS // Old API that doesn't support HTTPS
// http://google.com/complete/search?q= + query + &output=toolbar&hl= + language // http://google.com/complete/search?q= + query + &output=toolbar&hl= + language

Loading…
Cancel
Save