use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkBridge method getMoveDestinations.
/**
* Calls {@link #getAllFoldersWithDepths(List, List)} and remove all folders and children
* in bookmarksToMove. This method is useful when finding a list of possible parent folers when
* moving some folders (a folder cannot be moved to its own children).
*/
public void getMoveDestinations(List<BookmarkId> folderList, List<Integer> depthList, List<BookmarkId> bookmarksToMove) {
assert mIsNativeBookmarkModelLoaded;
nativeGetAllFoldersWithDepths(mNativeBookmarkBridge, folderList, depthList);
if (bookmarksToMove == null || bookmarksToMove.size() == 0)
return;
boolean shouldTrim = false;
int trimThreshold = -1;
for (int i = 0; i < folderList.size(); i++) {
int depth = depthList.get(i);
if (shouldTrim) {
if (depth <= trimThreshold) {
shouldTrim = false;
trimThreshold = -1;
} else {
folderList.remove(i);
depthList.remove(i);
i--;
}
}
// statement.
if (!shouldTrim) {
BookmarkId folder = folderList.get(i);
if (bookmarksToMove.contains(folder)) {
shouldTrim = true;
trimThreshold = depth;
folderList.remove(i);
depthList.remove(i);
i--;
}
}
}
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkDrawerListViewAdapter method getItemPosition.
/**
* Get item position of the given mode.
*/
int getItemPosition(int state, Object modeDetail) {
if (state == BookmarkUIState.STATE_FOLDER) {
Set<BookmarkId> topLevelFolderParents = new HashSet<>();
topLevelFolderParents.addAll(mDelegate.getModel().getTopLevelFolderParentIDs());
topLevelFolderParents.add(mDesktopNodeId);
topLevelFolderParents.add(mOthersNodeId);
topLevelFolderParents.add(mMobileNodeId);
// Find top folder id that contains |folder|.
BookmarkId topFolderId = (BookmarkId) modeDetail;
while (true) {
BookmarkId parentId = mDelegate.getModel().getBookmarkById(topFolderId).getParentId();
if (topLevelFolderParents.contains(parentId)) {
break;
}
topFolderId = parentId;
}
return positionOfBookmarkId(topFolderId);
}
return -1;
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkFolderSelectActivity method updateFolderList.
private void updateFolderList() {
List<BookmarkId> folderList = new ArrayList<>();
List<Integer> depthList = new ArrayList<>();
mModel.getMoveDestinations(folderList, depthList, mBookmarksToMove);
List<FolderListEntry> entryList = new ArrayList<>(folderList.size() + 3);
if (!mIsCreatingFolder) {
entryList.add(new FolderListEntry(null, 0, getString(R.string.bookmark_add_folder), false, FolderListEntry.TYPE_NEW_FOLDER));
}
for (int i = 0; i < folderList.size(); i++) {
BookmarkId folder = folderList.get(i);
if (!mModel.isFolderVisible(folder))
continue;
String title = mModel.getBookmarkById(folder).getTitle();
entryList.add(new FolderListEntry(folder, depthList.get(i), title, folder.equals(mParentId), FolderListEntry.TYPE_NORMAL));
}
mBookmarkIdsAdapter.setEntryList(entryList);
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkFolderSelectActivity method startFolderSelectActivity.
/**
* Starts a select folder activity.
*/
public static void startFolderSelectActivity(Context context, BookmarkId... bookmarks) {
assert bookmarks.length > 0;
Intent intent = new Intent(context, BookmarkFolderSelectActivity.class);
intent.putExtra(INTENT_IS_CREATING_FOLDER, false);
ArrayList<String> bookmarkStrings = new ArrayList<>(bookmarks.length);
for (BookmarkId id : bookmarks) {
bookmarkStrings.add(id.toString());
}
intent.putStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE, bookmarkStrings);
context.startActivity(intent);
}
use of org.chromium.components.bookmarks.BookmarkId in project AndroidChromium by JackyAndroid.
the class BookmarkFolderSelectActivity method startNewFolderSelectActivity.
/**
* Starts a select folder activity for the new folder that is about to be created. This method
* is only supposed to be called by {@link BookmarkAddEditFolderActivity}
*/
public static void startNewFolderSelectActivity(BookmarkAddEditFolderActivity activity, List<BookmarkId> bookmarks) {
assert bookmarks.size() > 0;
Intent intent = new Intent(activity, BookmarkFolderSelectActivity.class);
intent.putExtra(INTENT_IS_CREATING_FOLDER, true);
ArrayList<String> bookmarkStrings = new ArrayList<>(bookmarks.size());
for (BookmarkId id : bookmarks) {
bookmarkStrings.add(id.toString());
}
intent.putStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE, bookmarkStrings);
activity.startActivityForResult(intent, BookmarkAddEditFolderActivity.PARENT_FOLDER_REQUEST_CODE);
}
Aggregations