Commit 2e261dbf authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Remove TextButtonItemDelegate

Instead directly link button action method to method in tableview in cellForRowAtIndexPath

Change-Id: Ic571e8e49190e55bcb86277f2a4846f7b7088dc3
Reviewed-on: https://chromium-review.googlesource.com/1120844
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571950}
parent a4ba4c07
...@@ -104,7 +104,6 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -104,7 +104,6 @@ const int kRecentlyClosedTabsSectionIndex = 0;
@interface RecentTabsTableViewController ()<SigninPromoViewConsumer, @interface RecentTabsTableViewController ()<SigninPromoViewConsumer,
SigninPresenter, SigninPresenter,
SyncPresenter, SyncPresenter,
TextButtonItemDelegate,
UIGestureRecognizerDelegate> { UIGestureRecognizerDelegate> {
std::unique_ptr<synced_sessions::SyncedSessions> _syncedSessions; std::unique_ptr<synced_sessions::SyncedSessions> _syncedSessions;
} }
...@@ -426,7 +425,6 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -426,7 +425,6 @@ const int kRecentlyClosedTabsSectionIndex = 0;
l10n_util::GetNSString(IDS_IOS_OPEN_TABS_SYNC_IS_OFF_MOBILE); l10n_util::GetNSString(IDS_IOS_OPEN_TABS_SYNC_IS_OFF_MOBILE);
signinSyncOffItem.buttonText = signinSyncOffItem.buttonText =
l10n_util::GetNSString(IDS_IOS_OPEN_TABS_ENABLE_SYNC_MOBILE); l10n_util::GetNSString(IDS_IOS_OPEN_TABS_ENABLE_SYNC_MOBILE);
signinSyncOffItem.delegate = self;
[self.tableViewModel addItem:signinSyncOffItem [self.tableViewModel addItem:signinSyncOffItem
toSectionWithIdentifier:SectionIdentifierOtherDevices]; toSectionWithIdentifier:SectionIdentifierOtherDevices];
} }
...@@ -659,6 +657,14 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -659,6 +657,14 @@ const int kRecentlyClosedTabsSectionIndex = 0;
if (itemTypeSelected == ItemTypeOtherDevicesNoSessions) { if (itemTypeSelected == ItemTypeOtherDevicesNoSessions) {
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
} }
// Set button action method for ItemTypeOtherDevicesSyncOff.
if (itemTypeSelected == ItemTypeOtherDevicesSyncOff) {
TableViewTextButtonCell* tableViewTextButtonCell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
[tableViewTextButtonCell.button addTarget:self
action:@selector(updateSyncState)
forControlEvents:UIControlEventTouchUpInside];
}
return cell; return cell;
} }
...@@ -1093,9 +1099,15 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -1093,9 +1099,15 @@ const int kRecentlyClosedTabsSectionIndex = 0;
[self.dispatcher showSyncPassphraseSettingsFromViewController:self]; [self.dispatcher showSyncPassphraseSettingsFromViewController:self];
} }
#pragma mark - TextButtonItemDelegate #pragma mark - SigninPresenter
- (void)showSignin:(ShowSigninCommand*)command {
[self.dispatcher showSignin:command baseViewController:self];
}
#pragma mark - Private Helpers
- (void)performButtonAction { - (void)updateSyncState {
SyncSetupService::SyncServiceState syncState = SyncSetupService::SyncServiceState syncState =
GetSyncStateForBrowserState(_browserState); GetSyncStateForBrowserState(_browserState);
if (ShouldShowSyncSignin(syncState)) { if (ShouldShowSyncSignin(syncState)) {
...@@ -1107,10 +1119,4 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -1107,10 +1119,4 @@ const int kRecentlyClosedTabsSectionIndex = 0;
} }
} }
#pragma mark - SigninPresenter
- (void)showSignin:(ShowSigninCommand*)command {
[self.dispatcher showSignin:command baseViewController:self];
}
@end @end
...@@ -30,8 +30,7 @@ class ChromeBrowserState; ...@@ -30,8 +30,7 @@ class ChromeBrowserState;
} }
@interface ClearBrowsingDataTableViewController ()< @interface ClearBrowsingDataTableViewController ()<
TableViewTextLinkCellDelegate, TableViewTextLinkCellDelegate>
TextButtonItemDelegate>
// TODO(crbug.com/850699): remove direct dependency and replace with // TODO(crbug.com/850699): remove direct dependency and replace with
// delegate. // delegate.
...@@ -121,7 +120,10 @@ class ChromeBrowserState; ...@@ -121,7 +120,10 @@ class ChromeBrowserState;
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cellToReturn); base::mac::ObjCCastStrict<TableViewTextButtonCell>(cellToReturn);
tableViewTextButtonCell.selectionStyle = tableViewTextButtonCell.selectionStyle =
UITableViewCellSelectionStyleNone; UITableViewCellSelectionStyleNone;
tableViewTextButtonCell.delegate = self; [tableViewTextButtonCell.button
addTarget:self
action:@selector(showClearBrowsingDataAlertController)
forControlEvents:UIControlEventTouchUpInside];
break; break;
} }
case ItemTypeDataTypeBrowsingHistory: case ItemTypeDataTypeBrowsingHistory:
...@@ -178,9 +180,9 @@ class ChromeBrowserState; ...@@ -178,9 +180,9 @@ class ChromeBrowserState;
[self.localDispatcher openURL:copiedURL]; [self.localDispatcher openURL:copiedURL];
} }
#pragma mark - TextButtonItemDelegate #pragma mark - Private Helpers
- (void)performButtonAction { - (void)showClearBrowsingDataAlertController {
BrowsingDataRemoveMask dataTypeMaskToRemove = BrowsingDataRemoveMask dataTypeMaskToRemove =
BrowsingDataRemoveMask::REMOVE_NOTHING; BrowsingDataRemoveMask::REMOVE_NOTHING;
NSArray* dataTypeItems = [self.tableViewModel NSArray* dataTypeItems = [self.tableViewModel
......
...@@ -7,18 +7,10 @@ ...@@ -7,18 +7,10 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
@protocol TextButtonItemDelegate<NSObject>
// Delegates an action to be performed by the presenter.
- (void)performButtonAction;
@end
// TableViewTextButtonItem contains the model for // TableViewTextButtonItem contains the model for
// TableViewTextButtonCell. // TableViewTextButtonCell.
@interface TableViewTextButtonItem : TableViewItem @interface TableViewTextButtonItem : TableViewItem
// EnableSyncActionDelegate to perform TableViewTextButtonCell actions.
@property(nonatomic, weak) id<TextButtonItemDelegate> delegate;
// Text being displayed above the button. // Text being displayed above the button.
@property(nonatomic, readwrite, strong) NSString* text; @property(nonatomic, readwrite, strong) NSString* text;
// Text for cell button. // Text for cell button.
...@@ -33,11 +25,9 @@ ...@@ -33,11 +25,9 @@
// laid out vertically and centered. // laid out vertically and centered.
@interface TableViewTextButtonCell : UITableViewCell @interface TableViewTextButtonCell : UITableViewCell
// Delegate used to show sync settings options.
@property(nonatomic, weak) id<TextButtonItemDelegate> delegate;
// Cell text information. // Cell text information.
@property(nonatomic, strong) UILabel* textLabel; @property(nonatomic, strong) UILabel* textLabel;
// Action button. // Action button. Note: Set action method in the TableView datasource method.
@property(nonatomic, strong) UIButton* button; @property(nonatomic, strong) UIButton* button;
@end @end
......
...@@ -33,7 +33,6 @@ const CGFloat buttonCornerRadius = 8; ...@@ -33,7 +33,6 @@ const CGFloat buttonCornerRadius = 8;
@implementation TableViewTextButtonItem @implementation TableViewTextButtonItem
@synthesize buttonBackgroundColor = _buttonBackgroundColor; @synthesize buttonBackgroundColor = _buttonBackgroundColor;
@synthesize buttonText = _buttonText; @synthesize buttonText = _buttonText;
@synthesize delegate = _delegate;
@synthesize text = _text; @synthesize text = _text;
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
...@@ -49,7 +48,6 @@ const CGFloat buttonCornerRadius = 8; ...@@ -49,7 +48,6 @@ const CGFloat buttonCornerRadius = 8;
[super configureCell:tableCell withStyler:styler]; [super configureCell:tableCell withStyler:styler];
TableViewTextButtonCell* cell = TableViewTextButtonCell* cell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(tableCell); base::mac::ObjCCastStrict<TableViewTextButtonCell>(tableCell);
cell.delegate = self.delegate;
cell.textLabel.text = self.text; cell.textLabel.text = self.text;
[cell.button setTitle:self.buttonText forState:UIControlStateNormal]; [cell.button setTitle:self.buttonText forState:UIControlStateNormal];
cell.button.backgroundColor = self.buttonBackgroundColor cell.button.backgroundColor = self.buttonBackgroundColor
...@@ -61,7 +59,6 @@ const CGFloat buttonCornerRadius = 8; ...@@ -61,7 +59,6 @@ const CGFloat buttonCornerRadius = 8;
@end @end
@implementation TableViewTextButtonCell @implementation TableViewTextButtonCell
@synthesize delegate = _delegate;
@synthesize textLabel = _textLabel; @synthesize textLabel = _textLabel;
@synthesize button = _button; @synthesize button = _button;
...@@ -90,9 +87,6 @@ const CGFloat buttonCornerRadius = 8; ...@@ -90,9 +87,6 @@ const CGFloat buttonCornerRadius = 8;
self.button.contentEdgeInsets = UIEdgeInsetsMake( self.button.contentEdgeInsets = UIEdgeInsetsMake(
buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset, buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset,
buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset); buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset);
[self.button addTarget:self
action:@selector(performButtonAction)
forControlEvents:UIControlEventTouchUpInside];
// Vertical stackView to hold label and button. // Vertical stackView to hold label and button.
UIStackView* verticalStackView = [[UIStackView alloc] UIStackView* verticalStackView = [[UIStackView alloc]
...@@ -123,10 +117,4 @@ const CGFloat buttonCornerRadius = 8; ...@@ -123,10 +117,4 @@ const CGFloat buttonCornerRadius = 8;
return self; return self;
} }
#pragma mark - TextButtonItemDelegate
- (void)performButtonAction {
[self.delegate performButtonAction];
}
@end @end
...@@ -20,20 +20,15 @@ namespace { ...@@ -20,20 +20,15 @@ namespace {
using TableViewTextButtonItemTest = PlatformTest; using TableViewTextButtonItemTest = PlatformTest;
} }
// Tests that the UILabels and delegate are set properly after a call to // Tests that the UILabels are set properly after a call to |configureCell:|.
// |configureCell:|.
TEST_F(TableViewTextButtonItemTest, SetProperties) { TEST_F(TableViewTextButtonItemTest, SetProperties) {
NSString* text = @"You need to do something."; NSString* text = @"You need to do something.";
NSString* buttonText = @"Tap to do something."; NSString* buttonText = @"Tap to do something.";
id<TextButtonItemDelegate> mock_delegate =
[OCMockObject mockForProtocol:@protocol(TextButtonItemDelegate)];
TableViewTextButtonItem* item = TableViewTextButtonItem* item =
[[TableViewTextButtonItem alloc] initWithType:0]; [[TableViewTextButtonItem alloc] initWithType:0];
item.text = text; item.text = text;
item.buttonText = buttonText; item.buttonText = buttonText;
item.delegate = mock_delegate;
id cell = [[[item cellClass] alloc] init]; id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewTextButtonCell class]]); ASSERT_TRUE([cell isMemberOfClass:[TableViewTextButtonCell class]]);
...@@ -42,31 +37,9 @@ TEST_F(TableViewTextButtonItemTest, SetProperties) { ...@@ -42,31 +37,9 @@ TEST_F(TableViewTextButtonItemTest, SetProperties) {
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell); base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
EXPECT_FALSE(textButtonCell.textLabel.text); EXPECT_FALSE(textButtonCell.textLabel.text);
EXPECT_FALSE(textButtonCell.button.titleLabel.text); EXPECT_FALSE(textButtonCell.button.titleLabel.text);
EXPECT_FALSE(textButtonCell.delegate);
[item configureCell:textButtonCell [item configureCell:textButtonCell
withStyler:[[ChromeTableViewStyler alloc] init]]; withStyler:[[ChromeTableViewStyler alloc] init]];
EXPECT_NSEQ(text, textButtonCell.textLabel.text); EXPECT_NSEQ(text, textButtonCell.textLabel.text);
EXPECT_NSEQ(buttonText, textButtonCell.button.titleLabel.text); EXPECT_NSEQ(buttonText, textButtonCell.button.titleLabel.text);
EXPECT_TRUE(textButtonCell.delegate);
}
// Test that pressing the button invokes delegate.
TEST_F(TableViewTextButtonItemTest, DelegateCalled) {
TableViewTextButtonItem* item =
[[TableViewTextButtonItem alloc] initWithType:0];
id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewTextButtonCell class]]);
TableViewTextButtonCell* textButtonCell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
id<TextButtonItemDelegate> mock_delegate =
[OCMockObject mockForProtocol:@protocol(TextButtonItemDelegate)];
[textButtonCell setDelegate:mock_delegate];
OCMockObject* mock_delegate_obj = (OCMockObject*)mock_delegate;
[[mock_delegate_obj expect] performButtonAction];
UIButton* button = textButtonCell.button;
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
EXPECT_OCMOCK_VERIFY(mock_delegate_obj);
} }
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