Search in sources :

Example 41 with Repository

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

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

the class NewsFragment method openCommitComment.

private void openCommitComment(GitHubEvent event) {
    Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    if (repo == null) {
        return;
    }
    if (repo.name().contains("/")) {
        String[] repoId = repo.name().split("/");
        repo = InfoUtils.createRepoFromData(repoId[0], repoId[1]);
    }
    CommitCommentPayload payload = ((CommitCommentPayload) event.payload());
    GitComment comment = payload.comment();
    if (comment == null) {
        return;
    }
    String sha = comment.commitId();
    if (!TextUtils.isEmpty(sha)) {
        startActivity(CommitViewActivity.createIntent(repo, sha));
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) GitComment(com.meisolsson.githubsdk.model.git.GitComment) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload)

Example 43 with Repository

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

the class RenderedCommentFragment method onCreateLoader.

@Override
public Loader<CharSequence> onCreateLoader(int loader, Bundle args) {
    final CharSequence raw = args.getCharSequence(ARG_TEXT);
    final Repository repo = args.getParcelable(ARG_REPO);
    return new MarkdownLoader(getActivity(), repo, raw.toString(), imageGetter, true);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) MarkdownLoader(com.github.pockethub.android.ui.MarkdownLoader)

Example 44 with Repository

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

the class IssuesViewActivity method createIntent.

/**
 * Create an intent to show issues with an initial selected issue
 *
 * @param issues
 * @param position
 * @return intent
 */
public static Intent createIntent(Collection<? extends Issue> issues, int position) {
    final int count = issues.size();
    int[] numbers = new int[count];
    boolean[] pullRequests = new boolean[count];
    ArrayList<Repository> repos = new ArrayList<>(count);
    int index = 0;
    for (Issue issue : issues) {
        numbers[index] = issue.number();
        pullRequests[index] = IssueUtils.isPullRequest(issue);
        index++;
        Repository repoId = null;
        Repository issueRepo = issue.repository();
        if (issueRepo != null) {
            User owner = issueRepo.owner();
            if (owner != null) {
                repoId = InfoUtils.createRepoFromData(owner.login(), issueRepo.name());
            }
        }
        if (repoId == null) {
            repoId = InfoUtils.createRepoFromUrl(issue.htmlUrl());
        }
        repos.add(repoId);
    }
    Builder builder = new Builder("issues.VIEW");
    builder.add(EXTRA_ISSUE_NUMBERS, numbers);
    builder.add(EXTRA_REPOSITORIES, repos);
    builder.add(EXTRA_POSITION, position);
    builder.add(EXTRA_PULL_REQUESTS, pullRequests);
    return builder.toIntent();
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Issue(com.meisolsson.githubsdk.model.Issue) User(com.meisolsson.githubsdk.model.User) Builder(com.github.pockethub.android.Intents.Builder) ArrayList(java.util.ArrayList)

Example 45 with Repository

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

the class IssuesViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pager);
    issueNumbers = getIntArrayExtra(EXTRA_ISSUE_NUMBERS);
    pullRequests = getBooleanArrayExtra(EXTRA_PULL_REQUESTS);
    repoIds = getIntent().getParcelableArrayListExtra(EXTRA_REPOSITORIES);
    repo = getParcelableExtra(EXTRA_REPOSITORY);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    if (repo != null) {
        actionBar.setSubtitle(InfoUtils.createRepoId(repo));
        user = repo.owner();
        avatars.bind(actionBar, user);
    }
    // avatar URL
    if (repo == null) {
        Repository temp = repo != null ? repo : repoIds.get(0);
        ServiceGenerator.createService(this, RepositoryService.class).getRepository(temp.owner().login(), temp.name()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> repositoryLoaded(response.body()));
    } else {
        repositoryLoaded(repo);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) ActionBar(android.support.v7.app.ActionBar) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService)

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