Search in sources :

Example 21 with GitHubEvent

use of com.meisolsson.githubsdk.model.GitHubEvent in project PocketHub by pockethub.

the class NewsEventTextTest method testWatch.

/**
 * Verify text of watch event
 */
@UiThreadTest
public void testWatch() {
    GitHubEvent event = createEvent(GitHubEventType.WatchEvent, null);
    updateView(event);
    verify("user starred user/repo");
}
Also used : GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) UiThreadTest(android.test.UiThreadTest)

Example 22 with GitHubEvent

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

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

the class EventListFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) item.getMenuInfo();
    if (info.position >= mAdapter.getItemCount()) {
        return false;
    }
    int id = item.getItemId();
    GitHubEvent event = mAdapter.getItemFromAdapterPosition(info.position);
    if (id >= MENU_DOWNLOAD_START && id <= MENU_DOWNLOAD_END) {
        if (event.type() == GitHubEventType.ReleaseEvent) {
            ReleasePayload payload = (ReleasePayload) event.payload();
            ReleaseAsset asset = payload.release().assets().get(id - MENU_DOWNLOAD_START);
            UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), asset.url(), asset.contentType(), asset.name(), asset.label(), null);
        } else if (event.type() == GitHubEventType.DownloadEvent) {
            DownloadPayload payload = (DownloadPayload) event.payload();
            Download download = payload.download();
            UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
        }
        return true;
    }
    return false;
}
Also used : ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) ReleaseAsset(com.meisolsson.githubsdk.model.ReleaseAsset) BaseActivity(com.gh4a.BaseActivity) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload) Download(com.meisolsson.githubsdk.model.Download) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView)

Example 24 with GitHubEvent

use of com.meisolsson.githubsdk.model.GitHubEvent in project PocketHub by pockethub.

the class IconAndViewTextManagerTest method when_event_type_is_follow_then_icon_should_be_follow_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_follow_then_icon_should_be_follow_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.FollowEvent).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatFollow(event, null, null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, null, null);
    // Assert
    assertEquals(TypefaceUtils.ICON_FOLLOW, icon);
    verify(spyIconAndViewTextManager).formatFollow(event, null, null);
}
Also used : GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Example 25 with GitHubEvent

use of com.meisolsson.githubsdk.model.GitHubEvent in project PocketHub by pockethub.

the class IconAndViewTextManagerTest method when_event_type_is_download_then_icon_should_be_upload_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_download_then_icon_should_be_upload_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.DownloadEvent).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatDownload(event, null, null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, null, null);
    // Assert
    assertEquals(TypefaceUtils.ICON_UPLOAD, icon);
    verify(spyIconAndViewTextManager).formatDownload(event, null, null);
}
Also used : GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Aggregations

GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)43 Test (org.junit.Test)18 UiThreadTest (android.test.UiThreadTest)15 Repository (com.meisolsson.githubsdk.model.Repository)9 User (com.meisolsson.githubsdk.model.User)8 IssuesPayload (com.meisolsson.githubsdk.model.payload.IssuesPayload)8 Issue (com.meisolsson.githubsdk.model.Issue)6 CreatePayload (com.meisolsson.githubsdk.model.payload.CreatePayload)5 FollowPayload (com.meisolsson.githubsdk.model.payload.FollowPayload)5 IssueCommentPayload (com.meisolsson.githubsdk.model.payload.IssueCommentPayload)5 PullRequestPayload (com.meisolsson.githubsdk.model.payload.PullRequestPayload)5 PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)5 CommitCommentPayload (com.meisolsson.githubsdk.model.payload.CommitCommentPayload)4 DownloadPayload (com.meisolsson.githubsdk.model.payload.DownloadPayload)4 ForkPayload (com.meisolsson.githubsdk.model.payload.ForkPayload)4 GistPayload (com.meisolsson.githubsdk.model.payload.GistPayload)4 GollumPayload (com.meisolsson.githubsdk.model.payload.GollumPayload)4 ReleasePayload (com.meisolsson.githubsdk.model.payload.ReleasePayload)4 List (java.util.List)4 View (android.view.View)3