use of com.github.pockethub.android.core.code.FullTree 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);
}
});
}
Aggregations