Search in sources :

Example 1 with NewsItem

use of com.github.pockethub.android.ui.item.news.NewsItem in project PocketHub by pockethub.

the class NewsFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (!(item instanceof NewsItem)) {
        return;
    }
    GitHubEvent event = ((NewsItem) item).getGitHubEvent();
    if (DownloadEvent.equals(event.type())) {
        openDownload(event);
        return;
    }
    if (PushEvent.equals(event.type())) {
        openPush(event);
        return;
    }
    if (CommitCommentEvent.equals(event.type())) {
        openCommitComment(event);
        return;
    }
    Issue issue = IssueEventMatcher.getIssue(event);
    if (issue != null) {
        Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
        viewIssue(issue, repo);
        return;
    }
    Gist gist = GistEventMatcher.getGist(event);
    if (gist != null) {
        startActivity(GistsViewActivity.createIntent(gist));
        return;
    }
    Repository repo = RepositoryEventMatcher.getRepository(event);
    if (repo != null) {
        viewRepository(repo);
    }
    UserPair users = UserEventMatcher.getUsers(event);
    if (users != null) {
        viewUser(users);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Gist(com.meisolsson.githubsdk.model.Gist) Issue(com.meisolsson.githubsdk.model.Issue) UserPair(com.github.pockethub.android.core.user.UserEventMatcher.UserPair) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) NewsItem(com.github.pockethub.android.ui.item.news.NewsItem)

Example 2 with NewsItem

use of com.github.pockethub.android.ui.item.news.NewsItem in project PocketHub by pockethub.

the class NewsEventTextTest method updateView.

private void updateView(GitHubEvent event) {
    NewsItem item = NewsItem.createNewsItem(avatarLoader, event);
    View itemView = layoutInflater.inflate(item.getLayout(), null);
    ViewHolder viewHolder = item.createViewHolder(itemView);
    item.bind((com.xwray.groupie.kotlinandroidextensions.ViewHolder) viewHolder, 0);
    text = viewHolder.itemView.findViewById(R.id.tv_event);
    assertNotNull(text);
}
Also used : ViewHolder(com.xwray.groupie.ViewHolder) TextView(android.widget.TextView) View(android.view.View) NewsItem(com.github.pockethub.android.ui.item.news.NewsItem)

Example 3 with NewsItem

use of com.github.pockethub.android.ui.item.news.NewsItem 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

NewsItem (com.github.pockethub.android.ui.item.news.NewsItem)3 View (android.view.View)2 TextView (android.widget.TextView)2 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)2 Repository (com.meisolsson.githubsdk.model.Repository)2 ImageView (android.widget.ImageView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 UserPair (com.github.pockethub.android.core.user.UserEventMatcher.UserPair)1 Gist (com.meisolsson.githubsdk.model.Gist)1 Issue (com.meisolsson.githubsdk.model.Issue)1 User (com.meisolsson.githubsdk.model.User)1 ViewHolder (com.xwray.groupie.ViewHolder)1