Search in sources :

Example 1 with GitHubFile

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

the class CommitCompareListFragment method createFileSections.

private List<Section> createFileSections(List<GitHubFile> files) {
    List<Section> sections = new ArrayList<>();
    for (GitHubFile file : files) {
        Section section = new Section(new CommitFileHeaderItem(getActivity(), file));
        List<CharSequence> lines = diffStyler.get(file.filename());
        for (CharSequence line : lines) {
            section.add(new CommitFileLineItem(diffStyler, line));
        }
        sections.add(section);
    }
    return sections;
}
Also used : CommitFileHeaderItem(com.github.pockethub.android.ui.item.commit.CommitFileHeaderItem) CommitFileLineItem(com.github.pockethub.android.ui.item.commit.CommitFileLineItem) ArrayList(java.util.ArrayList) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) Section(com.xwray.groupie.Section)

Example 2 with GitHubFile

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

the class CommitCompareListFragment method updateList.

private void updateList(CommitCompare compare) {
    if (!isAdded()) {
        return;
    }
    this.compare = compare;
    progress.setVisibility(View.GONE);
    list.setVisibility(View.VISIBLE);
    List<Commit> commits = compare.commits();
    if (!commits.isEmpty()) {
        String comparingCommits = getString(R.string.comparing_commits);
        String text = MessageFormat.format(comparingCommits, commits.size());
        commitsSection.setHeader(new TextItem(R.layout.commit_details_header, R.id.tv_commit_summary, text));
        List<CommitItem> items = new ArrayList<>();
        for (Commit commit : commits) {
            items.add(new CommitItem(avatars, commit));
        }
        commitsSection.update(items);
    }
    List<GitHubFile> files = compare.files();
    if (!files.isEmpty()) {
        filesSection.setHeader(new TextItem(R.layout.commit_compare_file_details_header, R.id.tv_commit_file_summary, CommitUtils.formatStats(files)));
        filesSection.update(createFileSections(files));
    }
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) TextItem(com.github.pockethub.android.ui.item.TextItem) CommitItem(com.github.pockethub.android.ui.item.commit.CommitItem) ArrayList(java.util.ArrayList) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Example 3 with GitHubFile

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

the class CommitCompareListFragment method compareCommits.

private void compareCommits() {
    ServiceGenerator.createService(getActivity(), RepositoryCommitService.class).compareCommits(repository.owner().login(), repository.name(), base, head).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> {
        CommitCompare compareCommit = response.body();
        List<GitHubFile> files = compareCommit.files();
        diffStyler.setFiles(files);
        Collections.sort(files, new CommitFileComparator());
        updateList(compareCommit);
    }, error -> ToastUtils.show(getActivity(), R.string.error_commits_load));
}
Also used : GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) CommitCompare(com.meisolsson.githubsdk.model.CommitCompare) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Example 4 with GitHubFile

use of com.meisolsson.githubsdk.model.GitHubFile in project gh4a by slapperwan.

the class CommitFragment method onClick.

@Override
public void onClick(View v) {
    if (v.getId() == R.id.iv_gravatar) {
        Intent intent = UserActivity.makeIntent(getActivity(), (String) v.getTag());
        if (intent != null) {
            startActivity(intent);
        }
    } else {
        GitHubFile file = (GitHubFile) v.getTag();
        handleFileClick(file);
    }
}
Also used : GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) Intent(android.content.Intent)

Example 5 with GitHubFile

use of com.meisolsson.githubsdk.model.GitHubFile in project gh4a by slapperwan.

the class CommitFragment method fillStats.

protected void fillStats(List<GitHubFile> files, List<? extends PositionalCommentBase> comments) {
    LinearLayout llChanged = mContentView.findViewById(R.id.ll_changed);
    LinearLayout llAdded = mContentView.findViewById(R.id.ll_added);
    LinearLayout llRenamed = mContentView.findViewById(R.id.ll_renamed);
    LinearLayout llDeleted = mContentView.findViewById(R.id.ll_deleted);
    final LayoutInflater inflater = getLayoutInflater();
    int added = 0, changed = 0, renamed = 0, deleted = 0;
    int additions = 0, deletions = 0;
    int count = files != null ? files.size() : 0;
    int highlightColor = UiUtils.resolveColor(getActivity(), android.R.attr.textColorPrimary);
    ForegroundColorSpan addSpan = new ForegroundColorSpan(UiUtils.resolveColor(getActivity(), R.attr.colorCommitAddition));
    ForegroundColorSpan deleteSpan = new ForegroundColorSpan(UiUtils.resolveColor(getActivity(), R.attr.colorCommitDeletion));
    llChanged.removeAllViews();
    llAdded.removeAllViews();
    llRenamed.removeAllViews();
    llDeleted.removeAllViews();
    for (int i = 0; i < count; i++) {
        GitHubFile file = files.get(i);
        final LinearLayout parent;
        switch(file.status()) {
            case "added":
                parent = llAdded;
                added++;
                break;
            case "modified":
                parent = llChanged;
                changed++;
                break;
            case "renamed":
                parent = llRenamed;
                renamed++;
                break;
            case "removed":
                parent = llDeleted;
                deleted++;
                break;
            default:
                continue;
        }
        additions += file.additions();
        deletions += file.deletions();
        int commentCount = 0;
        for (PositionalCommentBase comment : comments) {
            if (TextUtils.equals(file.filename(), comment.path())) {
                commentCount++;
            }
        }
        ViewGroup fileView = (ViewGroup) inflater.inflate(R.layout.commit_filename, parent, false);
        TextView fileNameView = fileView.findViewById(R.id.filename);
        fileNameView.setText(file.filename());
        TextView statsView = fileView.findViewById(R.id.stats);
        if (file.patch() != null) {
            SpannableStringBuilder stats = new SpannableStringBuilder();
            stats.append("+").append(String.valueOf(file.additions()));
            int addLength = stats.length();
            stats.setSpan(addSpan, 0, addLength, 0);
            stats.append("\u00a0\u00a0\u00a0-").append(String.valueOf(file.deletions()));
            stats.setSpan(deleteSpan, addLength, stats.length(), 0);
            statsView.setText(stats);
            statsView.setVisibility(View.VISIBLE);
        } else {
            statsView.setVisibility(View.GONE);
        }
        if (file.patch() != null || (parent != llDeleted && FileUtils.isImage(file.filename()))) {
            fileNameView.setTextColor(highlightColor);
            fileView.setOnClickListener(this);
            fileView.setTag(file);
        }
        if (commentCount > 0) {
            TextView commentView = fileView.findViewById(R.id.comments);
            commentView.setText(String.valueOf(commentCount));
            commentView.setVisibility(View.VISIBLE);
        }
        parent.addView(fileView);
    }
    adjustVisibility(R.id.card_added, added);
    adjustVisibility(R.id.card_changed, changed);
    adjustVisibility(R.id.card_renamed, renamed);
    adjustVisibility(R.id.card_deleted, deleted);
    TextView tvSummary = mContentView.findViewById(R.id.tv_desc);
    tvSummary.setText(getString(R.string.commit_summary, added + changed + renamed + deleted, additions, deletions));
}
Also used : PositionalCommentBase(com.meisolsson.githubsdk.model.PositionalCommentBase) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) StyleableTextView(com.gh4a.widget.StyleableTextView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)19 SmallTest (androidx.test.filters.SmallTest)6 Commit (com.meisolsson.githubsdk.model.Commit)6 Test (org.junit.Test)6 Intent (android.content.Intent)5 GitComment (com.meisolsson.githubsdk.model.git.GitComment)5 ArrayList (java.util.ArrayList)5 ServiceFactory (com.gh4a.ServiceFactory)4 ApiHelpers (com.gh4a.utils.ApiHelpers)4 IntentUtils (com.gh4a.utils.IntentUtils)4 Optional (com.gh4a.utils.Optional)4 RxUtils (com.gh4a.utils.RxUtils)4 FullCommit (com.github.pockethub.android.core.commit.FullCommit)4 Single (io.reactivex.Single)4 List (java.util.List)4 ReviewComment (com.meisolsson.githubsdk.model.ReviewComment)3 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)3 PullRequestService (com.meisolsson.githubsdk.service.pull_request.PullRequestService)3 Bundle (android.os.Bundle)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2