Search in sources :

Example 1 with SearchService

use of com.meisolsson.githubsdk.service.search.SearchService in project PocketHub by pockethub.

the class SearchIssueListFragment method onCreateLoader.

@Override
public Loader<List<Issue>> onCreateLoader(int id, Bundle args) {
    return new ThrowableLoader<List<Issue>>(getActivity(), items) {

        @Override
        public List<Issue> loadData() throws Exception {
            if (repository == null) {
                return Collections.emptyList();
            }
            List<Issue> matches = new ArrayList<>();
            SearchService service = ServiceGenerator.createService(getActivity(), SearchService.class);
            int current = 1;
            int last = 0;
            while (current != last) {
                SearchPage<Issue> page = service.searchIssues(query, null, null, current).blockingGet();
                matches.addAll(page.items());
                last = page.last() != null ? page.last() : -1;
                current = page.next() != null ? page.next() : -1;
            }
            Collections.sort(matches, SearchIssueListFragment.this);
            return matches;
        }
    };
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) SearchService(com.meisolsson.githubsdk.service.search.SearchService) ArrayList(java.util.ArrayList) ThrowableLoader(com.github.pockethub.android.ThrowableLoader)

Aggregations

ThrowableLoader (com.github.pockethub.android.ThrowableLoader)1 Issue (com.meisolsson.githubsdk.model.Issue)1 SearchService (com.meisolsson.githubsdk.service.search.SearchService)1 ArrayList (java.util.ArrayList)1