use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkAddEditFolderActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
assert mIsAddMode;
if (requestCode == PARENT_FOLDER_REQUEST_CODE && resultCode == RESULT_OK) {
BookmarkId selectedBookmark = BookmarkId.getBookmarkIdFromString(data.getStringExtra(BookmarkFolderSelectActivity.INTENT_SELECTED_FOLDER));
updateParent(selectedBookmark);
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkAddEditFolderActivity method startAddFolderActivity.
/**
* Starts an add folder activity. This method should only be called by
* {@link BookmarkFolderSelectActivity}.
*/
public static void startAddFolderActivity(BookmarkFolderSelectActivity activity, List<BookmarkId> bookmarksToMove) {
assert bookmarksToMove.size() > 0;
Intent intent = new Intent(activity, BookmarkAddEditFolderActivity.class);
intent.putExtra(INTENT_IS_ADD_MODE, true);
ArrayList<String> bookmarkStrings = new ArrayList<>(bookmarksToMove.size());
for (BookmarkId id : bookmarksToMove) {
bookmarkStrings.add(id.toString());
}
intent.putStringArrayListExtra(BookmarkFolderSelectActivity.INTENT_BOOKMARKS_TO_MOVE, bookmarkStrings);
activity.startActivityForResult(intent, BookmarkFolderSelectActivity.CREATE_FOLDER_REQUEST_CODE);
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkUtils method addOrEditBookmark.
/**
* If the tab has already been bookmarked, start {@link BookmarkEditActivity} for the
* bookmark. If not, add the bookmark to bookmarkmodel, and show a snackbar notifying the user.
*
* Note: Takes ownership of bookmarkModel, and will call |destroy| on it when finished.
*
* @param existingBookmarkId The bookmark ID if the tab has already been bookmarked.
* @param bookmarkModel The bookmark model.
* @param tab The tab to add or edit a bookmark.
* @param snackbarManager The SnackbarManager used to show the snackbar.
* @param activity Current activity.
* @return Bookmark ID of the bookmark. Could be <code>null</code> if bookmark didn't exist
* and bookmark model failed to create it.
*/
public static BookmarkId addOrEditBookmark(long existingBookmarkId, BookmarkModel bookmarkModel, Tab tab, SnackbarManager snackbarManager, Activity activity) {
if (existingBookmarkId != Tab.INVALID_BOOKMARK_ID) {
BookmarkId bookmarkId = new BookmarkId(existingBookmarkId, BookmarkType.NORMAL);
startEditActivity(activity, bookmarkId);
bookmarkModel.destroy();
return bookmarkId;
}
BookmarkId parent = getLastUsedParent(activity);
if (parent == null || !bookmarkModel.doesBookmarkExist(parent)) {
parent = bookmarkModel.getDefaultFolder();
}
String url = tab.getOriginalUrl();
BookmarkId bookmarkId = bookmarkModel.addBookmark(parent, bookmarkModel.getChildCount(parent), tab.getTitle(), url);
Snackbar snackbar = null;
if (bookmarkId == null) {
snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_failed), new SnackbarController() {
@Override
public void onDismissNoAction(Object actionData) {
}
@Override
public void onAction(Object actionData) {
}
}, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_BOOKMARK_ADDED).setSingleLine(false);
RecordUserAction.record("EnhancedBookmarks.AddingFailed");
} else {
String folderName = bookmarkModel.getBookmarkTitle(bookmarkModel.getBookmarkById(bookmarkId).getParentId());
SnackbarController snackbarController = createSnackbarControllerForEditButton(activity, bookmarkId);
if (getLastUsedParent(activity) == null) {
snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_saved), snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED);
} else {
snackbar = Snackbar.make(folderName, snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED).setTemplateText(activity.getString(R.string.bookmark_page_saved_folder));
}
snackbar.setSingleLine(false).setAction(activity.getString(R.string.bookmark_item_edit), null);
}
snackbarManager.showSnackbar(snackbar);
bookmarkModel.destroy();
return bookmarkId;
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkModel method deleteBookmarks.
/**
* Delete one or multiple bookmarks from model. If more than one bookmarks are passed here, this
* method will group these delete operations into one undo bundle so that later if the user
* clicks undo, all bookmarks deleted here will be restored.
* @param bookmarks Bookmarks to delete. Note this array should not contain a folder and its
* children, because deleting folder will also remove all its children, and
* deleting children once more will cause errors.
*/
public void deleteBookmarks(BookmarkId... bookmarks) {
assert bookmarks != null && bookmarks.length > 0;
// Store all titles of bookmarks.
String[] titles = new String[bookmarks.length];
boolean isUndoable = true;
for (int i = 0; i < bookmarks.length; i++) {
titles[i] = getBookmarkTitle(bookmarks[i]);
isUndoable &= (bookmarks[i].getType() == BookmarkType.NORMAL);
}
if (bookmarks.length == 1) {
deleteBookmark(bookmarks[0]);
} else {
startGroupingUndos();
for (BookmarkId bookmark : bookmarks) {
deleteBookmark(bookmark);
}
endGroupingUndos();
}
for (BookmarkDeleteObserver observer : mDeleteObservers) {
observer.onDeleteBookmarks(titles, isUndoable);
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkBridge method addToBookmarkIdListWithDepth.
@CalledByNative
private static void addToBookmarkIdListWithDepth(List<BookmarkId> folderList, long id, int type, List<Integer> depthList, int depth) {
folderList.add(new BookmarkId(id, type));
depthList.add(depth);
}
Aggregations