use of com.github.pockethub.android.core.code.FullTree.Folder in project PocketHub by pockethub.
the class CodeTreeAdapter method update.
@Override
protected void update(final int position, final Object item, final int type) {
if (indented) {
updater.view.setPadding(indentedPaddingLeft, paddingTop, paddingRight, paddingBottom);
} else {
updater.view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
}
switch(type) {
case TYPE_BLOB:
Entry file = (Entry) item;
setText(0, file.name);
setText(1, Formatter.formatFileSize(context, file.entry.size()));
break;
case TYPE_TREE:
Folder folder = (Folder) item;
setText(0, CommitUtils.getName(folder.name));
setNumber(1, folder.folders.size());
setNumber(2, folder.files.size());
break;
}
}
use of com.github.pockethub.android.core.code.FullTree.Folder in project PocketHub by pockethub.
the class RepositoryCodeFragment method refreshTree.
private void refreshTree(final GitReference reference) {
showLoading(true);
Observable.create(new RefreshTreeTask(getActivity(), repository, reference)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<FullTree>bindToLifecycle()).subscribe(new ObserverAdapter<FullTree>() {
@Override
public void onNext(FullTree fullTree) {
if (folder == null || folder.parent == null) {
setFolder(fullTree, fullTree.root);
} else {
// Look for current folder in new tree or else reset to root
Folder current = folder;
LinkedList<Folder> stack = new LinkedList<>();
while (current.parent != null) {
stack.addFirst(current);
current = current.parent;
}
Folder refreshed = fullTree.root;
while (!stack.isEmpty()) {
refreshed = refreshed.folders.get(stack.removeFirst().name);
if (refreshed == null) {
break;
}
}
if (refreshed != null) {
setFolder(fullTree, refreshed);
} else {
setFolder(fullTree, fullTree.root);
}
}
}
@Override
public void onError(Throwable e) {
super.onError(e);
Log.d(TAG, "Exception loading tree", e);
showLoading(false);
ToastUtils.show(getActivity(), e, R.string.error_code_load);
}
});
}
use of com.github.pockethub.android.core.code.FullTree.Folder in project PocketHub by pockethub.
the class RepositoryCodeFragment method setFolder.
private void setFolder(final FullTree tree, final Folder folder) {
this.folder = folder;
this.tree = tree;
showLoading(false);
branchView.setText(tree.branch);
if (RefUtils.isTag(tree.reference)) {
branchIconView.setText(R.string.icon_tag);
} else {
branchIconView.setText(R.string.icon_fork);
}
adapter.getWrappedAdapter().setIndented(folder.entry != null);
if (folder.entry != null) {
int textLightColor = getResources().getColor(R.color.text_light);
final String[] segments = folder.entry.path().split("/");
StyledText text = new StyledText();
for (int i = 0; i < segments.length - 1; i++) {
final int index = i;
text.url(segments[i], new OnClickListener() {
@Override
public void onClick(View v) {
Folder clicked = folder;
for (int i = index; i < segments.length - 1; i++) {
clicked = clicked.parent;
if (clicked == null) {
return;
}
}
setFolder(tree, clicked);
}
}).append(' ').foreground('/', textLightColor).append(' ');
}
text.bold(segments[segments.length - 1]);
pathView.setText(text);
if (!pathShowing) {
adapter.addHeader(pathHeaderView);
pathShowing = true;
}
} else if (pathShowing) {
adapter.removeHeader(pathHeaderView);
pathShowing = false;
}
adapter.getWrappedAdapter().setItems(folder);
listView.setSelection(0);
}
Aggregations