Commit d89dd967 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Update tab counts in grid via delegate

Bug: 804552
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I183368403e1977c28dd0696532feff849fcbf0df
Reviewed-on: https://chromium-review.googlesource.com/966625
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543751}
parent 1a319783
...@@ -16,20 +16,18 @@ ...@@ -16,20 +16,18 @@
// Protocol used to relay relevant user interactions from a grid UI. // Protocol used to relay relevant user interactions from a grid UI.
@protocol GridViewControllerDelegate @protocol GridViewControllerDelegate
// Tells the receiver that the item at |index| was selected in // Tells the delegate that the item at |index| was selected in
// |gridViewController|. // |gridViewController|.
- (void)gridViewController:(GridViewController*)gridViewController - (void)gridViewController:(GridViewController*)gridViewController
didSelectItemAtIndex:(NSUInteger)index; didSelectItemAtIndex:(NSUInteger)index;
// Tells the receiver that the item at |index| was closed in // Tells the delegate that the item at |index| was closed in
// |gridViewController|. // |gridViewController|.
- (void)gridViewController:(GridViewController*)gridViewController - (void)gridViewController:(GridViewController*)gridViewController
didCloseItemAtIndex:(NSUInteger)index; didCloseItemAtIndex:(NSUInteger)index;
// Tells the receiver that the last item was closed in |gridViewController|. // Tells the delegate that the the number of items in |gridViewController|
- (void)lastItemWasClosedInGridViewController: // changed to |count|.
(GridViewController*)gridViewController; - (void)gridViewController:(GridViewController*)gridViewController
// Tells the receiver that the first item was added in |gridViewController|. didChangeItemCount:(NSUInteger)count;
- (void)firstItemWasAddedInGridViewController:
(GridViewController*)gridViewController;
@end @end
// A view controller that contains a grid of items. // A view controller that contains a grid of items.
...@@ -40,8 +38,6 @@ ...@@ -40,8 +38,6 @@
@property(nonatomic, strong) UIView* emptyStateView; @property(nonatomic, strong) UIView* emptyStateView;
// Returns YES if the grid has no items. // Returns YES if the grid has no items.
@property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty; @property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty;
// The number of items in the grid. Not all of the items may be visible.
@property(nonatomic, readonly) NSUInteger itemCount;
// The visual look of the grid. // The visual look of the grid.
@property(nonatomic, assign) GridTheme theme; @property(nonatomic, assign) GridTheme theme;
// Delegate is informed of user interactions in the grid UI. // Delegate is informed of user interactions in the grid UI.
......
...@@ -82,6 +82,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -82,6 +82,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self.collectionView selectItemAtIndexPath:CreateIndexPath(self.selectedIndex) [self.collectionView selectItemAtIndexPath:CreateIndexPath(self.selectedIndex)
animated:animated animated:animated
scrollPosition:UICollectionViewScrollPositionTop]; scrollPosition:UICollectionViewScrollPositionTop];
// Update the delegate, in case it wasn't set when |items| was populated.
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
} }
#pragma mark - Public #pragma mark - Public
...@@ -105,10 +107,6 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -105,10 +107,6 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
return self.items.count == 0; return self.items.count == 0;
} }
- (NSUInteger)itemCount {
return self.items.count;
}
- (BOOL)isSelectedCellVisible { - (BOOL)isSelectedCellVisible {
if (self.collectionView.indexPathsForSelectedItems.count == 0) if (self.collectionView.indexPathsForSelectedItems.count == 0)
return NO; return NO;
...@@ -205,6 +203,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -205,6 +203,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self.collectionView selectItemAtIndexPath:CreateIndexPath(selectedIndex) [self.collectionView selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES animated:YES
scrollPosition:UICollectionViewScrollPositionTop]; scrollPosition:UICollectionViewScrollPositionTop];
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
} }
- (void)insertItem:(GridItem*)item - (void)insertItem:(GridItem*)item
...@@ -216,6 +215,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -216,6 +215,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
}; };
if (![self isViewVisible]) { if (![self isViewVisible]) {
performDataSourceUpdates(); performDataSourceUpdates();
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
return; return;
} }
auto performAllUpdates = ^{ auto performAllUpdates = ^{
...@@ -228,9 +228,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -228,9 +228,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
selectItemAtIndexPath:CreateIndexPath(selectedIndex) selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES animated:YES
scrollPosition:UICollectionViewScrollPositionNone]; scrollPosition:UICollectionViewScrollPositionNone];
if (self.items.count == 1) { [self.delegate gridViewController:self didChangeItemCount:self.items.count];
[self.delegate firstItemWasAddedInGridViewController:self];
}
}; };
[self.collectionView performBatchUpdates:performAllUpdates [self.collectionView performBatchUpdates:performAllUpdates
completion:completion]; completion:completion];
...@@ -244,6 +242,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -244,6 +242,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
}; };
if (![self isViewVisible]) { if (![self isViewVisible]) {
performDataSourceUpdates(); performDataSourceUpdates();
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
return; return;
} }
auto performAllUpdates = ^{ auto performAllUpdates = ^{
...@@ -258,8 +257,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -258,8 +257,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
scrollPosition:UICollectionViewScrollPositionNone]; scrollPosition:UICollectionViewScrollPositionNone];
} else { } else {
self.collectionView.backgroundView.hidden = NO; self.collectionView.backgroundView.hidden = NO;
[self.delegate lastItemWasClosedInGridViewController:self];
} }
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
}; };
[self.collectionView performBatchUpdates:performAllUpdates [self.collectionView performBatchUpdates:performAllUpdates
completion:completion]; completion:completion];
......
...@@ -439,7 +439,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -439,7 +439,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
[self.topToolbar.pageControl addTarget:self [self.topToolbar.pageControl addTarget:self
action:@selector(pageControlChanged:) action:@selector(pageControlChanged:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];
[self updatePageControlItemCounts];
NSArray* constraints = @[ NSArray* constraints = @[
[topToolbar.topAnchor constraintEqualToAnchor:self.view.topAnchor], [topToolbar.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[topToolbar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], [topToolbar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
...@@ -632,13 +631,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -632,13 +631,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
} }
} }
- (void)updatePageControlItemCounts {
self.topToolbar.pageControl.incognitoTabCount =
self.incognitoTabsViewController.itemCount;
self.topToolbar.pageControl.regularTabCount =
self.regularTabsViewController.itemCount;
}
// Translates the toolbar views offscreen and then animates them back in using // Translates the toolbar views offscreen and then animates them back in using
// the transition coordinator. Transitions are preferred here since they don't // the transition coordinator. Transitions are preferred here since they don't
// interact with the layout system at all. // interact with the layout system at all.
...@@ -697,18 +689,16 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -697,18 +689,16 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
} else if (gridViewController == self.incognitoTabsViewController) { } else if (gridViewController == self.incognitoTabsViewController) {
[self.incognitoTabsDelegate closeItemAtIndex:index]; [self.incognitoTabsDelegate closeItemAtIndex:index];
} }
[self updatePageControlItemCounts];
}
- (void)lastItemWasClosedInGridViewController:
(GridViewController*)gridViewController {
[self configureButtonsForCurrentPage];
} }
- (void)firstItemWasAddedInGridViewController: - (void)gridViewController:(GridViewController*)gridViewController
(GridViewController*)gridViewController { didChangeItemCount:(NSUInteger)count {
[self configureButtonsForCurrentPage]; [self configureButtonsForCurrentPage];
[self updatePageControlItemCounts]; if (gridViewController == self.regularTabsViewController) {
self.topToolbar.pageControl.regularTabCount = count;
} else if (gridViewController == self.incognitoTabsViewController) {
self.topToolbar.pageControl.incognitoTabCount = count;
}
} }
#pragma mark - Control actions #pragma mark - Control actions
...@@ -745,7 +735,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -745,7 +735,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
// No-op. It is invalid to call insert new tab on remote tabs. // No-op. It is invalid to call insert new tab on remote tabs.
break; break;
} }
[self updatePageControlItemCounts];
} }
- (void)pageControlChanged:(id)sender { - (void)pageControlChanged:(id)sender {
......
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