Search in sources :

Example 16 with Repository

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

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class EventListFragment method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) menuInfo;
    GitHubEvent event = mAdapter.getItemFromAdapterPosition(info.position);
    if (EventAdapter.hasInvalidPayload(event)) {
        return;
    }
    GitHubEvent.RepoIdentifier eventRepo = event.repo();
    String[] repoNamePart = eventRepo.repoWithUserName().split("/");
    String repoOwner = repoNamePart.length == 2 ? repoNamePart[0] : null;
    String repoName = repoNamePart.length == 2 ? repoNamePart[1] : null;
    menu.setHeaderTitle(R.string.go_to);
    /* Common menu */
    menu.add(getString(R.string.menu_user, event.actor().login())).setIntent(UserActivity.makeIntent(getActivity(), event.actor()));
    if (repoOwner != null) {
        menu.add(getString(R.string.menu_repo, repoOwner + "/" + repoName)).setIntent(RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName));
    }
    switch(event.type()) {
        case CommitCommentEvent:
            if (repoOwner != null) {
                CommitCommentPayload payload = (CommitCommentPayload) event.payload();
                String sha = payload.comment().commitId();
                menu.add(getString(R.string.menu_commit, sha.substring(0, 7))).setIntent(CommitActivity.makeIntent(getActivity(), repoOwner, repoName, sha));
            }
            break;
        case DownloadEvent:
            {
                DownloadPayload payload = (DownloadPayload) event.payload();
                menu.add(Menu.NONE, MENU_DOWNLOAD_START, Menu.NONE, getString(R.string.menu_file, payload.download().name()));
                break;
            }
        case FollowEvent:
            {
                FollowPayload payload = (FollowPayload) event.payload();
                User target = payload.target();
                if (target != null) {
                    menu.add(getString(R.string.menu_user, target.login())).setIntent(UserActivity.makeIntent(getActivity(), target));
                }
                break;
            }
        case ForkEvent:
            {
                ForkPayload payload = (ForkPayload) event.payload();
                Repository forkee = payload.forkee();
                if (forkee != null) {
                    menu.add(getString(R.string.menu_fork, forkee.owner().login() + "/" + forkee.name())).setIntent(RepositoryActivity.makeIntent(getActivity(), forkee));
                }
                break;
            }
        case GistEvent:
            {
                GistPayload payload = (GistPayload) event.payload();
                String gistId = payload.gist().id();
                menu.add(getString(R.string.menu_gist, gistId)).setIntent(GistActivity.makeIntent(getActivity(), gistId));
                break;
            }
        case GollumEvent:
            {
                GollumPayload payload = (GollumPayload) event.payload();
                List<GitHubWikiPage> pages = payload.pages();
                if (pages != null && !pages.isEmpty()) {
                    // TODO: now just open the first page
                    menu.add(getString(R.string.menu_wiki)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(pages.get(0).htmlUrl())));
                }
                break;
            }
        case IssueCommentEvent:
            {
                IssueCommentPayload payload = (IssueCommentPayload) event.payload();
                boolean isPullRequest = payload.issue().pullRequest() != null;
                menu.add(getString(isPullRequest ? R.string.menu_pulls : R.string.menu_issues)).setIntent(IssueListActivity.makeIntent(getActivity(), repoOwner, repoName, isPullRequest));
                break;
            }
        case IssuesEvent:
            {
                IssuesPayload payload = (IssuesPayload) event.payload();
                int issueNumber = payload.issue().number();
                menu.add(getString(R.string.menu_issue, issueNumber)).setIntent(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issueNumber));
                break;
            }
        case PullRequestEvent:
            {
                PullRequestPayload payload = (PullRequestPayload) event.payload();
                menu.add(getString(R.string.menu_pull, payload.number())).setIntent(PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number()));
                break;
            }
        case PushEvent:
            {
                if (repoOwner != null) {
                    PushPayload payload = (PushPayload) event.payload();
                    menu.add(getString(R.string.menu_compare, payload.head().substring(0, 7))).setIntent(CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head()));
                    for (GitCommit commit : payload.commits()) {
                        String sha = commit.sha();
                        menu.add(getString(R.string.menu_commit, sha.substring(0, 7))).setIntent(CommitActivity.makeIntent(getActivity(), repoOwner, repoName, sha));
                    }
                }
                break;
            }
        case ReleaseEvent:
            {
                ReleasePayload payload = (ReleasePayload) event.payload();
                List<ReleaseAsset> downloads = payload.release().assets();
                int count = downloads != null ? downloads.size() : 0;
                for (int i = 0; i < count; i++) {
                    menu.add(Menu.NONE, MENU_DOWNLOAD_START + i, Menu.NONE, getString(R.string.menu_file, downloads.get(i).name()));
                }
                break;
            }
    }
}
Also used : ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) User(com.meisolsson.githubsdk.model.User) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) Intent(android.content.Intent) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) Repository(com.meisolsson.githubsdk.model.Repository) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) List(java.util.List) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload)

Example 18 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class RepositoryFragment method onClick.

@Override
public void onClick(View view) {
    int id = view.getId();
    if (id == R.id.readme_title) {
        toggleReadmeExpanded();
        return;
    }
    String owner = mRepository.owner().login();
    String name = mRepository.name();
    Intent intent = null;
    if (id == R.id.cell_pull_requests) {
        intent = IssueListActivity.makeIntent(getActivity(), owner, name, true);
    } else if (id == R.id.tv_contributors_label) {
        intent = ContributorListActivity.makeIntent(getActivity(), owner, name);
    } else if (id == R.id.tv_collaborators_label) {
        intent = CollaboratorListActivity.makeIntent(getActivity(), owner, name);
    } else if (id == R.id.cell_issues) {
        intent = IssueListActivity.makeIntent(getActivity(), owner, name);
    } else if (id == R.id.cell_stargazers) {
        intent = WatcherListActivity.makeIntent(getActivity(), owner, name);
    } else if (id == R.id.cell_forks) {
        intent = ForkListActivity.makeIntent(getActivity(), owner, name);
    } else if (id == R.id.tv_wiki_label) {
        intent = WikiListActivity.makeIntent(getActivity(), owner, name, null);
    } else if (id == R.id.tv_releases_label) {
        intent = ReleaseListActivity.makeIntent(getActivity(), owner, name);
    } else if (view.getTag() instanceof Repository) {
        intent = RepositoryActivity.makeIntent(getActivity(), (Repository) view.getTag());
    }
    if (intent != null) {
        startActivity(intent);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Intent(android.content.Intent)

Example 19 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class UserFragment method fillTopRepos.

private void fillTopRepos(Collection<Repository> topRepos) {
    View progress = mContentView.findViewById(R.id.pb_top_repos);
    LinearLayout ll = mContentView.findViewById(R.id.ll_top_repos);
    ll.removeAllViews();
    LayoutInflater inflater = getLayoutInflater();
    if (topRepos != null) {
        for (Repository repo : topRepos) {
            View rowView = inflater.inflate(R.layout.top_repo, null);
            rowView.setOnClickListener(this);
            rowView.setTag(repo);
            TextView tvTitle = rowView.findViewById(R.id.tv_title);
            tvTitle.setText(repo.owner().login() + "/" + repo.name());
            TextView tvDesc = rowView.findViewById(R.id.tv_desc);
            if (!StringUtils.isBlank(repo.description())) {
                tvDesc.setVisibility(View.VISIBLE);
                tvDesc.setText(repo.description());
            } else {
                tvDesc.setVisibility(View.GONE);
            }
            TextView tvForks = rowView.findViewById(R.id.tv_forks);
            tvForks.setText(String.valueOf(repo.forksCount()));
            TextView tvStars = rowView.findViewById(R.id.tv_stars);
            tvStars.setText(String.valueOf(repo.watchersCount()));
            ll.addView(rowView);
        }
    }
    View btnMore = getView().findViewById(R.id.btn_repos);
    if (topRepos != null && !topRepos.isEmpty()) {
        btnMore.setOnClickListener(this);
        btnMore.setVisibility(View.VISIBLE);
    } else {
        TextView hintView = (TextView) inflater.inflate(R.layout.hint_view, ll, false);
        hintView.setText(R.string.user_no_repos);
        ll.addView(hintView);
    }
    ll.setVisibility(View.VISIBLE);
    progress.setVisibility(View.GONE);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 20 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class NotificationListFragment method markAsRead.

@Override
public void markAsRead(NotificationHolder notificationHolder) {
    if (notificationHolder.notification == null) {
        final Repository repository = notificationHolder.repository;
        String login = ApiHelpers.getUserLogin(getActivity(), repository.owner());
        String title = getString(R.string.mark_repository_as_read_question, login + "/" + repository.name());
        new AlertDialog.Builder(getActivity()).setMessage(title).setPositiveButton(R.string.mark_as_read, (dialog, which) -> markAsRead(repository, null)).setNegativeButton(R.string.cancel, null).show();
    } else {
        markAsRead(null, notificationHolder.notification);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository)

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