Search in sources :

Example 1 with BookmarkTask

use of io.github.mthli.Bitocle.Bookmark.BookmarkTask 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 BookmarkTask

use of io.github.mthli.Bitocle.Bookmark.BookmarkTask in project Bitocle by mthli.

the class MainFragment method changeToBookmark.

public void changeToBookmark() {
    allTaskDown();
    hideWhenBookmark();
    setContentEmpty(false);
    setContentShown(true);
    actionBar.setTitle(R.string.bookmark_label);
    actionBar.setSubtitle(null);
    actionBar.setDisplayHomeAsUpEnabled(true);
    listView.setAdapter(bookmarkItemAdapter);
    bookmarkItemAdapter.notifyDataSetChanged();
    currentId = MainFragment.BOOKMARK_ID;
    bookmarkTask = new BookmarkTask(MainFragment.this);
    bookmarkTask.execute();
}
Also used : BookmarkTask(io.github.mthli.Bitocle.Bookmark.BookmarkTask)

Aggregations

BookmarkTask (io.github.mthli.Bitocle.Bookmark.BookmarkTask)2 SQLException (android.database.SQLException)1 SparseBooleanArray (android.util.SparseBooleanArray)1 BookmarkItem (io.github.mthli.Bitocle.Bookmark.BookmarkItem)1 ContentItem (io.github.mthli.Bitocle.Content.ContentItem)1 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)1 Bookmark (io.github.mthli.Bitocle.Database.Bookmark.Bookmark)1 TreeEntry (org.eclipse.egit.github.core.TreeEntry)1