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 @@
// Protocol used to relay relevant user interactions from a grid UI.
@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|.
- (void)gridViewController:(GridViewController*)gridViewController
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|.
- (void)gridViewController:(GridViewController*)gridViewController
didCloseItemAtIndex:(NSUInteger)index;
// Tells the receiver that the last item was closed in |gridViewController|.
- (void)lastItemWasClosedInGridViewController:
(GridViewController*)gridViewController;
// Tells the receiver that the first item was added in |gridViewController|.
- (void)firstItemWasAddedInGridViewController:
(GridViewController*)gridViewController;
// Tells the delegate that the the number of items in |gridViewController|
// changed to |count|.
- (void)gridViewController:(GridViewController*)gridViewController
didChangeItemCount:(NSUInteger)count;
@end
// A view controller that contains a grid of items.
......@@ -40,8 +38,6 @@
@property(nonatomic, strong) UIView* emptyStateView;
// Returns YES if the grid has no items.
@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.
@property(nonatomic, assign) GridTheme theme;
// Delegate is informed of user interactions in the grid UI.
......
......@@ -82,6 +82,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self.collectionView selectItemAtIndexPath:CreateIndexPath(self.selectedIndex)
animated:animated
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
......@@ -105,10 +107,6 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
return self.items.count == 0;
}
- (NSUInteger)itemCount {
return self.items.count;
}
- (BOOL)isSelectedCellVisible {
if (self.collectionView.indexPathsForSelectedItems.count == 0)
return NO;
......@@ -205,6 +203,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self.collectionView selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionTop];
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
}
- (void)insertItem:(GridItem*)item
......@@ -216,6 +215,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
};
if (![self isViewVisible]) {
performDataSourceUpdates();
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
return;
}
auto performAllUpdates = ^{
......@@ -228,9 +228,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
if (self.items.count == 1) {
[self.delegate firstItemWasAddedInGridViewController:self];
}
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
};
[self.collectionView performBatchUpdates:performAllUpdates
completion:completion];
......@@ -244,6 +242,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
};
if (![self isViewVisible]) {
performDataSourceUpdates();
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
return;
}
auto performAllUpdates = ^{
......@@ -258,8 +257,8 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
scrollPosition:UICollectionViewScrollPositionNone];
} else {
self.collectionView.backgroundView.hidden = NO;
[self.delegate lastItemWasClosedInGridViewController:self];
}
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
};
[self.collectionView performBatchUpdates:performAllUpdates
completion:completion];
......
......@@ -439,7 +439,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
[self.topToolbar.pageControl addTarget:self
action:@selector(pageControlChanged:)
forControlEvents:UIControlEventValueChanged];
[self updatePageControlItemCounts];
NSArray* constraints = @[
[topToolbar.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[topToolbar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
......@@ -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
// the transition coordinator. Transitions are preferred here since they don't
// interact with the layout system at all.
......@@ -697,18 +689,16 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
} else if (gridViewController == self.incognitoTabsViewController) {
[self.incognitoTabsDelegate closeItemAtIndex:index];
}
[self updatePageControlItemCounts];
}
- (void)lastItemWasClosedInGridViewController:
(GridViewController*)gridViewController {
[self configureButtonsForCurrentPage];
}
- (void)firstItemWasAddedInGridViewController:
(GridViewController*)gridViewController {
- (void)gridViewController:(GridViewController*)gridViewController
didChangeItemCount:(NSUInteger)count {
[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
......@@ -745,7 +735,6 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
// No-op. It is invalid to call insert new tab on remote tabs.
break;
}
[self updatePageControlItemCounts];
}
- (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