Search in sources :

Example 1 with FetchRecentUrlHistoryTask

use of com.odysee.app.tasks.localdata.FetchRecentUrlHistoryTask in project odysee-android by OdyseeTeam.

the class MainActivity method loadDefaultSuggestionsForBlankUrl.

private void loadDefaultSuggestionsForBlankUrl() {
    if (recentUrlHistory != null && recentUrlHistory.size() > 0) {
        urlSuggestionListAdapter.addUrlSuggestions(recentUrlHistory);
    }
    FetchRecentUrlHistoryTask task = new FetchRecentUrlHistoryTask(DatabaseHelper.getInstance(), new FetchRecentUrlHistoryTask.FetchRecentUrlHistoryHandler() {

        @Override
        public void onSuccess(List<UrlSuggestion> recentHistory) {
            List<UrlSuggestion> suggestions = new ArrayList<>(recentHistory);
            List<UrlSuggestion> lbrySuggestions = buildLbryUrlSuggestions();
            if (suggestions.size() < 10) {
                for (int i = suggestions.size(), j = 0; i < 10 && j < lbrySuggestions.size(); i++, j++) {
                    suggestions.add(lbrySuggestions.get(j));
                }
            } else if (suggestions.size() == 0) {
                suggestions.addAll(lbrySuggestions);
            }
            for (UrlSuggestion suggestion : suggestions) {
                suggestion.setUseTextAsDescription(true);
            }
            recentUrlHistory = new ArrayList<>(suggestions);
            urlSuggestionListAdapter.clear();
            urlSuggestionListAdapter.addUrlSuggestions(recentUrlHistory);
            List<String> urls = urlSuggestionListAdapter.getItemUrls();
            resolveUrlSuggestions(urls);
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FetchRecentUrlHistoryTask(com.odysee.app.tasks.localdata.FetchRecentUrlHistoryTask) UrlSuggestion(com.odysee.app.model.UrlSuggestion)

Aggregations

UrlSuggestion (com.odysee.app.model.UrlSuggestion)1 FetchRecentUrlHistoryTask (com.odysee.app.tasks.localdata.FetchRecentUrlHistoryTask)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1