diff --git a/ios/chrome/browser/ui/ntp/feed_management/follow_management_view_controller.mm b/ios/chrome/browser/ui/ntp/feed_management/follow_management_view_controller.mm index b3dba85586d059..8670ad4e934e40 100644 --- a/ios/chrome/browser/ui/ntp/feed_management/follow_management_view_controller.mm +++ b/ios/chrome/browser/ui/ntp/feed_management/follow_management_view_controller.mm @@ -6,7 +6,6 @@ #include "base/mac/foundation_util.h" #import "ios/chrome/browser/net/crurl.h" -#import "ios/chrome/browser/ui/follow/follow_block_types.h" #import "ios/chrome/browser/ui/follow/followed_web_channel.h" #import "ios/chrome/browser/ui/ntp/feed_management/feed_management_navigation_delegate.h" #import "ios/chrome/browser/ui/ntp/feed_management/follow_management_view_delegate.h" @@ -244,17 +243,18 @@ - (void)unfollowTapped { #pragma mark - FollowManagementUIUpdater - (void)removeFollowedWebChannel:(FollowedWebChannel*)channel { - for (id cell in self.tableView.visibleCells) { + for (UITableViewCell* cell in self.tableView.visibleCells) { FollowedWebChannelCell* followedWebChannelCell = base::mac::ObjCCastStrict(cell); if ([followedWebChannelCell.followedWebChannel isEqual:channel]) { NSIndexPath* indexPath = [self.tableView indexPathForCell:cell]; + [followedWebChannelCell stopAnimatingActivityIndicator]; self.lastUnfollowedWebChannelItem = base::mac::ObjCCastStrict( [self.tableViewModel itemAtIndexPath:indexPath]); self.indexPathOfLastUnfollowAttempt = indexPath; - [self deleteItemAtIndexPath:indexPath]; + [self deleteItemAtIndex:indexPath]; return; } } @@ -264,7 +264,7 @@ - (void)addFollowedWebChannel:(FollowedWebChannel*)channel { DCHECK( [self.lastUnfollowedWebChannelItem.followedWebChannel isEqual:channel]); [self addItem:self.lastUnfollowedWebChannelItem - AtIndexPath:self.indexPathOfLastUnfollowAttempt]; + atIndex:self.indexPathOfLastUnfollowAttempt]; } #pragma mark - Helpers @@ -289,55 +289,12 @@ - (void)requestUnfollowWebChannelAtIndexPath:(NSIndexPath*)indexPath { self.indexPathOfLastUnfollowAttempt = indexPath; - FollowedWebChannelItem* followedWebChannelItem = - base::mac::ObjCCastStrict( - [self.tableViewModel itemAtIndexPath:indexPath]); FollowedWebChannelCell* followedWebChannelCell = base::mac::ObjCCastStrict( [self.tableView cellForRowAtIndexPath:indexPath]); [followedWebChannelCell startAnimatingActivityIndicator]; - - __weak FollowManagementViewController* weakSelf = self; - followedWebChannelItem.followedWebChannel.unfollowRequestBlock( - ^(BOOL success) { - [followedWebChannelCell stopAnimatingActivityIndicator]; - if (success) { - // TODO(crbug.com/1296745): Show success snackbar - // with undo button. - weakSelf.lastUnfollowedWebChannelItem = followedWebChannelItem; - [weakSelf deleteItemAtIndexPath:indexPath]; - } else { - // TODO(crbug.com/1296745): Show failure snackbar - // with try again button. - } - }); -} - -- (void)retryUnfollow { - [self.feedMetricsRecorder recordManagementTappedUnfollowTryAgainOnSnackbar]; - [self - requestUnfollowWebChannelAtIndexPath:self.indexPathOfLastUnfollowAttempt]; -} - -- (void)undoUnfollow { - [self.feedMetricsRecorder - recordManagementTappedRefollowAfterUnfollowOnSnackbar]; - - // TODO(crbug.com/1296745): Start spinner over UNDO text in snackbar. - FollowedWebChannelItem* unfollowedItem = self.lastUnfollowedWebChannelItem; - __weak FollowManagementViewController* weakSelf = self; - unfollowedItem.followedWebChannel.refollowRequestBlock(^(BOOL success) { - // TODO(crbug.com/1296745): Stop spinner over UNDO text in snackbar. - if (success) { - [weakSelf reinsertLastUnfollowedItem]; - } else { - // TODO(crbug.com/1296745): Show undo failure snackbar. - } - }); } -#pragma mark - Helpers - - (void)showOrHideEmptyTableViewBackground { TableViewModel* model = self.tableViewModel; NSInteger section = @@ -355,7 +312,7 @@ - (void)showOrHideEmptyTableViewBackground { } // Deletes item at |indexPath| from both model and UI. -- (void)deleteItemAtIndexPath:(NSIndexPath*)indexPath { +- (void)deleteItemAtIndex:(NSIndexPath*)indexPath { TableViewModel* model = self.tableViewModel; NSInteger sectionID = [model sectionIdentifierForSectionIndex:indexPath.section]; @@ -369,8 +326,7 @@ - (void)deleteItemAtIndexPath:(NSIndexPath*)indexPath { [self showOrHideEmptyTableViewBackground]; } -- (void)addItem:(FollowedWebChannelItem*)item - AtIndexPath:(NSIndexPath*)indexPath { +- (void)addItem:(FollowedWebChannelItem*)item atIndex:(NSIndexPath*)indexPath { TableViewModel* model = self.tableViewModel; NSInteger sectionID = [model sectionIdentifierForSectionIndex:indexPath.section]; @@ -385,23 +341,4 @@ - (void)addItem:(FollowedWebChannelItem*)item [self showOrHideEmptyTableViewBackground]; } -// Reinserts last unfollowed item into both model and UI. -- (void)reinsertLastUnfollowedItem { - TableViewModel* model = self.tableViewModel; - NSIndexPath* indexPath = self.indexPathOfLastUnfollowAttempt; - - NSInteger sectionID = - [model sectionIdentifierForSectionIndex:indexPath.section]; - NSUInteger index = [model indexInItemTypeForIndexPath:indexPath]; - - [model insertItem:self.lastUnfollowedWebChannelItem - inSectionWithIdentifier:sectionID - atIndex:index]; - [self.tableView insertRowsAtIndexPaths:@[ indexPath ] - withRowAnimation:UITableViewRowAnimationAutomatic]; - self.lastUnfollowedWebChannelItem = nil; - self.indexPathOfLastUnfollowAttempt = nil; - [self showOrHideEmptyTableViewBackground]; -} - @end diff --git a/ios/showcase/follow/sc_follow_view_controller.mm b/ios/showcase/follow/sc_follow_view_controller.mm index bb427516b63db8..bf440c5c69eddf 100644 --- a/ios/showcase/follow/sc_follow_view_controller.mm +++ b/ios/showcase/follow/sc_follow_view_controller.mm @@ -7,7 +7,6 @@ #import "ios/chrome/browser/net/crurl.h" #import "ios/chrome/browser/ui/follow/first_follow_favicon_data_source.h" #import "ios/chrome/browser/ui/follow/first_follow_view_controller.h" -#import "ios/chrome/browser/ui/follow/follow_block_types.h" #import "ios/chrome/browser/ui/follow/followed_web_channel.h" #import "ios/chrome/browser/ui/icons/chrome_symbol.h" #import "ios/chrome/browser/ui/ntp/feed_management/feed_management_follow_delegate.h" @@ -186,22 +185,6 @@ - (FollowedWebChannel*)createWebChannelWithTitle:(NSString*)title { channel.available = YES; channel.faviconURL = [[CrURL alloc] initWithNSURL:[NSURL URLWithString:kExampleFaviconURL]]; - - __weak FollowedWebChannel* weakChannel = channel; - channel.unfollowRequestBlock = ^(RequestCompletionBlock completion) { - // This mimics a successful unfollow on the server. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), - dispatch_get_main_queue(), ^{ - [self.followManagementUIUpdater - removeFollowedWebChannel:weakChannel]; - }); - // This mimics refollowing after a few seconds. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 13 * NSEC_PER_SEC), - dispatch_get_main_queue(), ^{ - [self.followManagementUIUpdater - addFollowedWebChannel:weakChannel]; - }); - }; return channel; }