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

Read later: Use the reading list folder icon.

Use the Reading list folder icon on bookmark bottom sheet and main
bookmark UI.

Bug: 1149664
Change-Id: I4a28f62df8f678a1a72c422576b76b5ffdc42eea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553341
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832497}
parent 694169f9
...@@ -30,7 +30,7 @@ public class BookmarkFolderRow extends BookmarkRow { ...@@ -30,7 +30,7 @@ public class BookmarkFolderRow extends BookmarkRow {
@Override @Override
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext())); setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext(), BookmarkType.NORMAL));
} }
// BookmarkRow implementation. // BookmarkRow implementation.
...@@ -45,7 +45,7 @@ public class BookmarkFolderRow extends BookmarkRow { ...@@ -45,7 +45,7 @@ public class BookmarkFolderRow extends BookmarkRow {
BookmarkItem item = super.setBookmarkId(bookmarkId, location); BookmarkItem item = super.setBookmarkId(bookmarkId, location);
mTitleView.setText(item.getTitle()); mTitleView.setText(item.getTitle());
// Set description. // Set description and icon.
if (item.getId().getType() == BookmarkType.READING_LIST) { if (item.getId().getType() == BookmarkType.READING_LIST) {
int unreadCount = mDelegate.getModel().getUnreadCount(bookmarkId); int unreadCount = mDelegate.getModel().getUnreadCount(bookmarkId);
mDescriptionView.setText(unreadCount > 0 mDescriptionView.setText(unreadCount > 0
...@@ -60,12 +60,16 @@ public class BookmarkFolderRow extends BookmarkRow { ...@@ -60,12 +60,16 @@ public class BookmarkFolderRow extends BookmarkRow {
R.plurals.bookmarks_count, childCount, childCount) R.plurals.bookmarks_count, childCount, childCount)
: getResources().getString(R.string.no_bookmarks)); : getResources().getString(R.string.no_bookmarks));
} }
setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext(), item.getId().getType()));
return item; return item;
} }
@Override @Override
protected ColorStateList getDefaultStartIconTint() { protected ColorStateList getDefaultStartIconTint() {
@BookmarkType
int type = (mBookmarkId == null) ? BookmarkType.NORMAL : mBookmarkId.getType();
return AppCompatResources.getColorStateList( return AppCompatResources.getColorStateList(
getContext(), BookmarkUtils.getFolderIconTint()); getContext(), BookmarkUtils.getFolderIconTint(type));
} }
} }
...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.SynchronousInitializationActivity; ...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.SynchronousInitializationActivity;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkModelObserver; import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkModelObserver;
import org.chromium.components.bookmarks.BookmarkId; import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.bookmarks.BookmarkType;
import org.chromium.components.browser_ui.widget.selectable_list.SelectableItemView; import org.chromium.components.browser_ui.widget.selectable_list.SelectableItemView;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -365,7 +366,7 @@ public class BookmarkFolderSelectActivity extends SynchronousInitializationActiv ...@@ -365,7 +366,7 @@ public class BookmarkFolderSelectActivity extends SynchronousInitializationActiv
Drawable iconDrawable; Drawable iconDrawable;
if (entry.mType == FolderListEntry.TYPE_NORMAL) { if (entry.mType == FolderListEntry.TYPE_NORMAL) {
iconDrawable = BookmarkUtils.getFolderIcon(view.getContext()); iconDrawable = BookmarkUtils.getFolderIcon(view.getContext(), BookmarkType.NORMAL);
} else { } else {
// For new folder, start_icon is different. // For new folder, start_icon is different.
VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create( VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(
......
...@@ -8,6 +8,7 @@ import android.app.Activity; ...@@ -8,6 +8,7 @@ import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.provider.Browser; import android.provider.Browser;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -37,6 +38,7 @@ import org.chromium.components.bookmarks.BookmarkType; ...@@ -37,6 +38,7 @@ import org.chromium.components.bookmarks.BookmarkType;
import org.chromium.components.browser_ui.widget.TintedDrawable; import org.chromium.components.browser_ui.widget.TintedDrawable;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.feature_engagement.EventConstants; import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
...@@ -301,18 +303,25 @@ public class BookmarkUtils { ...@@ -301,18 +303,25 @@ public class BookmarkUtils {
/** /**
* @param context {@link Context} used to retrieve the drawable. * @param context {@link Context} used to retrieve the drawable.
* @return A {@link TintedDrawable} to use for displaying bookmark folders. * @param type The bookmark type of the folder.
* @return A {@link Drawable} to use for displaying bookmark folders.
*/ */
public static TintedDrawable getFolderIcon(Context context) { public static Drawable getFolderIcon(Context context, @BookmarkType int type) {
if (type == BookmarkType.READING_LIST) {
return UiUtils.getTintedDrawable(
context, R.drawable.ic_reading_list_folder, getFolderIconTint(type));
}
return TintedDrawable.constructTintedDrawable( return TintedDrawable.constructTintedDrawable(
context, R.drawable.ic_folder_blue_24dp, getFolderIconTint()); context, R.drawable.ic_folder_blue_24dp, getFolderIconTint(type));
} }
/** /**
* @param type The bookmark type.
* @return The tint used on the bookmark folder icon. * @return The tint used on the bookmark folder icon.
*/ */
public static int getFolderIconTint() { public static int getFolderIconTint(@BookmarkType int type) {
return R.color.default_icon_color_tint_list; return (type == BookmarkType.READING_LIST) ? R.color.default_icon_color_blue
: R.color.default_icon_color_tint_list;
} }
private static void openUrl(Context context, String url, ComponentName componentName) { private static void openUrl(Context context, String url, ComponentName componentName) {
......
...@@ -11,6 +11,7 @@ import android.view.View; ...@@ -11,6 +11,7 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.util.Pair;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
...@@ -96,10 +97,15 @@ public class BookmarkBottomSheetCoordinator { ...@@ -96,10 +97,15 @@ public class BookmarkBottomSheetCoordinator {
// Build the model for a single item in the bookmark bottom sheet. // Build the model for a single item in the bookmark bottom sheet.
private PropertyModel buildItemModel(BookmarkItem bookmarkItem) { private PropertyModel buildItemModel(BookmarkItem bookmarkItem) {
@BookmarkType
int type = bookmarkItem.getId().getType();
PropertyModel model = PropertyModel model =
new PropertyModel.Builder(BookmarkBottomSheetItemProperties.ALL_KEYS) new PropertyModel.Builder(BookmarkBottomSheetItemProperties.ALL_KEYS)
.with(BookmarkBottomSheetItemProperties.TITLE, bookmarkItem.getTitle()) .with(BookmarkBottomSheetItemProperties.TITLE, bookmarkItem.getTitle())
.with(BookmarkBottomSheetItemProperties.SUBTITLE, getSubtitle(bookmarkItem)) .with(BookmarkBottomSheetItemProperties.SUBTITLE, getSubtitle(bookmarkItem))
.with(BookmarkBottomSheetItemProperties.ICON_DRAWABLE_AND_COLOR,
new Pair<>(BookmarkUtils.getFolderIcon(mContext, type),
BookmarkUtils.getFolderIconTint(type)))
.with(BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER, .with(BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER,
() -> onClick(bookmarkItem)) () -> onClick(bookmarkItem))
.build(); .build();
......
...@@ -5,20 +5,26 @@ ...@@ -5,20 +5,26 @@
package org.chromium.chrome.browser.bookmarks.bottomsheet; package org.chromium.chrome.browser.bookmarks.bottomsheet;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.util.Pair;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.bookmarks.BookmarkRow; import org.chromium.chrome.browser.bookmarks.BookmarkRow;
import org.chromium.chrome.browser.bookmarks.BookmarkUtils;
/** /**
* Represents a folder row in bookmark bottom sheet. * Represents a folder row in bookmark bottom sheet.
*/ */
class BookmarkBottomSheetFolderRow extends BookmarkRow { class BookmarkBottomSheetFolderRow extends BookmarkRow {
private Runnable mOnClickListener; private Runnable mOnClickListener;
private @ColorRes int mIconColor = R.color.default_icon_color_tint_list;
/** /**
* Constructor for inflating from XML. * Constructor for inflating from XML.
...@@ -35,6 +41,11 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow { ...@@ -35,6 +41,11 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow {
mDescriptionView.setText(subtitle == null ? "" : subtitle); mDescriptionView.setText(subtitle == null ? "" : subtitle);
} }
void setIcon(Pair<Drawable, Integer> drawableAndColor) {
mIconColor = drawableAndColor.second;
setStartIconDrawable(drawableAndColor.first);
}
void setOnClickListener(@NonNull Runnable listener) { void setOnClickListener(@NonNull Runnable listener) {
mOnClickListener = listener; mOnClickListener = listener;
} }
...@@ -48,9 +59,6 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow { ...@@ -48,9 +59,6 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow {
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
mMoreIcon.setVisibility(GONE); mMoreIcon.setVisibility(GONE);
// TODO(xingliu): Load the correct icon.
setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext()));
} }
// BookmarkRow overrides. // BookmarkRow overrides.
...@@ -64,4 +72,9 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow { ...@@ -64,4 +72,9 @@ class BookmarkBottomSheetFolderRow extends BookmarkRow {
public boolean onLongClick(View view) { public boolean onLongClick(View view) {
return false; return false;
} }
@Override
protected ColorStateList getDefaultStartIconTint() {
return AppCompatResources.getColorStateList(getContext(), mIconColor);
}
} }
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
package org.chromium.chrome.browser.bookmarks.bottomsheet; package org.chromium.chrome.browser.bookmarks.bottomsheet;
import android.graphics.drawable.Drawable;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.core.util.Pair;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
...@@ -38,11 +41,20 @@ class BookmarkBottomSheetItemProperties { ...@@ -38,11 +41,20 @@ class BookmarkBottomSheetItemProperties {
static final PropertyModel.ReadableObjectPropertyKey<String> SUBTITLE = static final PropertyModel.ReadableObjectPropertyKey<String> SUBTITLE =
new PropertyModel.ReadableObjectPropertyKey<>(); new PropertyModel.ReadableObjectPropertyKey<>();
/**
* The pair of {@link Drawable} and the color resource id(as Integer) of the bottom sheet item
* icon. e.g. A folder icon and its color resource id.
*/
static final PropertyModel
.ReadableObjectPropertyKey<Pair<Drawable, Integer>> ICON_DRAWABLE_AND_COLOR =
new PropertyModel.ReadableObjectPropertyKey<>();
/** /**
* A callback invoked when the bottom sheet bookmark item is clicked. * A callback invoked when the bottom sheet bookmark item is clicked.
*/ */
static final PropertyModel.ReadableObjectPropertyKey<Runnable> ON_CLICK_LISTENER = static final PropertyModel.ReadableObjectPropertyKey<Runnable> ON_CLICK_LISTENER =
new PropertyModel.ReadableObjectPropertyKey<>(); new PropertyModel.ReadableObjectPropertyKey<>();
static final PropertyKey[] ALL_KEYS = new PropertyKey[] {TITLE, SUBTITLE, ON_CLICK_LISTENER}; static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {TITLE, SUBTITLE, ICON_DRAWABLE_AND_COLOR, ON_CLICK_LISTENER};
} }
...@@ -17,6 +17,8 @@ class BookmarkBottomSheetRowViewBinder { ...@@ -17,6 +17,8 @@ class BookmarkBottomSheetRowViewBinder {
view.setTitle(model.get(BookmarkBottomSheetItemProperties.TITLE)); view.setTitle(model.get(BookmarkBottomSheetItemProperties.TITLE));
} else if (BookmarkBottomSheetItemProperties.SUBTITLE.equals(propertyKey)) { } else if (BookmarkBottomSheetItemProperties.SUBTITLE.equals(propertyKey)) {
view.setSubtitle(model.get(BookmarkBottomSheetItemProperties.SUBTITLE)); view.setSubtitle(model.get(BookmarkBottomSheetItemProperties.SUBTITLE));
} else if (BookmarkBottomSheetItemProperties.ICON_DRAWABLE_AND_COLOR.equals(propertyKey)) {
view.setIcon(model.get(BookmarkBottomSheetItemProperties.ICON_DRAWABLE_AND_COLOR));
} else if (BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER.equals(propertyKey)) { } else if (BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER.equals(propertyKey)) {
view.setOnClickListener(model.get(BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER)); view.setOnClickListener(model.get(BookmarkBottomSheetItemProperties.ON_CLICK_LISTENER));
} }
......
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