Search in sources :

Example 1 with ThrowableLoader

use of com.github.pockethub.android.ThrowableLoader in project PocketHub by pockethub.

the class RepositoryContributorsFragment method onCreateLoader.

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

        @Override
        public List<User> loadData() throws Exception {
            RepositoryService service = ServiceGenerator.createService(getActivity(), RepositoryService.class);
            int current = 1;
            int last = 0;
            List<User> users = new ArrayList<>();
            while (current != last) {
                Page<User> page = service.getContributors(repo.owner().login(), repo.name(), current).blockingGet();
                users.addAll(page.items());
                last = page.last() != null ? page.last() : -1;
                current = page.next() != null ? page.next() : -1;
            }
            return users;
        }
    };
}
Also used : User(com.meisolsson.githubsdk.model.User) ArrayList(java.util.ArrayList) ThrowableLoader(com.github.pockethub.android.ThrowableLoader) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService)

Example 2 with ThrowableLoader

use of com.github.pockethub.android.ThrowableLoader in project PocketHub by pockethub.

the class RepositoryListFragment method onCreateLoader.

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

        @Override
        public List<Repository> loadData() throws Exception {
            User org = RepositoryListFragment.this.org.get();
            if (org == null) {
                return Collections.emptyList();
            }
            List<Repository> repos = cache.getRepos(org, isForceRefresh(args));
            Collections.sort(repos, recentRepos);
            updateHeaders(repos);
            return repos;
        }
    };
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) ThrowableLoader(com.github.pockethub.android.ThrowableLoader)

Example 3 with ThrowableLoader

use of com.github.pockethub.android.ThrowableLoader 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)

Example 4 with ThrowableLoader

use of com.github.pockethub.android.ThrowableLoader in project PocketHub by pockethub.

the class MembersFragment method onCreateLoader.

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

        @Override
        public List<User> loadData() throws Exception {
            OrganizationMemberService service = ServiceGenerator.createService(getContext(), OrganizationMemberService.class);
            int current = 1;
            int last = -1;
            List<User> users = new ArrayList<>();
            while (current != last) {
                Page<User> page = service.getMembers(org.login(), current).blockingGet();
                users.addAll(page.items());
                last = page.last() != null ? page.last() : -1;
                current = page.next() != null ? page.next() : -1;
            }
            return users;
        }
    };
}
Also used : OrganizationMemberService(com.meisolsson.githubsdk.service.organizations.OrganizationMemberService) User(com.meisolsson.githubsdk.model.User) ArrayList(java.util.ArrayList) ThrowableLoader(com.github.pockethub.android.ThrowableLoader)

Aggregations

ThrowableLoader (com.github.pockethub.android.ThrowableLoader)4 User (com.meisolsson.githubsdk.model.User)3 ArrayList (java.util.ArrayList)3 Issue (com.meisolsson.githubsdk.model.Issue)1 Repository (com.meisolsson.githubsdk.model.Repository)1 OrganizationMemberService (com.meisolsson.githubsdk.service.organizations.OrganizationMemberService)1 RepositoryService (com.meisolsson.githubsdk.service.repositories.RepositoryService)1 SearchService (com.meisolsson.githubsdk.service.search.SearchService)1