|
|
@ -36,7 +36,7 @@ abstract class BaseSuggestionsTask { |
|
|
|
|
|
|
|
|
|
|
|
static final int MAX_RESULTS = 5; |
|
|
|
static final int MAX_RESULTS = 5; |
|
|
|
private static final long INTERVAL_DAY = TimeUnit.DAYS.toMillis(1); |
|
|
|
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; |
|
|
|
@Nullable private static String sLanguage; |
|
|
|
@NonNull private final SuggestionsResult mResultCallback; |
|
|
|
@NonNull private final SuggestionsResult mResultCallback; |
|
|
|
@NonNull private final Application mApplication; |
|
|
|
@NonNull private final Application mApplication; |
|
|
@ -46,7 +46,7 @@ abstract class BaseSuggestionsTask { |
|
|
|
@NonNull private String mQuery; |
|
|
|
@NonNull private String mQuery; |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@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<HistoryItem> results) throws Exception; |
|
|
|
protected abstract void parseResults(@NonNull FileInputStream inputStream, @NonNull List<HistoryItem> results) throws Exception; |
|
|
|
|
|
|
|
|
|
|
@ -113,7 +113,7 @@ abstract class BaseSuggestionsTask { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) { |
|
|
|
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); |
|
|
|
File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + SuggestionsAdapter.CACHE_FILE_TYPE); |
|
|
|
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { |
|
|
|
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { |
|
|
|
return cacheFile; |
|
|
|
return cacheFile; |
|
|
|