Search in sources :

Example 1 with RepositoryHeaderItem

use of com.github.pockethub.android.ui.item.repository.RepositoryHeaderItem in project PocketHub by pockethub.

the class RepositoryListFragment method updateHeaders.

private void updateHeaders(final List<Item> repos) {
    if (repos.isEmpty()) {
        return;
    }
    // Add recent header if at least one recent repository
    Repository first = ((RepositoryItem) repos.get(0)).getRepo();
    if (recentRepos.contains(first)) {
        repos.add(0, new RepositoryHeaderItem(getString(R.string.recently_viewed)));
    }
    // Advance past all recent repositories
    int index;
    for (index = 0; index < repos.size(); index++) {
        Item item = repos.get(index);
        if (item instanceof RepositoryItem) {
            Repository repository = ((RepositoryItem) item).getRepo();
            if (!recentRepos.contains(repository.id())) {
                break;
            }
        }
    }
    if (index >= repos.size()) {
        return;
    }
    // Register header for first character
    Repository current = ((RepositoryItem) repos.get(index)).getRepo();
    char start = Character.toLowerCase(current.name().charAt(0));
    repos.add(index, new RepositoryHeaderItem(Character.toString(start).toUpperCase(US)));
    for (index = index + 1; index < repos.size(); index++) {
        current = ((RepositoryItem) repos.get(index)).getRepo();
        char repoStart = Character.toLowerCase(current.name().charAt(0));
        if (repoStart <= start) {
            continue;
        }
        repos.add(index, new RepositoryHeaderItem(Character.toString(repoStart).toUpperCase(US)));
        start = repoStart;
    }
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Item(com.xwray.groupie.Item) RepositoryHeaderItem(com.github.pockethub.android.ui.item.repository.RepositoryHeaderItem) Repository(com.meisolsson.githubsdk.model.Repository) RepositoryHeaderItem(com.github.pockethub.android.ui.item.repository.RepositoryHeaderItem)

Aggregations

RepositoryHeaderItem (com.github.pockethub.android.ui.item.repository.RepositoryHeaderItem)1 RepositoryItem (com.github.pockethub.android.ui.item.repository.RepositoryItem)1 Repository (com.meisolsson.githubsdk.model.Repository)1 Item (com.xwray.groupie.Item)1