Search in sources :

Example 1 with Folder

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;
    }
}
Also used : Entry(com.github.pockethub.android.core.code.FullTree.Entry) Folder(com.github.pockethub.android.core.code.FullTree.Folder)

Example 2 with Folder

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

Example 3 with Folder

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);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) OnClickListener(android.view.View.OnClickListener) Folder(com.github.pockethub.android.core.code.FullTree.Folder) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Aggregations

Folder (com.github.pockethub.android.core.code.FullTree.Folder)3 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 FullTree (com.github.pockethub.android.core.code.FullTree)1 Entry (com.github.pockethub.android.core.code.FullTree.Entry)1 RefreshTreeTask (com.github.pockethub.android.core.code.RefreshTreeTask)1 StyledText (com.github.pockethub.android.ui.StyledText)1 LinkedList (java.util.LinkedList)1