Search in sources :

Example 1 with RepositoryItem

use of com.github.pockethub.android.ui.item.repository.RepositoryItem 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)

Example 2 with RepositoryItem

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

the class UserRepositoryListFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (item instanceof RepositoryItem) {
        Repository repo = ((RepositoryItem) item).getRepo();
        startActivityForResult(RepositoryViewActivity.createIntent(repo), REPOSITORY_VIEW);
    }
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository)

Example 3 with RepositoryItem

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

the class SearchRepositoryListFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (item instanceof RepositoryItem) {
        final Repository result = ((RepositoryItem) item).getRepo();
        ServiceGenerator.createService(getContext(), RepositoryService.class).getRepository(result.owner().login(), result.name()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(RxProgress.bindToLifecycle(getActivity(), MessageFormat.format(getString(R.string.opening_repository), InfoUtils.createRepoId(result)))).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> startActivity(RepositoryViewActivity.createIntent(response.body())));
    }
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository)

Example 4 with RepositoryItem

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

the class RepositoryListFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (item instanceof RepositoryItem) {
        Repository repo = ((RepositoryItem) item).getRepo();
        if (recentRepos != null) {
            recentRepos.add(repo);
        }
        startActivityForResult(RepositoryViewActivity.createIntent(repo), REPOSITORY_VIEW);
    }
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository)

Example 5 with RepositoryItem

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

the class RepositoryListFragment method onItemLongClick.

@Override
public boolean onItemLongClick(@NonNull Item item, @NonNull View view) {
    if (!isAdded()) {
        return false;
    }
    if (item instanceof RepositoryItem) {
        Repository repo = ((RepositoryItem) item).getRepo();
        if (repo == null) {
            return false;
        }
        MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(InfoUtils.createRepoId(repo));
        final MaterialDialog[] dialogHolder = new MaterialDialog[1];
        View dialogView = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
        final User owner = repo.owner();
        avatars.bind((ImageView) dialogView.findViewById(R.id.iv_owner_avatar), owner);
        ((TextView) dialogView.findViewById(R.id.tv_owner_name)).setText(getString(R.string.navigate_to_user, owner.login()));
        dialogView.findViewById(R.id.ll_owner_area).setOnClickListener(v1 -> {
            dialogHolder[0].dismiss();
            viewUser(owner);
        });
        if ((recentRepos != null) && (recentRepos.contains(repo))) {
            dialogView.findViewById(R.id.divider).setVisibility(View.VISIBLE);
            View recentRepoArea = dialogView.findViewById(R.id.ll_recent_repo_area);
            recentRepoArea.setVisibility(View.VISIBLE);
            recentRepoArea.setOnClickListener(v1 -> {
                dialogHolder[0].dismiss();
                recentRepos.remove(repo);
                refresh();
            });
        }
        builder.customView(dialogView, false);
        MaterialDialog dialog = builder.build();
        dialogHolder[0] = dialog;
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        return true;
    }
    return false;
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) User(com.meisolsson.githubsdk.model.User) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Aggregations

RepositoryItem (com.github.pockethub.android.ui.item.repository.RepositoryItem)5 Repository (com.meisolsson.githubsdk.model.Repository)5 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 RepositoryHeaderItem (com.github.pockethub.android.ui.item.repository.RepositoryHeaderItem)1 User (com.meisolsson.githubsdk.model.User)1 Item (com.xwray.groupie.Item)1