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