Search in sources :

Example 31 with GitHubEvent

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

the class IconAndViewTextManagerTest method when_event_type_is_fork_then_icon_should_be_fork_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_fork_then_icon_should_be_fork_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.ForkEvent).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatFork(event, new StyledText(), null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, new StyledText(), null);
    // Assert
    assertEquals(TypefaceUtils.ICON_FORK, icon);
    verify(spyIconAndViewTextManager).formatFork(event, new StyledText(), null);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Example 32 with GitHubEvent

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

the class IconAndViewTextManagerTest method when_event_type_is_pull_request_review_comment_then_icon_should_be_comment_and_its_text_should_be_formatted.

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

Example 33 with GitHubEvent

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

the class IconAndViewTextManagerTest method when_event_type_is_pull_request_then_icon_should_be_pull_request_and_its_text_should_be_formatted.

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

Example 34 with GitHubEvent

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

the class NewsFragment method onListItemLongClick.

@Override
public boolean onListItemLongClick(ListView l, View v, int position, long itemId) {
    if (!isUsable()) {
        return false;
    }
    final GitHubEvent event = (GitHubEvent) l.getItemAtPosition(position);
    final Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    final User user = event.actor();
    if (repo != null && user != null) {
        final MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.navigate_to);
        // Hacky but necessary since material dialogs has a different API
        final MaterialDialog[] dialogHolder = new MaterialDialog[1];
        View view = getActivity().getLayoutInflater().inflate(R.layout.nav_dialog, null);
        ViewFinder finder = new ViewFinder(view);
        avatars.bind(finder.imageView(R.id.iv_user_avatar), user);
        avatars.bind(finder.imageView(R.id.iv_repo_avatar), repo.owner());
        finder.setText(R.id.tv_login, user.login());
        finder.setText(R.id.tv_repo_name, InfoUtils.createRepoId(repo));
        finder.onClick(R.id.ll_user_area, new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogHolder[0].dismiss();
                viewUser(user);
            }
        });
        finder.onClick(R.id.ll_repo_area, new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogHolder[0].dismiss();
                viewRepository(repo);
            }
        });
        builder.customView(view, false);
        MaterialDialog dialog = builder.build();
        dialogHolder[0] = dialog;
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        return true;
    }
    return false;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ViewFinder(com.github.kevinsawicki.wishlist.ViewFinder) OnClickListener(android.view.View.OnClickListener) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) View(android.view.View) ListView(android.widget.ListView)

Example 35 with GitHubEvent

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

the class NewsFragment method onItemLongClick.

@Override
public boolean onItemLongClick(@NonNull Item item, @NonNull View view) {
    if (!isAdded()) {
        return false;
    }
    if (!(item instanceof NewsItem)) {
        return false;
    }
    final GitHubEvent event = ((NewsItem) item).getGitHubEvent();
    final Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    final User user = event.actor();
    if (repo != null && user != null) {
        final MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.navigate_to);
        // Hacky but necessary since material dialogs has a different API
        final MaterialDialog[] dialogHolder = new MaterialDialog[1];
        View dialogView = getActivity().getLayoutInflater().inflate(R.layout.nav_dialog, null);
        avatars.bind((ImageView) dialogView.findViewById(R.id.iv_user_avatar), user);
        avatars.bind((ImageView) dialogView.findViewById(R.id.iv_repo_avatar), repo.owner());
        ((TextView) dialogView.findViewById(R.id.tv_login)).setText(user.login());
        ((TextView) dialogView.findViewById(R.id.tv_repo_name)).setText(InfoUtils.createRepoId(repo));
        dialogView.findViewById(R.id.ll_user_area).setOnClickListener(v1 -> {
            dialogHolder[0].dismiss();
            viewUser(user);
        });
        dialogView.findViewById(R.id.ll_repo_area).setOnClickListener(v1 -> {
            dialogHolder[0].dismiss();
            viewRepository(repo);
        });
        builder.customView(dialogView, false);
        MaterialDialog dialog = builder.build();
        dialogHolder[0] = dialog;
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        return true;
    }
    return false;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TextView(android.widget.TextView) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) NewsItem(com.github.pockethub.android.ui.item.news.NewsItem)

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