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