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