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);
}
}
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));
}
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();
});
}
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());
}
}
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;
}
Aggregations