Search in sources :

Example 1 with Repository

use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.

the class RepositoryListFragment method updateHeaders.

private void updateHeaders(final List<Repository> repos) {
    HeaderFooterListAdapter<?> rootAdapter = getListAdapter();
    if (rootAdapter == null) {
        return;
    }
    DefaultRepositoryListAdapter adapter = (DefaultRepositoryListAdapter) rootAdapter.getWrappedAdapter();
    adapter.clearHeaders();
    if (repos.isEmpty()) {
        return;
    }
    // Add recent header if at least one recent repository
    Repository first = repos.get(0);
    if (recentRepos.contains(first)) {
        adapter.registerHeader(first, getString(R.string.recently_viewed));
    }
    // Advance past all recent repositories
    int index;
    Repository current = null;
    for (index = 0; index < repos.size(); index++) {
        Repository repository = repos.get(index);
        if (recentRepos.contains(repository.id())) {
            current = repository;
        } else {
            break;
        }
    }
    if (index >= repos.size()) {
        return;
    }
    if (current != null) {
        adapter.registerNoSeparator(current);
    }
    // Register header for first character
    current = repos.get(index);
    char start = Character.toLowerCase(current.name().charAt(0));
    adapter.registerHeader(current, Character.toString(start).toUpperCase(US));
    char previousHeader = start;
    for (index = index + 1; index < repos.size(); index++) {
        current = repos.get(index);
        char repoStart = Character.toLowerCase(current.name().charAt(0));
        if (repoStart <= start) {
            continue;
        }
        // character
        if (previousHeader != repoStart) {
            adapter.registerNoSeparator(repos.get(index - 1));
        }
        adapter.registerHeader(current, Character.toString(repoStart).toUpperCase(US));
        previousHeader = repoStart;
        start = repoStart++;
    }
    // Don't include separator for last element
    adapter.registerNoSeparator(repos.get(repos.size() - 1));
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository)

Example 2 with Repository

use of com.meisolsson.githubsdk.model.Repository 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 Repository

use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.

the class BranchFileViewActivity method onCreateLoader.

@Override
public Loader<CharSequence> onCreateLoader(int loader, Bundle args) {
    final String raw = args.getString(ARG_TEXT);
    final Repository repo = args.getParcelable(ARG_REPO);
    return new MarkdownLoader(this, repo, raw, imageGetter, false);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) MarkdownLoader(com.github.pockethub.android.ui.MarkdownLoader)

Example 4 with Repository

use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.

the class IssuesViewActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            Repository repository = repo;
            if (repository == null) {
                int position = pager.getCurrentItem();
                Repository repoId = repoIds.get(position);
                if (repoId != null) {
                    Issue issue = store.getIssue(repoId, issueNumbers[position]);
                    if (issue != null) {
                        repository = issue.repository();
                    }
                }
            }
            if (repository != null) {
                Intent intent = RepositoryViewActivity.createIntent(repository);
                intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Issue(com.meisolsson.githubsdk.model.Issue) Intent(android.content.Intent)

Example 5 with Repository

use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.

the class SearchRepositoryListFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    final Repository result = (Repository) l.getItemAtPosition(position);
    ServiceGenerator.createService(getContext(), RepositoryService.class).getRepository(result.owner().login(), result.name()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Repository>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Repository>(getActivity(), MessageFormat.format(getString(R.string.opening_repository), InfoUtils.createRepoId(result))) {

        @Override
        public void onSuccess(Repository repo) {
            super.onSuccess(repo);
            startActivity(RepositoryViewActivity.createIntent(repo));
        }
    });
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService)

Aggregations

Repository (com.meisolsson.githubsdk.model.Repository)68 User (com.meisolsson.githubsdk.model.User)18 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)9 Issue (com.meisolsson.githubsdk.model.Issue)9 Intent (android.content.Intent)8 View (android.view.View)8 TextView (android.widget.TextView)6 Bundle (android.os.Bundle)5 ImageView (android.widget.ImageView)5 LayoutInflater (android.view.LayoutInflater)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 Test (org.junit.Test)4 Uri (android.net.Uri)3 Menu (android.view.Menu)3 ViewGroup (android.view.ViewGroup)3 LinearLayout (android.widget.LinearLayout)3 R (com.gh4a.R)3 RepositoryActivity (com.gh4a.activities.RepositoryActivity)3 UserActivity (com.gh4a.activities.UserActivity)3 ApiHelpers (com.gh4a.utils.ApiHelpers)3