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