Skip to content

Commit 2bb70dd

Browse files
committed
Save changes to edited tokens and refresh the token list
1 parent 0de0a90 commit 2bb70dd

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Authenticator/Classes/OTPTokenEditViewController.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@
2525
#import "OTPTokenEntryViewController.h"
2626

2727

28+
@protocol OTPTokenEditorDelegate <OTPTokenSourceDelegate>
29+
30+
- (void)tokenSource:(id)tokenSource didEditToken:(OTPToken *)token;
31+
32+
@end
33+
34+
2835
@interface OTPTokenEditViewController : OTPTokenEntryViewController
2936

37+
@property (nonatomic, weak) id <OTPTokenEditorDelegate> delegate;
38+
3039
@property (nonatomic, strong) OTPToken *token;
3140

3241
@end

Authenticator/Classes/OTPTokenEditViewController.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#import "OTPTokenEditViewController.h"
2626
#import "OTPTextFieldCell.h"
27-
#import "OTPToken.h"
27+
#import "OTPToken+Persistence.h"
2828

2929

3030
@interface OTPTokenEntryViewController () <UITextFieldDelegate>
@@ -71,8 +71,17 @@ - (void)setToken:(OTPToken *)token
7171

7272
- (void)updateToken
7373
{
74-
NSLog(@"!!!");
74+
if (!self.formIsValid) return;
7575

76+
if (![self.token.name isEqualToString:self.accountNameCell.textField.text] ||
77+
![self.token.issuer isEqualToString:self.issuerCell.textField.text]) {
78+
self.token.name = self.accountNameCell.textField.text;
79+
self.token.issuer = self.issuerCell.textField.text;
80+
[self.token saveToKeychain];
81+
}
82+
83+
id <OTPTokenEditorDelegate> delegate = self.delegate;
84+
[delegate tokenSource:self didEditToken:self.token];
7685
}
7786

7887

Authenticator/Classes/OTPTokenListViewController.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#import "OTPTokenEditViewController.h"
3434

3535

36-
@interface OTPTokenListViewController ()
36+
@interface OTPTokenListViewController () <OTPTokenEditorDelegate>
3737

3838
@property (nonatomic, strong) OTPTokenManager *tokenManager;
3939
@property (nonatomic, strong) OTPProgressRing *ring;
@@ -144,6 +144,8 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
144144
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
145145
{
146146
if (self.isEditing) {
147+
self.editing = NO;
148+
147149
OTPTokenEditViewController *editController = [OTPTokenEditViewController new];
148150
editController.token = self.tokenManager.tokens[(NSUInteger)indexPath.row];
149151
editController.delegate = self;
@@ -191,4 +193,13 @@ - (void)tokenSource:(id)tokenSource didCreateToken:(OTPToken *)token
191193
}
192194
}
193195

196+
197+
#pragma mark - OTPTokenEditorDelegate
198+
199+
- (void)tokenSource:(id)tokenSource didEditToken:(OTPToken *)token
200+
{
201+
[self dismissViewControllerAnimated:YES completion:nil];
202+
[self.tableView reloadData];
203+
}
204+
194205
@end

0 commit comments

Comments
 (0)