Commit b14c4d31 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add number of unread items to the tools menu

This CL adds the number of unread items in the ReadingList to the badge
associated with the ReadingList entry in the tools menu.

Bug: 826304
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Id806406c1e1452793092afdefeb6937051e9bdaf
Reviewed-on: https://chromium-review.googlesource.com/992233
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548024}
parent 76a81eb4
...@@ -16,11 +16,13 @@ source_set("popup_menu") { ...@@ -16,11 +16,13 @@ source_set("popup_menu") {
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/find_in_page", "//ios/chrome/browser/find_in_page",
"//ios/chrome/browser/reading_list",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/activity_services", "//ios/chrome/browser/ui/activity_services",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/popup_menu/cells", "//ios/chrome/browser/ui/popup_menu/cells",
"//ios/chrome/browser/ui/reading_list",
"//ios/chrome/browser/ui/tools_menu/public", "//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
...@@ -96,6 +98,7 @@ source_set("unit_tests") { ...@@ -96,6 +98,7 @@ source_set("unit_tests") {
":popup_menu_ui", ":popup_menu_ui",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/reading_list/core",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/ui/toolbar/test", "//ios/chrome/browser/ui/toolbar/test",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
......
...@@ -164,7 +164,7 @@ const CGFloat kTopMarginBadge = 14; ...@@ -164,7 +164,7 @@ const CGFloat kTopMarginBadge = 14;
- (void)setBadgeNumber:(NSInteger)badgeNumber { - (void)setBadgeNumber:(NSInteger)badgeNumber {
BOOL wasHidden = self.numberBadgeView.hidden; BOOL wasHidden = self.numberBadgeView.hidden;
[self.numberBadgeView setNumber:badgeNumber animated:YES]; [self.numberBadgeView setNumber:badgeNumber animated:NO];
// If the number badge is shown, then the text badge must be hidden. // If the number badge is shown, then the text badge must be hidden.
if (!self.numberBadgeView.hidden && !self.textBadgeView.hidden) { if (!self.numberBadgeView.hidden && !self.textBadgeView.hidden) {
[self setBadgeText:nil]; [self setBadgeText:nil];
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/popup_menu_commands.h" #import "ios/chrome/browser/ui/commands/popup_menu_commands.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_mediator.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_mediator.h"
...@@ -94,7 +95,9 @@ ...@@ -94,7 +95,9 @@
self.mediator = [[PopupMenuMediator alloc] self.mediator = [[PopupMenuMediator alloc]
initWithType:PopupMenuTypeToolsMenu initWithType:PopupMenuTypeToolsMenu
isIncognito:self.browserState->IsOffTheRecord()]; isIncognito:self.browserState->IsOffTheRecord()
readingListModel:ReadingListModelFactory::GetForBrowserState(
self.browserState)];
self.mediator.webStateList = self.webStateList; self.mediator.webStateList = self.webStateList;
self.mediator.popupMenu = tableViewController; self.mediator.popupMenu = tableViewController;
self.mediator.dispatcher = static_cast<id<BrowserCommands>>(self.dispatcher); self.mediator.dispatcher = static_cast<id<BrowserCommands>>(self.dispatcher);
...@@ -113,7 +116,9 @@ ...@@ -113,7 +116,9 @@
self.mediator = [[PopupMenuMediator alloc] self.mediator = [[PopupMenuMediator alloc]
initWithType:PopupMenuTypeTabGrid initWithType:PopupMenuTypeTabGrid
isIncognito:self.browserState->IsOffTheRecord()]; isIncognito:self.browserState->IsOffTheRecord()
readingListModel:ReadingListModelFactory::GetForBrowserState(
self.browserState)];
self.mediator.webStateList = self.webStateList; self.mediator.webStateList = self.webStateList;
self.mediator.popupMenu = tableViewController; self.mediator.popupMenu = tableViewController;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
@protocol BrowserCommands; @protocol BrowserCommands;
@class PopupMenuTableViewController; @class PopupMenuTableViewController;
class ReadingListModel;
class WebStateList; class WebStateList;
// Type of popup menus. // Type of popup menus.
...@@ -25,7 +26,9 @@ typedef NS_ENUM(NSInteger, PopupMenuType) { ...@@ -25,7 +26,9 @@ typedef NS_ENUM(NSInteger, PopupMenuType) {
@interface PopupMenuMediator : NSObject @interface PopupMenuMediator : NSObject
- (instancetype)initWithType:(PopupMenuType)type - (instancetype)initWithType:(PopupMenuType)type
isIncognito:(BOOL)isIncognito NS_DESIGNATED_INITIALIZER; isIncognito:(BOOL)isIncognito
readingListModel:(ReadingListModel*)readingListModel
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// The WebStateList that this mediator listens for any changes on the current // The WebStateList that this mediator listens for any changes on the current
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.h" #import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_tools_item.h" #import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_tools_item.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_delegate.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h"
#include "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h" #include "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
...@@ -51,6 +53,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -51,6 +53,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
@interface PopupMenuMediator ()<CRWWebStateObserver, @interface PopupMenuMediator ()<CRWWebStateObserver,
PopupMenuTableViewControllerCommand, PopupMenuTableViewControllerCommand,
ReadingListMenuNotificationDelegate,
WebStateListObserving> { WebStateListObserving> {
std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
...@@ -69,12 +72,16 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -69,12 +72,16 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
// Whether the popup menu is presented in incognito or not. // Whether the popup menu is presented in incognito or not.
@property(nonatomic, assign) BOOL isIncognito; @property(nonatomic, assign) BOOL isIncognito;
// Items notifying this items of changes happening to the ReadingList model.
@property(nonatomic, strong) ReadingListMenuNotifier* readingListMenuNotifier;
#pragma mark*** Specific Items *** #pragma mark*** Specific Items ***
@property(nonatomic, strong) PopupMenuToolsItem* reloadStop; @property(nonatomic, strong) PopupMenuToolsItem* reloadStop;
@property(nonatomic, strong) PopupMenuToolsItem* readLater; @property(nonatomic, strong) PopupMenuToolsItem* readLater;
@property(nonatomic, strong) PopupMenuToolsItem* findInPage; @property(nonatomic, strong) PopupMenuToolsItem* findInPage;
@property(nonatomic, strong) PopupMenuToolsItem* siteInformation; @property(nonatomic, strong) PopupMenuToolsItem* siteInformation;
@property(nonatomic, strong) PopupMenuToolsItem* readingList;
// Array containing all the nonnull items/ // Array containing all the nonnull items/
@property(nonatomic, strong) NSArray<TableViewItem*>* specificItems; @property(nonatomic, strong) NSArray<TableViewItem*>* specificItems;
...@@ -86,6 +93,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -86,6 +93,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
@synthesize isIncognito = _isIncognito; @synthesize isIncognito = _isIncognito;
@synthesize popupMenu = _popupMenu; @synthesize popupMenu = _popupMenu;
@synthesize dispatcher = _dispatcher; @synthesize dispatcher = _dispatcher;
@synthesize readingListMenuNotifier = _readingListMenuNotifier;
@synthesize type = _type; @synthesize type = _type;
@synthesize webState = _webState; @synthesize webState = _webState;
@synthesize webStateList = _webStateList; @synthesize webStateList = _webStateList;
...@@ -93,15 +101,20 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -93,15 +101,20 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
@synthesize readLater = _readLater; @synthesize readLater = _readLater;
@synthesize findInPage = _findInPage; @synthesize findInPage = _findInPage;
@synthesize siteInformation = _siteInformation; @synthesize siteInformation = _siteInformation;
@synthesize readingList = _readingList;
@synthesize specificItems = _specificItems; @synthesize specificItems = _specificItems;
#pragma mark - Public #pragma mark - Public
- (instancetype)initWithType:(PopupMenuType)type isIncognito:(BOOL)isIncognito { - (instancetype)initWithType:(PopupMenuType)type
isIncognito:(BOOL)isIncognito
readingListModel:(ReadingListModel*)readingListModel {
self = [super init]; self = [super init];
if (self) { if (self) {
_isIncognito = isIncognito; _isIncognito = isIncognito;
_type = type; _type = type;
_readingListMenuNotifier =
[[ReadingListMenuNotifier alloc] initWithReadingList:readingListModel];
_webStateObserver = std::make_unique<web::WebStateObserverBridge>(self); _webStateObserver = std::make_unique<web::WebStateObserverBridge>(self);
_webStateListObserver = std::make_unique<WebStateListObserverBridge>(self); _webStateListObserver = std::make_unique<WebStateListObserverBridge>(self);
} }
...@@ -255,6 +268,8 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -255,6 +268,8 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
[specificItems addObject:self.findInPage]; [specificItems addObject:self.findInPage];
if (self.siteInformation) if (self.siteInformation)
[specificItems addObject:self.siteInformation]; [specificItems addObject:self.siteInformation];
if (self.readingList)
[specificItems addObject:self.readingList];
self.specificItems = specificItems; self.specificItems = specificItems;
} }
return _items; return _items;
...@@ -281,6 +296,21 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -281,6 +296,21 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
}); });
} }
#pragma mark - ReadingListMenuNotificationDelegate Implementation
- (void)unreadCountChanged:(NSInteger)unreadCount {
if (!self.readingList)
return;
self.readingList.badgeNumber = unreadCount;
[self.popupMenu reconfigureCellsForItems:@[ self.readingList ]];
}
- (void)unseenStateChanged:(BOOL)unseenItemsExist {
// TODO(crbug.com/828367): Implement this once the "unseen items effect" is
// defined.
}
#pragma mark - Popup updates (Private) #pragma mark - Popup updates (Private)
// Updates the popup menu to have its state in sync with the current page // Updates the popup menu to have its state in sync with the current page
...@@ -446,9 +476,13 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -446,9 +476,13 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
@"popup_menu_bookmarks", kToolsMenuBookmarksId); @"popup_menu_bookmarks", kToolsMenuBookmarksId);
// Reading List. // Reading List.
TableViewItem* readingList = CreateTableViewItem( self.readingList = CreateTableViewItem(
IDS_IOS_TOOLS_MENU_READING_LIST, PopupMenuActionReadingList, IDS_IOS_TOOLS_MENU_READING_LIST, PopupMenuActionReadingList,
@"popup_menu_reading_list", kToolsMenuReadingListId); @"popup_menu_reading_list", kToolsMenuReadingListId);
self.readingList.badgeNumber =
[self.readingListMenuNotifier readingListUnreadCount];
// TODO(crbug.com/828367): Once the "unseen items effect" is defined,
// implement it.
// Recent Tabs. // Recent Tabs.
TableViewItem* recentTabs = CreateTableViewItem( TableViewItem* recentTabs = CreateTableViewItem(
...@@ -465,7 +499,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -465,7 +499,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
CreateTableViewItem(IDS_IOS_TOOLS_MENU_SETTINGS, PopupMenuActionSettings, CreateTableViewItem(IDS_IOS_TOOLS_MENU_SETTINGS, PopupMenuActionSettings,
@"popup_menu_settings", kToolsMenuSettingsId); @"popup_menu_settings", kToolsMenuSettingsId);
return @[ bookmarks, readingList, recentTabs, history, settings ]; return @[ bookmarks, self.readingList, recentTabs, history, settings ];
} }
// Returns the UserAgentType currently in use. // Returns the UserAgentType currently in use.
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/popup_menu/popup_menu_mediator.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_mediator.h"
#include "base/time/default_clock.h"
#include "components/reading_list/core/reading_list_model_impl.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.h"
#import "ios/chrome/browser/ui/toolbar/test/toolbar_test_navigation_manager.h" #import "ios/chrome/browser/ui/toolbar/test/toolbar_test_navigation_manager.h"
#import "ios/chrome/browser/ui/toolbar/test/toolbar_test_web_state.h" #import "ios/chrome/browser/ui/toolbar/test/toolbar_test_web_state.h"
...@@ -37,12 +39,16 @@ const int kNumberOfWebStates = 3; ...@@ -37,12 +39,16 @@ const int kNumberOfWebStates = 3;
class PopupMenuMediatorTest : public PlatformTest { class PopupMenuMediatorTest : public PlatformTest {
public: public:
PopupMenuMediatorTest() { PopupMenuMediatorTest() {
reading_list_model_.reset(new ReadingListModelImpl(
nullptr, nullptr, base::DefaultClock::GetInstance()));
mediator_incognito_ = mediator_incognito_ =
[[PopupMenuMediator alloc] initWithType:PopupMenuTypeToolsMenu [[PopupMenuMediator alloc] initWithType:PopupMenuTypeToolsMenu
isIncognito:YES]; isIncognito:YES
readingListModel:reading_list_model_.get()];
mediator_non_incognito_ = mediator_non_incognito_ =
[[PopupMenuMediator alloc] initWithType:PopupMenuTypeToolsMenu [[PopupMenuMediator alloc] initWithType:PopupMenuTypeToolsMenu
isIncognito:NO]; isIncognito:NO
readingListModel:reading_list_model_.get()];
popup_menu_ = OCMClassMock([PopupMenuTableViewController class]); popup_menu_ = OCMClassMock([PopupMenuTableViewController class]);
popup_menu_strict_ = popup_menu_strict_ =
OCMStrictClassMock([PopupMenuTableViewController class]); OCMStrictClassMock([PopupMenuTableViewController class]);
...@@ -91,6 +97,7 @@ class PopupMenuMediatorTest : public PlatformTest { ...@@ -91,6 +97,7 @@ class PopupMenuMediatorTest : public PlatformTest {
PopupMenuMediator* mediator_incognito_; PopupMenuMediator* mediator_incognito_;
PopupMenuMediator* mediator_non_incognito_; PopupMenuMediator* mediator_non_incognito_;
std::unique_ptr<ReadingListModelImpl> reading_list_model_;
ToolbarTestWebState* web_state_; ToolbarTestWebState* web_state_;
ToolbarTestNavigationManager* navigation_manager_; ToolbarTestNavigationManager* navigation_manager_;
std::unique_ptr<WebStateList> web_state_list_; std::unique_ptr<WebStateList> web_state_list_;
......
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