Commit ebcadc5f authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Read Later : Configure menu items

This CL
1 - Adds mark as read option for reading list items
2 - Removes select option for reading list items
3 - Removes edit, move menu buttons from multi-select toolbar menu if
at least one reading list item is selected.

Bug: 1148872
Change-Id: Ibb790a48d9f330436c1899bf7322a5432d3ec7b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2539115
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828518}
parent a758517c
......@@ -228,6 +228,15 @@ public class BookmarkActionBar extends SelectableListToolbar<BookmarkId>
break;
}
}
// Disable edit, move buttons, if the selection includes a reading list item.
for (BookmarkId bookmark : selectedBookmarks) {
if (bookmark.getType() == BookmarkType.READING_LIST) {
getMenu().findItem(R.id.selection_mode_move_menu_id).setVisible(false);
getMenu().findItem(R.id.selection_mode_edit_menu_id).setVisible(false);
break;
}
}
} else {
mDelegate.notifyStateChange(this);
}
......
......@@ -21,6 +21,7 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem;
import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.bookmarks.BookmarkType;
import org.chromium.components.browser_ui.widget.listmenu.BasicListMenu;
import org.chromium.components.browser_ui.widget.listmenu.ListMenu;
import org.chromium.components.browser_ui.widget.listmenu.ListMenuButton;
......@@ -147,10 +148,16 @@ public abstract class BookmarkRow
if (bookmarkItem != null) canMove = bookmarkItem.isMovable();
}
ModelList listItems = new ModelList();
listItems.add(buildMenuListItem(R.string.bookmark_item_select, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_edit, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_move, 0, 0, canMove));
listItems.add(buildMenuListItem(R.string.bookmark_item_delete, 0, 0));
if (mBookmarkId.getType() == BookmarkType.READING_LIST) {
listItems.add(buildMenuListItem(R.string.reading_list_mark_as_read, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_select, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_delete, 0, 0));
} else {
listItems.add(buildMenuListItem(R.string.bookmark_item_select, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_edit, 0, 0));
listItems.add(buildMenuListItem(R.string.bookmark_item_move, 0, 0, canMove));
listItems.add(buildMenuListItem(R.string.bookmark_item_delete, 0, 0));
}
if (mDelegate.getCurrentState() == BookmarkUIState.STATE_SEARCHING) {
listItems.add(buildMenuListItem(R.string.bookmark_show_in_folder, 0, 0));
......@@ -183,6 +190,11 @@ public abstract class BookmarkRow
} else {
BookmarkUtils.startEditActivity(getContext(), bookmarkItem.getId());
}
} else if (textId == R.string.reading_list_mark_as_read) {
BookmarkItem bookmarkItem = mDelegate.getModel().getBookmarkById(mBookmarkId);
mDelegate.getModel().setReadStatusForReadingList(
bookmarkItem.getUrl(), true /*read*/);
// TODO(crbug/1140277): Add metrics.
} else if (textId == R.string.bookmark_item_move) {
BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), mBookmarkId);
RecordUserAction.record("MobileBookmarkManagerMoveToFolder");
......
......@@ -1002,6 +1002,63 @@ public class BookmarkTest {
mManager.getSelectionDelegate().isSelectionEnabled());
}
@Test
@SmallTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
public void testReadingListItemsInSelectionMode() throws Exception {
addReadingListBookmark(TEST_PAGE_TITLE_GOOGLE, TEST_URL_A);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
openBookmarkManager();
TestThreadUtils.runOnUiThreadBlocking(
() -> mManager.openFolder(mBookmarkModel.getRootFolderId()));
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
// Open the "Reading list" folder.
onView(withText("Reading list")).perform(click());
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
// Select a reading list item. Verify the toolbar menu buttons being shown.
BookmarkRow bookmarkRow =
(BookmarkRow) mItemsContainer.findViewHolderForAdapterPosition(1).itemView;
TouchCommon.longPressView(bookmarkRow);
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
BookmarkActionBar toolbar = mManager.getToolbarForTests();
Assert.assertFalse("Read later items shouldn't have move option",
toolbar.getMenu().findItem(R.id.selection_mode_move_menu_id).isVisible());
Assert.assertFalse("Read later items shouldn't have edit option",
toolbar.getMenu().findItem(R.id.selection_mode_edit_menu_id).isVisible());
Assert.assertTrue("Read later items should have delete option",
toolbar.getMenu().findItem(R.id.selection_mode_delete_menu_id).isVisible());
}
@Test
@SmallTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
public void testReadingListItemMenuItems() throws Exception {
addReadingListBookmark(TEST_PAGE_TITLE_GOOGLE, TEST_URL_A);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
openBookmarkManager();
TestThreadUtils.runOnUiThreadBlocking(
() -> mManager.openFolder(mBookmarkModel.getRootFolderId()));
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
// Open the "Reading list" folder.
onView(withText("Reading list")).perform(click());
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
// Open the three-dot menu and verify the menu options being shown.
View readingListItem = mItemsContainer.findViewHolderForAdapterPosition(1).itemView;
View more = readingListItem.findViewById(R.id.more);
TestThreadUtils.runOnUiThreadBlocking(more::callOnClick);
onView(withText("Select")).check(matches(isDisplayed()));
onView(withText("Edit")).check(doesNotExist());
onView(withText("Delete")).check(matches(isDisplayed()));
onView(withText("Mark as read")).check(matches(isDisplayed()));
onView(withText("Move up")).check(doesNotExist());
onView(withText("Move down")).check(doesNotExist());
}
@Test
@MediumTest
public void testMoveUpMenuItem() throws Exception {
......@@ -1599,6 +1656,13 @@ public class BookmarkTest {
() -> mBookmarkModel.addBookmark(mBookmarkModel.getDefaultFolder(), 0, title, url));
}
private BookmarkId addReadingListBookmark(final String title, final String url)
throws ExecutionException {
readPartnerBookmarks();
return TestThreadUtils.runOnUiThreadBlocking(
() -> mBookmarkModel.addToReadingList(title, url));
}
private BookmarkId addFolder(final String title) throws ExecutionException {
readPartnerBookmarks();
return TestThreadUtils.runOnUiThreadBlocking(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment