Android build for ungoogled-chromium. https://uc.droidware.info
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

211 lines
11 KiB

From: Wengling Chen <[email protected]>
Date: Thu, 23 Apr 2020 03:32:39 -0400
Subject: Add new folder button to bookmark activity
---
chrome/android/java/res/menu/bookmark_action_bar_menu.xml | 7 +++
chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java | 6 ++
chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java | 21 ++++++++-
chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java | 5 +-
chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java | 22 +++++++++-
chrome/browser/ui/android/strings/android_chrome_strings.grd | 3 +
6 files changed, 59 insertions(+), 5 deletions(-)
--- a/chrome/android/java/res/menu/bookmark_action_bar_menu.xml
+++ b/chrome/android/java/res/menu/bookmark_action_bar_menu.xml
@@ -15,6 +15,13 @@
app:showAsAction="ifRoom"
app:iconTint="@color/default_icon_color_tint_list" />
<item
+ android:id="@+id/add_folder_menu_id"
+ android:icon="@drawable/ic_add_outline_white_24dp"
+ android:title="@string/bookmark_action_bar_add_folder"
+ android:visible="false"
+ app:showAsAction="ifRoom"
+ app:iconTint="@color/default_icon_color_tint_list" />
+ <item
android:id="@+id/search_menu_id"
android:icon="@drawable/ic_search"
android:title="@string/search"
--- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java
@@ -80,6 +80,9 @@ public class BookmarkActionBar extends S
} else if (menuItem.getItemId() == R.id.close_menu_id) {
BookmarkUtils.finishActivityOnPhone(getContext());
return true;
+ } else if (menuItem.getItemId() == R.id.add_folder_menu_id) {
+ BookmarkAddEditFolderActivity.startAddFolderActivity(getContext(), mCurrentFolder.getId());
+ return true;
} else if (menuItem.getItemId() == R.id.search_menu_id) {
mDelegate.openSearchUI();
return true;
@@ -136,6 +139,7 @@ public class BookmarkActionBar extends S
setNavigationButton(NAVIGATION_BUTTON_NONE);
getMenu().findItem(R.id.search_menu_id).setVisible(false);
getMenu().findItem(R.id.edit_menu_id).setVisible(false);
+ getMenu().findItem(R.id.add_folder_menu_id).setVisible(false);
}
@Override
@@ -145,6 +149,7 @@ public class BookmarkActionBar extends S
if (mDelegate == null) {
getMenu().findItem(R.id.search_menu_id).setVisible(false);
getMenu().findItem(R.id.edit_menu_id).setVisible(false);
+ getMenu().findItem(R.id.add_folder_menu_id).setVisible(false);
}
}
@@ -174,6 +179,7 @@ public class BookmarkActionBar extends S
mCurrentFolder = mDelegate.getModel().getBookmarkById(folder);
getMenu().findItem(R.id.search_menu_id).setVisible(true);
+ getMenu().findItem(R.id.add_folder_menu_id).setVisible(true);
getMenu().findItem(R.id.edit_menu_id).setVisible(mCurrentFolder.isEditable());
// If this is the root folder, we can't go up anymore.
--- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java
@@ -35,12 +35,14 @@ import java.util.List;
public class BookmarkAddEditFolderActivity extends SynchronousInitializationActivity
implements OnClickListener {
static final String INTENT_IS_ADD_MODE = "BookmarkAddEditFolderActivity.isAddMode";
+ static final String INTENT_IS_SIMPLE_ADD_MODE = "BookmarkAddEditFolderActivity.isSimpleAddMode";
static final String INTENT_BOOKMARK_ID = "BookmarkAddEditFolderActivity.BookmarkId";
static final String
INTENT_CREATED_BOOKMARK = "BookmarkAddEditFolderActivity.createdBookmark";
static final int PARENT_FOLDER_REQUEST_CODE = 10;
private boolean mIsAddMode;
+ private boolean mIsSimpleAddMode;
private BookmarkId mParentId;
private BookmarkModel mModel;
private TextView mParentTextView;
@@ -99,6 +101,17 @@ public class BookmarkAddEditFolderActivi
}
/**
+ * Starts an add folder activity, without a specific bookmark.
+ */
+ public static void startAddFolderActivity(Context context, BookmarkId idToEdit) {
+ Intent intent = new Intent(context, BookmarkAddEditFolderActivity.class);
+ intent.putExtra(INTENT_IS_ADD_MODE, true);
+ intent.putExtra(INTENT_IS_SIMPLE_ADD_MODE, true);
+ intent.putExtra(INTENT_BOOKMARK_ID, idToEdit.toString());
+ context.startActivity(intent);
+ }
+
+ /**
* Starts an add folder activity. This method should only be called by
* {@link BookmarkFolderSelectActivity}.
*/
@@ -123,7 +136,9 @@ public class BookmarkAddEditFolderActivi
mModel = new BookmarkModel();
mModel.addObserver(mBookmarkModelObserver);
mIsAddMode = getIntent().getBooleanExtra(INTENT_IS_ADD_MODE, false);
- if (mIsAddMode) {
+ mIsSimpleAddMode = getIntent().getBooleanExtra(INTENT_IS_SIMPLE_ADD_MODE, false);
+ assert !mIsSimpleAddMode || mIsAddMode;
+ if (mIsAddMode && !mIsSimpleAddMode) {
List<String> stringList = getIntent().getStringArrayListExtra(
BookmarkFolderSelectActivity.INTENT_BOOKMARKS_TO_MOVE);
mBookmarksToMove = new ArrayList<>(stringList.size());
@@ -172,7 +187,9 @@ public class BookmarkAddEditFolderActivi
public void onClick(View v) {
assert v == mParentTextView;
- if (mIsAddMode) {
+ if (mIsSimpleAddMode) {
+ BookmarkFolderSelectActivity.startNewFolderSelectActivity(this, mFolderId);
+ } else if (mIsAddMode) {
BookmarkFolderSelectActivity.startNewFolderSelectActivity(
this, mBookmarksToMove);
} else {
--- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java
@@ -52,11 +52,14 @@ public class BookmarkFolderSelectActivit
static final String
INTENT_IS_CREATING_FOLDER = "BookmarkFolderSelectActivity.isCreatingFolder";
static final String
+ INTENT_IS_SIMPLE_CREATING_FOLDER = "BookmarkFolderSelectActivity.isSimpleCreatingFolder";
+ static final String
INTENT_BOOKMARKS_TO_MOVE = "BookmarkFolderSelectActivity.bookmarksToMove";
static final int CREATE_FOLDER_REQUEST_CODE = 13;
private BookmarkModel mModel;
private boolean mIsCreatingFolder;
+ private boolean mIsSimpleCreatingFolder;
private List<BookmarkId> mBookmarksToMove;
private BookmarkId mParentId;
private FolderListAdapter mBookmarkIdsAdapter;
@@ -99,6 +102,22 @@ public class BookmarkFolderSelectActivit
}
/**
+ * Starts a select folder activity for the new folder that is about to be created. No bookmark
+ * specified.
+ */
+ public static void startNewFolderSelectActivity(
+ BookmarkAddEditFolderActivity activity, BookmarkId folderId) {
+ Intent intent = new Intent(activity, BookmarkFolderSelectActivity.class);
+ intent.putExtra(INTENT_IS_CREATING_FOLDER, true);
+ intent.putExtra(INTENT_IS_SIMPLE_CREATING_FOLDER, true);
+ ArrayList<String> bookmarkStrings = new ArrayList<>(1);
+ bookmarkStrings.add(folderId.toString());
+ intent.putStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE, bookmarkStrings);
+ activity.startActivityForResult(intent,
+ BookmarkAddEditFolderActivity.PARENT_FOLDER_REQUEST_CODE);
+ }
+
+ /**
* 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}
*/
@@ -149,6 +168,7 @@ public class BookmarkFolderSelectActivit
}
mIsCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_CREATING_FOLDER, false);
+ mIsSimpleCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_SIMPLE_CREATING_FOLDER, false);
if (mIsCreatingFolder) {
mParentId = mModel.getMobileFolderId();
} else {
@@ -183,7 +203,7 @@ public class BookmarkFolderSelectActivit
private void updateFolderList() {
List<BookmarkId> folderList = new ArrayList<>();
List<Integer> depthList = new ArrayList<>();
- mModel.getMoveDestinations(folderList, depthList, mBookmarksToMove);
+ mModel.getMoveDestinations(folderList, depthList, mBookmarksToMove, mIsSimpleCreatingFolder);
List<FolderListEntry> entryList = new ArrayList<>(folderList.size() + 3);
if (!mIsCreatingFolder) {
--- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
+++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
@@ -2944,6 +2944,9 @@ Data from your Incognito session will on
<message name="IDS_BOOKMARK_ACTION_BAR_EDIT_FOLDER" desc="Button text for editing current folder action on the bookmark action bar [CHAR-LIMIT=32]">
Edit folder
</message>
+ <message name="IDS_BOOKMARK_ACTION_BAR_ADD_FOLDER" desc="Button text for adding new folder action on the bookmark action bar [CHAR-LIMIT=32]">
+ Add folder
+ </message>
<message name="IDS_BOOKMARK_ACTION_BAR_MOVE" desc="Button text for bookmark move action on the bookmark action bar [CHAR-LIMIT=32]">
Move bookmarks
</message>
--- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java
@@ -437,7 +437,8 @@ public class BookmarkBridge {
* moving some folders (a folder cannot be moved to its own children).
*/
public void getMoveDestinations(List<BookmarkId> folderList,
- List<Integer> depthList, List<BookmarkId> bookmarksToMove) {
+ List<Integer> depthList, List<BookmarkId> bookmarksToMove,
+ boolean isSimpleCreatingFolder) {
ThreadUtils.assertOnUiThread();
assert mIsNativeBookmarkModelLoaded;
BookmarkBridgeJni.get().getAllFoldersWithDepths(
@@ -462,7 +463,7 @@ public class BookmarkBridge {
// statement.
if (!shouldTrim) {
BookmarkId folder = folderList.get(i);
- if (bookmarksToMove.contains(folder)) {
+ if (!isSimpleCreatingFolder && bookmarksToMove.contains(folder)) {
shouldTrim = true;
trimThreshold = depth;
folderList.remove(i);