Search in sources :

Example 1 with RefreshTreeTask

use of com.github.pockethub.android.core.code.RefreshTreeTask 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);
        }
    });
}
Also used : RefreshTreeTask(com.github.pockethub.android.core.code.RefreshTreeTask) Folder(com.github.pockethub.android.core.code.FullTree.Folder) FullTree(com.github.pockethub.android.core.code.FullTree) LinkedList(java.util.LinkedList)

Aggregations

FullTree (com.github.pockethub.android.core.code.FullTree)1 Folder (com.github.pockethub.android.core.code.FullTree.Folder)1 RefreshTreeTask (com.github.pockethub.android.core.code.RefreshTreeTask)1 LinkedList (java.util.LinkedList)1