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.

212 lines
11KB

  1. From: Wengling Chen <[email protected]>
  2. Date: Thu, 23 Apr 2020 03:32:39 -0400
  3. Subject: Add new folder button to bookmark activity
  4. ---
  5. chrome/android/java/res/menu/bookmark_action_bar_menu.xml | 7 +++
  6. chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java | 6 ++
  7. chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java | 21 ++++++++-
  8. chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java | 5 +-
  9. chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java | 22 +++++++++-
  10. chrome/browser/ui/android/strings/android_chrome_strings.grd | 3 +
  11. 6 files changed, 59 insertions(+), 5 deletions(-)
  12. --- a/chrome/android/java/res/menu/bookmark_action_bar_menu.xml
  13. +++ b/chrome/android/java/res/menu/bookmark_action_bar_menu.xml
  14. @@ -15,6 +15,13 @@
  15. app:showAsAction="ifRoom"
  16. app:iconTint="@color/default_icon_color_tint_list" />
  17. <item
  18. + android:id="@+id/add_folder_menu_id"
  19. + android:icon="@drawable/ic_add_outline_white_24dp"
  20. + android:title="@string/bookmark_action_bar_add_folder"
  21. + android:visible="false"
  22. + app:showAsAction="ifRoom"
  23. + app:iconTint="@color/default_icon_color_tint_list" />
  24. + <item
  25. android:id="@+id/search_menu_id"
  26. android:icon="@drawable/ic_search"
  27. android:title="@string/search"
  28. --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java
  29. +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkActionBar.java
  30. @@ -80,6 +80,9 @@ public class BookmarkActionBar extends S
  31. } else if (menuItem.getItemId() == R.id.close_menu_id) {
  32. BookmarkUtils.finishActivityOnPhone(getContext());
  33. return true;
  34. + } else if (menuItem.getItemId() == R.id.add_folder_menu_id) {
  35. + BookmarkAddEditFolderActivity.startAddFolderActivity(getContext(), mCurrentFolder.getId());
  36. + return true;
  37. } else if (menuItem.getItemId() == R.id.search_menu_id) {
  38. mDelegate.openSearchUI();
  39. return true;
  40. @@ -136,6 +139,7 @@ public class BookmarkActionBar extends S
  41. setNavigationButton(NAVIGATION_BUTTON_NONE);
  42. getMenu().findItem(R.id.search_menu_id).setVisible(false);
  43. getMenu().findItem(R.id.edit_menu_id).setVisible(false);
  44. + getMenu().findItem(R.id.add_folder_menu_id).setVisible(false);
  45. }
  46. @Override
  47. @@ -145,6 +149,7 @@ public class BookmarkActionBar extends S
  48. if (mDelegate == null) {
  49. getMenu().findItem(R.id.search_menu_id).setVisible(false);
  50. getMenu().findItem(R.id.edit_menu_id).setVisible(false);
  51. + getMenu().findItem(R.id.add_folder_menu_id).setVisible(false);
  52. }
  53. }
  54. @@ -174,6 +179,7 @@ public class BookmarkActionBar extends S
  55. mCurrentFolder = mDelegate.getModel().getBookmarkById(folder);
  56. getMenu().findItem(R.id.search_menu_id).setVisible(true);
  57. + getMenu().findItem(R.id.add_folder_menu_id).setVisible(true);
  58. getMenu().findItem(R.id.edit_menu_id).setVisible(mCurrentFolder.isEditable());
  59. // If this is the root folder, we can't go up anymore.
  60. --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java
  61. +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkAddEditFolderActivity.java
  62. @@ -35,12 +35,14 @@ import java.util.List;
  63. public class BookmarkAddEditFolderActivity extends SynchronousInitializationActivity
  64. implements OnClickListener {
  65. static final String INTENT_IS_ADD_MODE = "BookmarkAddEditFolderActivity.isAddMode";
  66. + static final String INTENT_IS_SIMPLE_ADD_MODE = "BookmarkAddEditFolderActivity.isSimpleAddMode";
  67. static final String INTENT_BOOKMARK_ID = "BookmarkAddEditFolderActivity.BookmarkId";
  68. static final String
  69. INTENT_CREATED_BOOKMARK = "BookmarkAddEditFolderActivity.createdBookmark";
  70. static final int PARENT_FOLDER_REQUEST_CODE = 10;
  71. private boolean mIsAddMode;
  72. + private boolean mIsSimpleAddMode;
  73. private BookmarkId mParentId;
  74. private BookmarkModel mModel;
  75. private TextView mParentTextView;
  76. @@ -99,6 +101,17 @@ public class BookmarkAddEditFolderActivi
  77. }
  78. /**
  79. + * Starts an add folder activity, without a specific bookmark.
  80. + */
  81. + public static void startAddFolderActivity(Context context, BookmarkId idToEdit) {
  82. + Intent intent = new Intent(context, BookmarkAddEditFolderActivity.class);
  83. + intent.putExtra(INTENT_IS_ADD_MODE, true);
  84. + intent.putExtra(INTENT_IS_SIMPLE_ADD_MODE, true);
  85. + intent.putExtra(INTENT_BOOKMARK_ID, idToEdit.toString());
  86. + context.startActivity(intent);
  87. + }
  88. +
  89. + /**
  90. * Starts an add folder activity. This method should only be called by
  91. * {@link BookmarkFolderSelectActivity}.
  92. */
  93. @@ -123,7 +136,9 @@ public class BookmarkAddEditFolderActivi
  94. mModel = new BookmarkModel();
  95. mModel.addObserver(mBookmarkModelObserver);
  96. mIsAddMode = getIntent().getBooleanExtra(INTENT_IS_ADD_MODE, false);
  97. - if (mIsAddMode) {
  98. + mIsSimpleAddMode = getIntent().getBooleanExtra(INTENT_IS_SIMPLE_ADD_MODE, false);
  99. + assert !mIsSimpleAddMode || mIsAddMode;
  100. + if (mIsAddMode && !mIsSimpleAddMode) {
  101. List<String> stringList = getIntent().getStringArrayListExtra(
  102. BookmarkFolderSelectActivity.INTENT_BOOKMARKS_TO_MOVE);
  103. mBookmarksToMove = new ArrayList<>(stringList.size());
  104. @@ -172,7 +187,9 @@ public class BookmarkAddEditFolderActivi
  105. public void onClick(View v) {
  106. assert v == mParentTextView;
  107. - if (mIsAddMode) {
  108. + if (mIsSimpleAddMode) {
  109. + BookmarkFolderSelectActivity.startNewFolderSelectActivity(this, mFolderId);
  110. + } else if (mIsAddMode) {
  111. BookmarkFolderSelectActivity.startNewFolderSelectActivity(
  112. this, mBookmarksToMove);
  113. } else {
  114. --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java
  115. +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkFolderSelectActivity.java
  116. @@ -52,11 +52,14 @@ public class BookmarkFolderSelectActivit
  117. static final String
  118. INTENT_IS_CREATING_FOLDER = "BookmarkFolderSelectActivity.isCreatingFolder";
  119. static final String
  120. + INTENT_IS_SIMPLE_CREATING_FOLDER = "BookmarkFolderSelectActivity.isSimpleCreatingFolder";
  121. + static final String
  122. INTENT_BOOKMARKS_TO_MOVE = "BookmarkFolderSelectActivity.bookmarksToMove";
  123. static final int CREATE_FOLDER_REQUEST_CODE = 13;
  124. private BookmarkModel mModel;
  125. private boolean mIsCreatingFolder;
  126. + private boolean mIsSimpleCreatingFolder;
  127. private List<BookmarkId> mBookmarksToMove;
  128. private BookmarkId mParentId;
  129. private FolderListAdapter mBookmarkIdsAdapter;
  130. @@ -99,6 +102,22 @@ public class BookmarkFolderSelectActivit
  131. }
  132. /**
  133. + * Starts a select folder activity for the new folder that is about to be created. No bookmark
  134. + * specified.
  135. + */
  136. + public static void startNewFolderSelectActivity(
  137. + BookmarkAddEditFolderActivity activity, BookmarkId folderId) {
  138. + Intent intent = new Intent(activity, BookmarkFolderSelectActivity.class);
  139. + intent.putExtra(INTENT_IS_CREATING_FOLDER, true);
  140. + intent.putExtra(INTENT_IS_SIMPLE_CREATING_FOLDER, true);
  141. + ArrayList<String> bookmarkStrings = new ArrayList<>(1);
  142. + bookmarkStrings.add(folderId.toString());
  143. + intent.putStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE, bookmarkStrings);
  144. + activity.startActivityForResult(intent,
  145. + BookmarkAddEditFolderActivity.PARENT_FOLDER_REQUEST_CODE);
  146. + }
  147. +
  148. + /**
  149. * Starts a select folder activity for the new folder that is about to be created. This method
  150. * is only supposed to be called by {@link BookmarkAddEditFolderActivity}
  151. */
  152. @@ -149,6 +168,7 @@ public class BookmarkFolderSelectActivit
  153. }
  154. mIsCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_CREATING_FOLDER, false);
  155. + mIsSimpleCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_SIMPLE_CREATING_FOLDER, false);
  156. if (mIsCreatingFolder) {
  157. mParentId = mModel.getMobileFolderId();
  158. } else {
  159. @@ -183,7 +203,7 @@ public class BookmarkFolderSelectActivit
  160. private void updateFolderList() {
  161. List<BookmarkId> folderList = new ArrayList<>();
  162. List<Integer> depthList = new ArrayList<>();
  163. - mModel.getMoveDestinations(folderList, depthList, mBookmarksToMove);
  164. + mModel.getMoveDestinations(folderList, depthList, mBookmarksToMove, mIsSimpleCreatingFolder);
  165. List<FolderListEntry> entryList = new ArrayList<>(folderList.size() + 3);
  166. if (!mIsCreatingFolder) {
  167. --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
  168. +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
  169. @@ -2648,6 +2648,9 @@ To change this setting, <ph name="BEGIN_
  170. <message name="IDS_BOOKMARK_ACTION_BAR_EDIT_FOLDER" desc="Button text for editing current folder action on the bookmark action bar [CHAR-LIMIT=32]">
  171. Edit folder
  172. </message>
  173. + <message name="IDS_BOOKMARK_ACTION_BAR_ADD_FOLDER" desc="Button text for adding new folder action on the bookmark action bar [CHAR-LIMIT=32]">
  174. + Add folder
  175. + </message>
  176. <message name="IDS_BOOKMARK_ACTION_BAR_MOVE" desc="Button text for bookmark move action on the bookmark action bar [CHAR-LIMIT=32]">
  177. Move bookmarks
  178. </message>
  179. --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java
  180. +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkBridge.java
  181. @@ -437,7 +437,8 @@ public class BookmarkBridge {
  182. * moving some folders (a folder cannot be moved to its own children).
  183. */
  184. public void getMoveDestinations(List<BookmarkId> folderList,
  185. - List<Integer> depthList, List<BookmarkId> bookmarksToMove) {
  186. + List<Integer> depthList, List<BookmarkId> bookmarksToMove,
  187. + boolean isSimpleCreatingFolder) {
  188. ThreadUtils.assertOnUiThread();
  189. assert mIsNativeBookmarkModelLoaded;
  190. BookmarkBridgeJni.get().getAllFoldersWithDepths(
  191. @@ -462,7 +463,7 @@ public class BookmarkBridge {
  192. // statement.
  193. if (!shouldTrim) {
  194. BookmarkId folder = folderList.get(i);
  195. - if (bookmarksToMove.contains(folder)) {
  196. + if (!isSimpleCreatingFolder && bookmarksToMove.contains(folder)) {
  197. shouldTrim = true;
  198. trimThreshold = depth;
  199. folderList.remove(i);