Search in sources :

Example 6 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 7 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)

Example 8 with GitHubFile

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

the class CommitCommentLoadTask method load.

public static Single<Optional<Intent>> load(Context context, String repoOwner, String repoName, String commitSha, IntentUtils.InitialCommentMarker marker) {
    RepositoryCommitService commitService = ServiceFactory.get(RepositoryCommitService.class, false);
    RepositoryCommentService commentService = ServiceFactory.get(RepositoryCommentService.class, false);
    Single<Commit> commitSingle = commitService.getCommit(repoOwner, repoName, commitSha).map(ApiHelpers::throwOnFailure);
    Single<List<GitComment>> commentSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getCommitComments(repoOwner, repoName, commitSha, page)).cache();
    Single<Optional<GitHubFile>> fileSingle = commentSingle.compose(RxUtils.filterAndMapToFirst(c -> marker.matches(c.id(), c.createdAt()))).zipWith(commitSingle, (comment, commit) -> {
        if (comment.isPresent()) {
            for (GitHubFile commitFile : commit.files()) {
                if (commitFile.filename().equals(comment.get().path())) {
                    return Optional.of(commitFile);
                }
            }
        }
        return Optional.absent();
    });
    return Single.zip(commitSingle, commentSingle, fileSingle, (commit, comments, fileOpt) -> {
        GitHubFile file = fileOpt.orNull();
        if (file != null && !FileUtils.isImage(file.filename())) {
            return Optional.of(CommitDiffViewerActivity.makeIntent(context, repoOwner, repoName, commitSha, file.filename(), file.patch(), comments, -1, -1, false, marker));
        } else if (file == null) {
            return Optional.of(CommitActivity.makeIntent(context, repoOwner, repoName, commitSha, marker));
        }
        return Optional.absent();
    });
}
Also used : Context(android.content.Context) FileUtils(com.gh4a.utils.FileUtils) CommitDiffViewerActivity(com.gh4a.activities.CommitDiffViewerActivity) ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) Intent(android.content.Intent) Single(io.reactivex.Single) VisibleForTesting(android.support.annotation.VisibleForTesting) Commit(com.meisolsson.githubsdk.model.Commit) GitComment(com.meisolsson.githubsdk.model.git.GitComment) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) CommitActivity(com.gh4a.activities.CommitActivity) FragmentActivity(android.support.v4.app.FragmentActivity) Optional(com.gh4a.utils.Optional) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService) ServiceFactory(com.gh4a.ServiceFactory) IntentUtils(com.gh4a.utils.IntentUtils) Commit(com.meisolsson.githubsdk.model.Commit) Optional(com.gh4a.utils.Optional) ApiHelpers(com.gh4a.utils.ApiHelpers) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) List(java.util.List) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Example 9 with GitHubFile

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

the class CommitFileListAdapter method update.

@Override
protected void update(final int position, final Object item, final int type) {
    switch(type) {
        case TYPE_FILE_HEADER:
            GitHubFile file = (GitHubFile) item;
            String path = file.filename();
            int lastSlash = path.lastIndexOf('/');
            if (lastSlash != -1) {
                setText(0, path.substring(lastSlash + 1));
                ViewUtils.setGone(setText(1, path.substring(0, lastSlash + 1)), false);
            } else {
                setText(0, path);
                setGone(1, true);
            }
            StyledText stats = new StyledText();
            stats.foreground('+', addTextColor);
            stats.foreground(FORMAT_INT.format(file.additions()), addTextColor);
            stats.append(' ').append(' ').append(' ');
            stats.foreground('-', removeTextColor);
            stats.foreground(FORMAT_INT.format(file.deletions()), removeTextColor);
            setText(2, stats);
            return;
        case TYPE_FILE_LINE:
            CharSequence text = (CharSequence) item;
            diffStyler.updateColors((CharSequence) item, setText(0, text));
            return;
        case TYPE_LINE_COMMENT:
        case TYPE_COMMENT:
            GitComment comment = (GitComment) item;
            avatars.bind(imageView(1), comment.user());
            setText(2, comment.user().login());
            setText(3, TimeUtils.getRelativeTime(comment.updatedAt()));
            imageGetter.bind(textView(0), comment.bodyHtml(), comment.id());
    }
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 10 with GitHubFile

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

the class CommitUtils method formatStats.

/**
     * Format stats into {@link StyledText}
     *
     * @param files
     * @return styled text
     */
public static StyledText formatStats(final Collection<GitHubFile> files) {
    StyledText fileDetails = new StyledText();
    int added = 0;
    int deleted = 0;
    int changed = 0;
    if (files != null) {
        for (GitHubFile file : files) {
            added += file.additions();
            deleted += file.deletions();
            changed++;
        }
    }
    if (changed != 1) {
        fileDetails.append(FORMAT.format(changed)).append(" changed files");
    } else {
        fileDetails.append("1 changed file");
    }
    fileDetails.append(" with ");
    if (added != 1) {
        fileDetails.append(FORMAT.format(added)).append(" additions");
    } else {
        fileDetails.append("1 addition ");
    }
    fileDetails.append(" and ");
    if (deleted != 1) {
        fileDetails.append(FORMAT.format(deleted)).append(" deletions");
    } else {
        fileDetails.append("1 deletion");
    }
    return fileDetails;
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Aggregations

GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)19 Commit (com.meisolsson.githubsdk.model.Commit)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 FragmentActivity (android.support.v4.app.FragmentActivity)2 AlertDialog (android.support.v7.app.AlertDialog)2