1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.chrome.browser.bookmarks; 6 7 import android.content.Context; 8 import android.content.res.ColorStateList; 9 import android.util.AttributeSet; 10 11 import androidx.appcompat.content.res.AppCompatResources; 12 13 import org.chromium.chrome.R; 14 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; 15 import org.chromium.components.bookmarks.BookmarkId; 16 import org.chromium.components.bookmarks.BookmarkType; 17 18 /** 19 * A row view that shows folder info in the bookmarks UI. 20 */ 21 public class BookmarkFolderRow extends BookmarkRow { 22 23 /** 24 * Constructor for inflating from XML. 25 */ BookmarkFolderRow(Context context, AttributeSet attrs)26 public BookmarkFolderRow(Context context, AttributeSet attrs) { 27 super(context, attrs); 28 } 29 30 @Override onFinishInflate()31 protected void onFinishInflate() { 32 super.onFinishInflate(); 33 setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext(), BookmarkType.NORMAL)); 34 } 35 36 // BookmarkRow implementation. 37 38 @Override onClick()39 public void onClick() { 40 mDelegate.openFolder(mBookmarkId); 41 } 42 43 @Override setBookmarkId(BookmarkId bookmarkId, @Location int location)44 BookmarkItem setBookmarkId(BookmarkId bookmarkId, @Location int location) { 45 BookmarkItem item = super.setBookmarkId(bookmarkId, location); 46 mTitleView.setText(item.getTitle()); 47 48 // Set description and icon. 49 if (item.getId().getType() == BookmarkType.READING_LIST) { 50 int unreadCount = mDelegate.getModel().getUnreadCount(bookmarkId); 51 mDescriptionView.setText(unreadCount > 0 52 ? getResources().getQuantityString( 53 R.plurals.reading_list_unread_page_count, unreadCount, 54 unreadCount) 55 : getResources().getString(R.string.reading_list_no_unread_pages)); 56 } else { 57 int childCount = mDelegate.getModel().getTotalBookmarkCount(bookmarkId); 58 mDescriptionView.setText((childCount > 0) 59 ? getResources().getQuantityString( 60 R.plurals.bookmarks_count, childCount, childCount) 61 : getResources().getString(R.string.no_bookmarks)); 62 } 63 64 setStartIconDrawable(BookmarkUtils.getFolderIcon(getContext(), item.getId().getType())); 65 return item; 66 } 67 68 @Override getDefaultStartIconTint()69 protected ColorStateList getDefaultStartIconTint() { 70 @BookmarkType 71 int type = (mBookmarkId == null) ? BookmarkType.NORMAL : mBookmarkId.getType(); 72 return AppCompatResources.getColorStateList( 73 getContext(), BookmarkUtils.getFolderIconTint(type)); 74 } 75 } 76