Browse Source

Making encoding a constructor parameter

master
anthony restaino 8 years ago
parent
commit
103eea9fcb
  1. 11
      app/src/main/java/acr/browser/lightning/search/BaseSuggestionsModel.java
  2. 8
      app/src/main/java/acr/browser/lightning/search/DuckSuggestionsModel.java
  3. 8
      app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsModel.java

11
app/src/main/java/acr/browser/lightning/search/BaseSuggestionsModel.java

@ -37,16 +37,15 @@ abstract class BaseSuggestionsModel { @@ -37,16 +37,15 @@ abstract class BaseSuggestionsModel {
@Nullable private static String sLanguage;
@NonNull private final OkHttpClient mHttpClient;
@NonNull private final CacheControl mCacheControl;
@NonNull private final String mEncoding;
@NonNull
protected abstract String createQueryUrl(@NonNull String query, @NonNull String language);
protected abstract void parseResults(@NonNull InputStream inputStream, @NonNull List<HistoryItem> results) throws Exception;
@NonNull
protected abstract String getEncoding();
BaseSuggestionsModel(@NonNull Application application) {
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
mEncoding = encoding;
File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
mHttpClient = new OkHttpClient.Builder()
.cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
@ -70,7 +69,7 @@ abstract class BaseSuggestionsModel { @@ -70,7 +69,7 @@ abstract class BaseSuggestionsModel {
List<HistoryItem> getResults(@NonNull String query) {
List<HistoryItem> filter = new ArrayList<>(5);
try {
query = URLEncoder.encode(query, getEncoding());
query = URLEncoder.encode(query, mEncoding);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unable to encode the URL", e);
}
@ -107,7 +106,7 @@ abstract class BaseSuggestionsModel { @@ -107,7 +106,7 @@ abstract class BaseSuggestionsModel {
// OkHttp automatically gzips requests
Request suggestionsRequest = new Request.Builder().url(url)
.addHeader("Accept-Charset", getEncoding())
.addHeader("Accept-Charset", mEncoding)
.cacheControl(mCacheControl)
.build();

8
app/src/main/java/acr/browser/lightning/search/DuckSuggestionsModel.java

@ -20,7 +20,7 @@ final class DuckSuggestionsModel extends BaseSuggestionsModel { @@ -20,7 +20,7 @@ final class DuckSuggestionsModel extends BaseSuggestionsModel {
@NonNull private final String mSearchSubtitle;
DuckSuggestionsModel(@NonNull Application application) {
super(application);
super(application, ENCODING);
mSearchSubtitle = application.getString(R.string.suggestion);
}
@ -47,10 +47,4 @@ final class DuckSuggestionsModel extends BaseSuggestionsModel { @@ -47,10 +47,4 @@ final class DuckSuggestionsModel extends BaseSuggestionsModel {
}
}
@NonNull
@Override
protected String getEncoding() {
return ENCODING;
}
}

8
app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsModel.java

@ -23,7 +23,7 @@ class GoogleSuggestionsModel extends BaseSuggestionsModel { @@ -23,7 +23,7 @@ class GoogleSuggestionsModel extends BaseSuggestionsModel {
@NonNull private final String mSearchSubtitle;
GoogleSuggestionsModel(@NonNull Application application) {
super(application);
super(application, ENCODING);
mSearchSubtitle = application.getString(R.string.suggestion);
}
@ -54,12 +54,6 @@ class GoogleSuggestionsModel extends BaseSuggestionsModel { @@ -54,12 +54,6 @@ class GoogleSuggestionsModel extends BaseSuggestionsModel {
}
}
@NonNull
@Override
protected String getEncoding() {
return ENCODING;
}
@NonNull
private static synchronized XmlPullParser getParser() throws XmlPullParserException {
if (sXpp == null) {

Loading…
Cancel
Save