Search in sources :

Example 46 with Repository

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

the class RepositoryListFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (item instanceof RepositoryItem) {
        Repository repo = ((RepositoryItem) item).getRepo();
        if (recentRepos != null) {
            recentRepos.add(repo);
        }
        startActivityForResult(RepositoryViewActivity.createIntent(repo), REPOSITORY_VIEW);
    }
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository)

Example 47 with Repository

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

the class RepositoryListFragment method onItemLongClick.

@Override
public boolean onItemLongClick(@NonNull Item item, @NonNull View view) {
    if (!isAdded()) {
        return false;
    }
    if (item instanceof RepositoryItem) {
        Repository repo = ((RepositoryItem) item).getRepo();
        if (repo == null) {
            return false;
        }
        MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(InfoUtils.createRepoId(repo));
        final MaterialDialog[] dialogHolder = new MaterialDialog[1];
        View dialogView = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
        final User owner = repo.owner();
        avatars.bind((ImageView) dialogView.findViewById(R.id.iv_owner_avatar), owner);
        ((TextView) dialogView.findViewById(R.id.tv_owner_name)).setText(getString(R.string.navigate_to_user, owner.login()));
        dialogView.findViewById(R.id.ll_owner_area).setOnClickListener(v1 -> {
            dialogHolder[0].dismiss();
            viewUser(owner);
        });
        if ((recentRepos != null) && (recentRepos.contains(repo))) {
            dialogView.findViewById(R.id.divider).setVisibility(View.VISIBLE);
            View recentRepoArea = dialogView.findViewById(R.id.ll_recent_repo_area);
            recentRepoArea.setVisibility(View.VISIBLE);
            recentRepoArea.setOnClickListener(v1 -> {
                dialogHolder[0].dismiss();
                recentRepos.remove(repo);
                refresh();
            });
        }
        builder.customView(dialogView, false);
        MaterialDialog dialog = builder.build();
        dialogHolder[0] = dialog;
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        return true;
    }
    return false;
}
Also used : RepositoryItem(com.github.pockethub.android.ui.item.repository.RepositoryItem) Repository(com.meisolsson.githubsdk.model.Repository) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) User(com.meisolsson.githubsdk.model.User) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 48 with Repository

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

the class RepositoryViewActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.m_star:
            starRepository();
            return true;
        case R.id.m_fork:
            forkRepository();
            return true;
        case R.id.m_contributors:
            startActivity(RepositoryContributorsActivity.createIntent(repository));
            return true;
        case R.id.m_share:
            shareRepository();
            return true;
        case R.id.m_parent_repo:
            if (repository.parent() == null) {
                ServiceGenerator.createService(this, RepositoryService.class).getRepository(repository.owner().login(), repository.name()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
                    Repository parent = response.body().parent();
                    startActivity(RepositoryViewActivity.createIntent(parent));
                });
            } else {
                startActivity(RepositoryViewActivity.createIntent(repository.parent()));
            }
            return true;
        case R.id.m_delete:
            deleteRepository();
            return true;
        case R.id.m_refresh:
            checkStarredRepositoryStatus();
            return super.onOptionsItemSelected(item);
        case android.R.id.home:
            finish();
            Intent intent = UserViewActivity.createIntent(repository.owner());
            intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Intent(android.content.Intent)

Example 49 with Repository

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

the class NewsFragment method openPush.

private void openPush(GitHubEvent event) {
    Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    if (repo == null) {
        return;
    }
    PushPayload payload = ((PushPayload) event.payload());
    List<GitCommit> commits = payload.commits();
    if (commits.isEmpty()) {
        return;
    }
    if (commits.size() > 1) {
        String base = payload.before();
        String head = payload.head();
        if (!TextUtils.isEmpty(base) && !TextUtils.isEmpty(head)) {
            startActivity(CommitCompareViewActivity.createIntent(repo, base, head));
        }
    } else {
        GitCommit commit = commits.get(0);
        String sha = commit != null ? commit.sha() : null;
        if (!TextUtils.isEmpty(sha)) {
            startActivity(CommitViewActivity.createIntent(repo, sha));
        }
    }
}
Also used : PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) Repository(com.meisolsson.githubsdk.model.Repository) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit)

Example 50 with Repository

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

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