Skip to content

Commit 8fcbe74

Browse files
committed
Merge branch 'token-cells'
2 parents a6c7d29 + f3196f9 commit 8fcbe74

File tree

2 files changed

+30
-75
lines changed

2 files changed

+30
-75
lines changed

Authenticator/Classes/OTPTokenCell.m

Lines changed: 28 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
#import "OTPToken+Generation.h"
2929

3030

31-
@interface OTPTokenCell () <UITextFieldDelegate>
31+
@interface OTPTokenCell ()
3232

33-
@property (nonatomic, strong) UITextField *nameLabel;
34-
@property (nonatomic, strong) UITextField *issuerLabel;
33+
@property (nonatomic, strong) UILabel *titleLabel;
3534
@property (nonatomic, strong) UILabel *passwordLabel;
3635
@property (nonatomic, strong) UIButton *nextPasswordButton;
3736

@@ -75,32 +74,23 @@ - (void)createSubviews
7574
{
7675
self.backgroundColor = [UIColor otpBackgroundColor];
7776

78-
self.nameLabel = [UITextField new];
79-
self.nameLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
80-
self.nameLabel.textColor = [UIColor otpForegroundColor];
81-
self.nameLabel.returnKeyType = UIReturnKeyDone;
82-
self.nameLabel.delegate = self;
83-
self.nameLabel.enabled = NO;
84-
85-
self.issuerLabel = [UITextField new];
86-
self.issuerLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15];
87-
self.issuerLabel.textColor = [UIColor otpForegroundColor];
88-
self.issuerLabel.returnKeyType = UIReturnKeyNext;
89-
self.issuerLabel.delegate = self;
90-
self.issuerLabel.enabled = NO;
77+
self.titleLabel = [UILabel new];
78+
self.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
79+
self.titleLabel.textColor = [UIColor otpForegroundColor];
80+
self.titleLabel.textAlignment = NSTextAlignmentCenter;
9181

9282
self.passwordLabel = [UILabel new];
9383
self.passwordLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:50];
9484
self.passwordLabel.textColor = [UIColor otpForegroundColor];
85+
self.passwordLabel.textAlignment = NSTextAlignmentCenter;
9586

96-
[self.contentView addSubview:self.nameLabel];
97-
[self.contentView addSubview:self.issuerLabel];
87+
[self.contentView addSubview:self.titleLabel];
9888
[self.contentView addSubview:self.passwordLabel];
9989

10090
self.nextPasswordButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
10191
self.nextPasswordButton.tintColor = [UIColor otpForegroundColor];
10292
[self.nextPasswordButton addTarget:self action:@selector(generateNextPassword) forControlEvents:UIControlEventTouchUpInside];
103-
self.accessoryView = self.nextPasswordButton;
93+
[self.contentView addSubview:self.nextPasswordButton];
10494
}
10595

10696
- (void)generateNextPassword
@@ -112,24 +102,20 @@ - (void)layoutSubviews
112102
{
113103
[super layoutSubviews];
114104

115-
CGRect insetFrame = CGRectInset(self.contentView.bounds, 10, 5);
105+
CGRect insetFrame = [self convertRect:self.bounds toView:self.contentView];
106+
insetFrame.origin.x = MIN(insetFrame.origin.x, self.contentView.bounds.origin.x);
116107

117108
CGRect frame = insetFrame;
118109
frame.size.height = 20;
119-
frame.size.width = (self.issuerLabel.text.length || self.editing) ? [self.issuerLabel sizeThatFits:frame.size].width : 0;
120-
if (self.editing && frame.size.width < 80) {
121-
frame.size.width = 80;
122-
}
123-
self.issuerLabel.frame = frame;
124-
125-
frame.origin.x += frame.size.width;
126-
frame.size.width = CGRectGetMaxX(insetFrame) - frame.origin.x;
127-
self.nameLabel.frame = frame;
110+
self.titleLabel.frame = frame;
128111

129112
frame = insetFrame;
130113
frame.origin.y += 20;
131-
frame.size.height -= 20;
114+
frame.size.height -= 30;
132115
self.passwordLabel.frame = frame;
116+
117+
self.nextPasswordButton.center = CGPointMake(CGRectGetMaxX(insetFrame) - 25,
118+
CGRectGetMidY(self.passwordLabel.frame));
133119
}
134120

135121

@@ -161,10 +147,18 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
161147

162148
- (void)refresh
163149
{
164-
if (!self.editing) {
165-
self.nameLabel.text = self.token.name;
166-
self.issuerLabel.text = self.token.issuer;
150+
NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] init];
151+
if (self.token.issuer.length) {
152+
[titleString appendAttributedString:[[NSAttributedString alloc] initWithString:self.token.issuer attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Medium" size:15]}]];
153+
}
154+
if (self.token.issuer.length && self.token.name.length) {
155+
[titleString appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
156+
}
157+
if (self.token.name.length) {
158+
[titleString appendAttributedString:[[NSAttributedString alloc] initWithString:self.token.name]];
167159
}
160+
self.titleLabel.attributedText = titleString;
161+
168162
self.passwordLabel.text = self.token.password;
169163
self.nextPasswordButton.hidden = self.token.type != OTPTokenTypeCounter;
170164
}
@@ -176,50 +170,10 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated
176170
{
177171
[super setEditing:editing animated:animated];
178172

179-
self.nameLabel.enabled = editing;
180-
self.issuerLabel.enabled = self.nameLabel.enabled;
181-
182-
NSAttributedString *namePlaceholder, *issuerPlaceholder;
183-
if (editing) {
184-
UIColor *placeholderColor = [[UIColor otpForegroundColor] colorWithAlphaComponent:(CGFloat)0.3];
185-
namePlaceholder = [[NSAttributedString alloc] initWithString:@"Name"
186-
attributes:@{NSForegroundColorAttributeName: placeholderColor}];
187-
issuerPlaceholder = [[NSAttributedString alloc] initWithString:@"Issuer"
188-
attributes:@{NSForegroundColorAttributeName: placeholderColor}];
189-
}
190-
self.nameLabel.attributedPlaceholder = namePlaceholder;
191-
self.issuerLabel.attributedPlaceholder = issuerPlaceholder;
192-
193173
[UIView animateWithDuration:0.3 animations:^{
194174
self.passwordLabel.alpha = !editing ? 1 : (CGFloat)0.2;
175+
self.nextPasswordButton.alpha = !editing ? 1 : 0;
195176
}];
196-
197-
if (!editing) {
198-
[self.nameLabel resignFirstResponder];
199-
[self.issuerLabel resignFirstResponder];
200-
201-
[self commitChanges];
202-
}
203-
}
204-
205-
- (void)commitChanges
206-
{
207-
if (![self.token.name isEqualToString:self.nameLabel.text] ||
208-
![self.token.issuer isEqualToString:self.issuerLabel.text]) {
209-
self.token.name = self.nameLabel.text;
210-
self.token.issuer = self.issuerLabel.text;
211-
[self.token saveToKeychain];
212-
}
213-
}
214-
215-
- (BOOL)textFieldShouldReturn:(UITextField *)textField
216-
{
217-
if (textField == self.issuerLabel) {
218-
[self.nameLabel becomeFirstResponder];
219-
} else {
220-
[textField resignFirstResponder];
221-
}
222-
return NO;
223177
}
224178

225179
@end

Authenticator/Classes/OTPTokenListViewController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ - (void)viewDidLoad
7272
self.addButtonItem];
7373
self.navigationController.toolbarHidden = NO;
7474

75+
self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
7576
[self update];
7677
}
7778

@@ -133,7 +134,7 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fro
133134

134135
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
135136
{
136-
return 80;
137+
return 85;
137138
}
138139

139140

0 commit comments

Comments
 (0)