use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkActionBar method onSelectionStateChange.
@Override
public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) {
super.onSelectionStateChange(selectedBookmarks);
if (mIsSelectionEnabled) {
// Editing a bookmark action on multiple selected items doesn't make sense. So disable.
getMenu().findItem(R.id.selection_mode_edit_menu_id).setVisible(selectedBookmarks.size() == 1);
getMenu().findItem(R.id.selection_open_in_incognito_tab_id).setVisible(PrefServiceBridge.getInstance().isIncognitoModeEnabled());
// It does not make sense to open a folder in new tab.
for (BookmarkId bookmark : selectedBookmarks) {
BookmarkItem item = mDelegate.getModel().getBookmarkById(bookmark);
if (item != null && item.isFolder()) {
getMenu().findItem(R.id.selection_open_in_new_tab_id).setVisible(false);
getMenu().findItem(R.id.selection_open_in_incognito_tab_id).setVisible(false);
break;
}
}
// disable the move button.
for (BookmarkId bookmark : selectedBookmarks) {
if (bookmark.getType() == BookmarkType.PARTNER) {
getMenu().findItem(R.id.selection_mode_move_menu_id).setVisible(false);
break;
}
}
} else {
mDelegate.notifyStateChange(this);
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == EDIT_BOOKMARK_REQUEST_CODE && resultCode == RESULT_OK) {
BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(data.getStringExtra(INTENT_VISIT_BOOKMARK_ID));
mBookmarkManager.openBookmark(bookmarkId, BookmarkLaunchLocation.BOOKMARK_EDITOR);
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkFolderSelectActivity method onItemClick.
/**
* Moves bookmark from original parent to selected folder. In creation mode, directly add the
* new bookmark to selected folder instead of moving.
*/
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
FolderListEntry entry = (FolderListEntry) adapter.getItemAtPosition(position);
if (mIsCreatingFolder) {
BookmarkId selectedFolder = null;
if (entry.mType == FolderListEntry.TYPE_NORMAL) {
selectedFolder = entry.mId;
} else {
assert false : "New folder items should not be clickable in creating mode";
}
Intent intent = new Intent();
intent.putExtra(INTENT_SELECTED_FOLDER, selectedFolder.toString());
setResult(RESULT_OK, intent);
finish();
} else if (entry.mType == FolderListEntry.TYPE_NEW_FOLDER) {
BookmarkAddEditFolderActivity.startAddFolderActivity(this, mBookmarksToMove);
} else if (entry.mType == FolderListEntry.TYPE_NORMAL) {
mModel.moveBookmarks(mBookmarksToMove, entry.mId);
BookmarkUtils.setLastUsedParent(this, entry.mId);
finish();
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class ChromeActivity method addOrEditBookmark.
/**
* Add the specified tab to bookmarks or allows to edit the bookmark if the specified tab is
* already bookmarked. If a new bookmark is added, a snackbar will be shown.
* @param tabToBookmark The tab that needs to be bookmarked.
*/
public void addOrEditBookmark(final Tab tabToBookmark) {
if (tabToBookmark == null || tabToBookmark.isFrozen()) {
return;
}
// Defense in depth against the UI being erroneously enabled.
if (!mToolbarManager.getBookmarkBridge().isEditBookmarksEnabled()) {
assert false;
return;
}
// Note the use of getUserBookmarkId() over getBookmarkId() here: Managed bookmarks can't be
// edited. If the current URL is only bookmarked by managed bookmarks, this will return
// INVALID_BOOKMARK_ID, so the code below will fall back on adding a new bookmark instead.
// TODO(bauerb): This does not take partner bookmarks into account.
final long bookmarkId = tabToBookmark.getUserBookmarkId();
final BookmarkModel bookmarkModel = new BookmarkModel();
bookmarkModel.runAfterBookmarkModelLoaded(new Runnable() {
@Override
public void run() {
// Gives up the bookmarking if the tab is being destroyed.
if (!tabToBookmark.isClosing() && tabToBookmark.isInitialized()) {
// The BookmarkModel will be destroyed by BookmarkUtils#addOrEditBookmark() when
// done.
BookmarkId newBookmarkId = BookmarkUtils.addOrEditBookmark(bookmarkId, bookmarkModel, tabToBookmark, getSnackbarManager(), ChromeActivity.this);
// If a new bookmark was created, try to save an offline page for it.
if (newBookmarkId != null && newBookmarkId.getId() != bookmarkId) {
OfflinePageUtils.saveBookmarkOffline(newBookmarkId, tabToBookmark);
}
} else {
bookmarkModel.destroy();
}
}
});
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkActionBar method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
SelectionDelegate<BookmarkId> selectionDelegate = mDelegate.getSelectionDelegate();
if (menuItem.getItemId() == R.id.edit_menu_id) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), mCurrentFolder.getId());
return true;
} else if (menuItem.getItemId() == R.id.close_menu_id) {
BookmarkUtils.finishActivityOnPhone(getContext());
return true;
} else if (menuItem.getItemId() == R.id.search_menu_id) {
mDelegate.openSearchUI();
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_edit_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
assert list.size() == 1;
BookmarkItem item = mDelegate.getModel().getBookmarkById(list.get(0));
if (item.isFolder()) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
} else {
BookmarkUtils.startEditActivity(getContext(), item.getId());
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_move_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
if (list.size() >= 1) {
BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), list.toArray(new BookmarkId[list.size()]));
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_delete_menu_id) {
mDelegate.getModel().deleteBookmarks(selectionDelegate.getSelectedItems().toArray(new BookmarkId[0]));
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_new_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(false), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_incognito_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(true), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
}
assert false : "Unhandled menu click.";
return false;
}
Aggregations