use of io.github.mthli.Bitocle.Bookmark.BookmarkItem 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;
}
Aggregations