Search in sources :

Example 1 with TreeEntry

use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.

the class MainFragment method clickWhenActionItem.

private boolean clickWhenActionItem(MenuItem item, Context context) {
    BAction action = new BAction(context);
    try {
        action.openDatabase(true);
    } catch (SQLException s) {
        SuperToast.create(context, getString(R.string.content_database_error), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
        return false;
    }
    SparseBooleanArray array = listView.getCheckedItemPositions();
    switch(item.getItemId()) {
        case R.id.content_choice_add:
            for (int i = 0; i < array.size(); i++) {
                if (array.valueAt(i)) {
                    ContentItem c = contentItemAdapter.getItem(array.keyAt(i));
                    TreeEntry e = c.getEntry();
                    if (!action.checkBookmark(e.getSha())) {
                        Bookmark b = new Bookmark();
                        String[] arr = e.getPath().split("/");
                        b.setTitle(arr[arr.length - 1]);
                        b.setType(e.getType());
                        b.setOwner(owner);
                        b.setName(name);
                        if (toggle) {
                            if (prefix.equals("/")) {
                                b.setPath(e.getPath());
                            } else {
                                b.setPath(prefix + "/" + e.getPath());
                            }
                        } else {
                            b.setPath(e.getPath());
                        }
                        b.setSha(e.getSha());
                        b.setKey(owner + "/" + name);
                        action.addBookmark(b);
                    }
                    listView.setItemChecked(i, false);
                }
            }
            SuperToast.create(context, getString(R.string.content_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
            break;
        case R.id.bookmark_choice_remove:
            for (int i = 0; i < array.size(); i++) {
                if (array.valueAt(i)) {
                    BookmarkItem b = bookmarkItemAdapter.getItem(array.keyAt(i));
                    action.unMarkBySha(b.getSha());
                    listView.setItemChecked(i, false);
                }
            }
            SuperToast.create(context, getString(R.string.bookmark_remove_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
            bookmarkTask = new BookmarkTask(MainFragment.this);
            bookmarkTask.execute();
            break;
        default:
            break;
    }
    action.closeDatabase();
    return true;
}
Also used : BookmarkTask(io.github.mthli.Bitocle.Bookmark.BookmarkTask) Bookmark(io.github.mthli.Bitocle.Database.Bookmark.Bookmark) SQLException(android.database.SQLException) BAction(io.github.mthli.Bitocle.Database.Bookmark.BAction) SparseBooleanArray(android.util.SparseBooleanArray) TreeEntry(org.eclipse.egit.github.core.TreeEntry) BookmarkItem(io.github.mthli.Bitocle.Bookmark.BookmarkItem) ContentItem(io.github.mthli.Bitocle.Content.ContentItem)

Example 2 with TreeEntry

use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.

the class MainFragment method clickWhenStarContent.

private void clickWhenStarContent(int position) {
    allTaskDown();
    ContentItem item = contentItemList.get(position);
    if (item.getEntry().getType().equals("tree")) {
        entry = item.getEntry();
        String[] arr = entry.getPath().split("/");
        title = arr[arr.length - 1];
        if (toggle) {
            if (prefix.equals("/")) {
                subTitle = name + "/" + entry.getPath();
            } else {
                subTitle = name + "/" + prefix + "/" + entry.getPath();
            }
        } else {
            subTitle = name + "/" + entry.getPath();
        }
        actionBar.setTitle(title);
        actionBar.setSubtitle(subTitle);
        actionBar.setDisplayHomeAsUpEnabled(true);
        flag = Flag.STAR_CONTENT_SECOND;
        currentId = STAR_CONTENT_ID;
        starContentTask = new StarContentTask(MainFragment.this);
        starContentTask.execute();
    } else {
        TreeEntry e = item.getEntry();
        String[] a = e.getPath().split("/");
        String t = a[a.length - 1];
        if (MimeType.isUnSupport(t)) {
            SuperToast.create(view.getContext(), getString(R.string.webview_unsupport), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
        } else {
            String s;
            if (toggle) {
                if (prefix.equals("/")) {
                    s = name + "/" + e.getPath();
                } else {
                    s = name + "/" + prefix + "/" + e.getPath();
                }
            } else {
                s = name + "/" + e.getPath();
            }
            Intent intent = new Intent(getActivity(), WebViewActivity.class);
            intent.putExtra(getString(R.string.webview_intent_title), t);
            intent.putExtra(getString(R.string.webview_intent_subtitle), s);
            intent.putExtra(getString(R.string.webview_intent_owner), owner);
            intent.putExtra(getString(R.string.webview_intent_name), name);
            intent.putExtra(getString(R.string.webview_intent_sha), item.getEntry().getSha());
            startActivityForResult(intent, 0);
        }
    }
}
Also used : StarContentTask(io.github.mthli.Bitocle.Content.StarContentTask) Intent(android.content.Intent) TreeEntry(org.eclipse.egit.github.core.TreeEntry) ContentItem(io.github.mthli.Bitocle.Content.ContentItem)

Example 3 with TreeEntry

use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.

the class MainFragment method clickWhenRepoContent.

private void clickWhenRepoContent(int position) {
    allTaskDown();
    ContentItem item = contentItemList.get(position);
    if (item.getEntry().getType().equals("tree")) {
        entry = item.getEntry();
        String[] arr = entry.getPath().split("/");
        title = arr[arr.length - 1];
        if (toggle) {
            if (prefix.equals("/")) {
                subTitle = name + "/" + entry.getPath();
            } else {
                subTitle = name + "/" + prefix + "/" + entry.getPath();
            }
        } else {
            subTitle = name + "/" + entry.getPath();
        }
        actionBar.setTitle(title);
        actionBar.setSubtitle(subTitle);
        actionBar.setDisplayHomeAsUpEnabled(true);
        flag = Flag.REPO_CONTENT_SECOND;
        currentId = REPO_CONTENT_ID;
        repoContentTask = new RepoContentTask(MainFragment.this);
        repoContentTask.execute();
    } else {
        TreeEntry e = item.getEntry();
        String[] a = e.getPath().split("/");
        String t = a[a.length - 1];
        if (MimeType.isUnSupport(t)) {
            SuperToast.create(view.getContext(), getString(R.string.webview_unsupport), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
        } else {
            String s;
            if (toggle) {
                if (prefix.equals("/")) {
                    s = name + "/" + e.getPath();
                } else {
                    s = name + "/" + prefix + "/" + e.getPath();
                }
            } else {
                s = name + "/" + e.getPath();
            }
            Intent intent = new Intent(getActivity(), WebViewActivity.class);
            intent.putExtra(getString(R.string.webview_intent_title), t);
            intent.putExtra(getString(R.string.webview_intent_subtitle), s);
            intent.putExtra(getString(R.string.webview_intent_owner), owner);
            intent.putExtra(getString(R.string.webview_intent_name), name);
            intent.putExtra(getString(R.string.webview_intent_sha), item.getEntry().getSha());
            startActivityForResult(intent, 0);
        }
    }
}
Also used : RepoContentTask(io.github.mthli.Bitocle.Content.RepoContentTask) Intent(android.content.Intent) TreeEntry(org.eclipse.egit.github.core.TreeEntry) ContentItem(io.github.mthli.Bitocle.Content.ContentItem)

Example 4 with TreeEntry

use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.

the class RepoContentTask method onPostExecute.

@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        if (flag == Flag.REPO_CONTENT_FIRST || flag == Flag.REPO_CONTENT_REFRESH) {
            fragment.setRoot(root);
        }
        List<TreeEntry> entries = root.getTree();
        if (flag == Flag.REPO_CONTENT_FIRST || flag == Flag.REPO_CONTENT_REFRESH) {
            list.clear();
            for (TreeEntry e : entries) {
                String[] a = e.getPath().split("/");
                if (a.length == 1) {
                    list.add(new ContentItem(e));
                }
            }
            Collections.sort(list);
            if (list.size() <= 0) {
                bookmark.setVisible(false);
                fragment.setContentEmpty(true);
                fragment.setEmptyText(R.string.content_empty_list);
                fragment.setContentShown(true);
            } else {
                bookmark.setVisible(true);
                fragment.setContentEmpty(false);
                adapter.notifyDataSetChanged();
                fragment.setContentShown(true);
            }
        } else {
            list.clear();
            String[] a = entry.getPath().split("/");
            for (TreeEntry e : entries) {
                String[] r = e.getPath().split("/");
                if ((r.length - 1 == a.length) && e.getPath().startsWith(entry.getPath())) {
                    list.add(new ContentItem(e));
                }
            }
            Collections.sort(list);
            if (list.size() <= 0) {
                bookmark.setVisible(false);
                fragment.setContentEmpty(true);
                fragment.setEmptyText(R.string.content_empty_list);
                fragment.setContentShown(true);
            } else {
                bookmark.setVisible(true);
                fragment.setContentEmpty(false);
                adapter.notifyDataSetChanged();
                fragment.setContentShown(true);
            }
        }
    } else {
        bookmark.setVisible(false);
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.content_empty_error);
        fragment.setContentShown(true);
    }
}
Also used : TreeEntry(org.eclipse.egit.github.core.TreeEntry)

Example 5 with TreeEntry

use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.

the class MainFragment method backToPrevious.

public void backToPrevious() {
    allTaskDown();
    String path;
    try {
        path = entry.getPath();
    } catch (NullPointerException n) {
        switch(currentId) {
            case REPO_CONTENT_ID:
                changeToRepo(Flag.REPO_SECOND);
                break;
            case STAR_CONTENT_ID:
                changeToStar(false);
                break;
            default:
                break;
        }
        return;
    }
    contentItemList.clear();
    if (path.split("/").length <= 1) {
        for (TreeEntry e : root.getTree()) {
            String[] a = e.getPath().split("/");
            if (a.length == 1) {
                contentItemList.add(new ContentItem(e));
            }
        }
        if (toggle) {
            title = prefix.split("/")[prefix.split("/").length - 1];
            subTitle = name + "/" + prefix;
        } else {
            title = name;
            subTitle = name;
        }
        actionBar.setTitle(title);
        actionBar.setSubtitle(subTitle);
        actionBar.setDisplayHomeAsUpEnabled(true);
        entry = null;
    } else {
        String[] a = path.split("/");
        String str = a[0];
        for (int i = 1; i < a.length - 1; i++) {
            str = str + "/" + a[i];
        }
        for (TreeEntry e : root.getTree()) {
            String[] r = e.getPath().split("/");
            if ((r.length - 1 == str.split("/").length) && e.getPath().startsWith(str)) {
                contentItemList.add(new ContentItem(e));
            }
            if (e.getPath().equals(str)) {
                entry = e;
            }
        }
        title = str.split("/")[str.split("/").length - 1];
        if (toggle) {
            subTitle = name + "/" + prefix + "/" + str;
        } else {
            subTitle = name + "/" + str;
        }
        actionBar.setTitle(title);
        actionBar.setSubtitle(subTitle);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    Collections.sort(contentItemList);
    contentItemAdapter.notifyDataSetChanged();
}
Also used : TreeEntry(org.eclipse.egit.github.core.TreeEntry) ContentItem(io.github.mthli.Bitocle.Content.ContentItem)

Aggregations

TreeEntry (org.eclipse.egit.github.core.TreeEntry)7 ContentItem (io.github.mthli.Bitocle.Content.ContentItem)4 Intent (android.content.Intent)2 Activity (android.app.Activity)1 SQLException (android.database.SQLException)1 SparseBooleanArray (android.util.SparseBooleanArray)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BookmarkItem (io.github.mthli.Bitocle.Bookmark.BookmarkItem)1 BookmarkTask (io.github.mthli.Bitocle.Bookmark.BookmarkTask)1 RepoContentTask (io.github.mthli.Bitocle.Content.RepoContentTask)1 StarContentTask (io.github.mthli.Bitocle.Content.StarContentTask)1 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)1 Bookmark (io.github.mthli.Bitocle.Database.Bookmark.Bookmark)1