Search in sources :

Example 1 with BookmarkId

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--;
            }
        }
    }
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId)

Example 2 with BookmarkId

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;
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) HashSet(java.util.HashSet)

Example 3 with BookmarkId

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);
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) ArrayList(java.util.ArrayList)

Example 4 with BookmarkId

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);
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 5 with BookmarkId

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);
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

BookmarkId (org.chromium.components.bookmarks.BookmarkId)18 Intent (android.content.Intent)4 ArrayList (java.util.ArrayList)4 BookmarkItem (org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem)2 Toolbar (android.support.v7.widget.Toolbar)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 BookmarkModel (org.chromium.chrome.browser.bookmarks.BookmarkModel)1 Snackbar (org.chromium.chrome.browser.snackbar.Snackbar)1 SnackbarController (org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController)1 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)1