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));
}
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;
}
};
}
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);
}
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);
}
}
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));
}
});
}
Aggregations