Search in sources :

Example 1 with Bookmark

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

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

the class BookmarkTask method onPostExecute.

@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        list.clear();
        for (Bookmark b : bookmarks) {
            list.add(new BookmarkItem(b.getTitle(), b.getType(), b.getOwner(), b.getName(), b.getPath(), b.getSha(), b.getKey()));
        }
        if (list.size() <= 0) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.bookmark_empty_list);
            fragment.setContentShown(true);
        } else {
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
        }
    } else {
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.bookmark_empty_error);
        fragment.setContentShown(true);
    }
}
Also used : Bookmark(io.github.mthli.Bitocle.Database.Bookmark.Bookmark)

Aggregations

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