Commit 33358957 authored by Xing Liu's avatar Xing Liu Committed by Chromium LUCI CQ

Read later: Make showBookmarkManager able to show a specific folder.

BookmarkUtils.showBookmarkManager currently needs a non null activity
to show bookmark manager from most recently visited bookmark folder.

For reading list, we need to open the bookmark UI and directly navigate
to reading list page. Also when clicking from a notification, no
activity is provided, we need to start the bookmark UI from application
context.

Bug: 1139073
Change-Id: I81bf5ce1e46c41c57c8b0f34ffdabe250540c515
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2576081
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834414}
parent dea9aceb
......@@ -18,6 +18,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
......@@ -248,25 +249,56 @@ public class BookmarkUtils {
* @param activity An activity to start the manager with.
*/
public static void showBookmarkManager(Activity activity) {
showBookmarkManager(activity, null);
}
/**
* Shows bookmark main UI.
* @param activity An activity to start the manager with. If null, the bookmark manager will be
* started as a new task.
* @param folderId The bookmark folder to open. If null, the bookmark manager will open the most
* recent folder.
*/
public static void showBookmarkManager(
@Nullable Activity activity, @Nullable BookmarkId folderId) {
ThreadUtils.assertOnUiThread();
String url = getFirstUrlToLoad(activity);
Context context = activity == null ? ContextUtils.getApplicationContext() : activity;
String url = getFirstUrlToLoad(context, folderId);
if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(activity)) {
openUrl(activity, url, activity.getComponentName());
} else {
Intent intent = new Intent(activity, BookmarkActivity.class);
intent.setData(Uri.parse(url));
// Tablet.
if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(context)) {
openUrl(context, url, activity == null ? null : activity.getComponentName());
return;
}
// Phone.
Intent intent = new Intent(context, BookmarkActivity.class);
intent.setData(Uri.parse(url));
if (activity != null) {
// Start from an existing activity.
intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
activity.startActivity(intent);
} else {
// Start a new task.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentHandler.startActivityForTrustedIntent(intent);
}
}
/**
* The initial url the bookmark manager shows depends some experiments we run.
* @return the bookmark folder URL to open.
*/
private static String getFirstUrlToLoad(Context context) {
String lastUsedUrl = getLastUsedUrl(context);
return TextUtils.isEmpty(lastUsedUrl) ? UrlConstants.BOOKMARKS_URL : lastUsedUrl;
private static String getFirstUrlToLoad(Context context, @Nullable BookmarkId folderId) {
String url;
if (folderId == null) {
// Load most recently visited bookmark folder.
url = getLastUsedUrl(context);
} else {
// Load a specific folder.
url = BookmarkUIState.createFolderUrl(folderId).toString();
}
return TextUtils.isEmpty(url) ? UrlConstants.BOOKMARKS_URL : url;
}
/**
......@@ -337,7 +369,8 @@ public class BookmarkUtils {
"Bookmarks.OpenBookmarkType", bookmarkId.getType(), BookmarkType.LAST + 1);
BookmarkItem bookmarkItem = model.getBookmarkById(bookmarkId);
if (bookmarkItem.getId().getType() == BookmarkType.READING_LIST) {
if (bookmarkItem.getId().getType() == BookmarkType.READING_LIST
&& !bookmarkItem.isFolder()) {
model.setReadStatusForReadingList(bookmarkItem.getUrl(), true);
}
openUrl(context, bookmarkItem.getUrl(), openBookmarkComponentName);
......
......@@ -1642,6 +1642,31 @@ public class BookmarkTest {
waitForEditActivity().finish();
}
@Test
@SmallTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
public void testShowBookmarkManagerReadingListPage() {
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
TestThreadUtils.runOnUiThreadBlocking(
() -> mBookmarkModel.loadEmptyPartnerBookmarkShimForTesting());
BookmarkTestUtil.waitForBookmarkModelLoaded();
if (mActivityTestRule.getActivity().isTablet()) {
TestThreadUtils.runOnUiThreadBlocking(() -> {
BookmarkUtils.showBookmarkManager(
null, new BookmarkId(0, BookmarkType.READING_LIST));
});
} else {
mBookmarkActivity = ApplicationTestUtils.waitForActivityWithClass(
BookmarkActivity.class, Stage.CREATED, () -> {
BookmarkUtils.showBookmarkManager(
null, new BookmarkId(0, BookmarkType.READING_LIST));
});
}
onView(withText("Reading list")).check(matches(isDisplayed()));
}
/**
* Adds a bookmark in the scenario where we have partner bookmarks.
*
......
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