|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import "ALTPreferencesViewController.h" |
| 10 | +#import <SAMKeychain/SAMKeychain.h> |
| 11 | +#import "ALTMainViewController.h" |
10 | 12 |
|
11 | 13 | @implementation ALTPreferencesViewController |
12 | 14 |
|
13 | 15 | - (void)viewDidLoad { |
14 | 16 | [super viewDidLoad]; |
15 | | - |
| 17 | + dateFormatter = [NSDateFormatter new]; |
| 18 | + [dateFormatter setLocalizedDateFormatFromTemplate:@"E, d MMM yyyy HH:mm:ss"]; |
| 19 | + _tableView.usesStaticContents = NO; |
| 20 | + _tableView.delegate = self; |
| 21 | + _tableView.dataSource = self; |
| 22 | + _tableView.translatesAutoresizingMaskIntoConstraints = NO; |
| 23 | + [_tableView.widthAnchor constraintEqualToAnchor:_scrollView.widthAnchor multiplier:1.0].active = |
| 24 | + [_tableView.centerYAnchor constraintEqualToAnchor:_scrollView.centerYAnchor].active = |
| 25 | + [_tableView.centerXAnchor constraintEqualToAnchor:_scrollView.centerXAnchor].active = |
| 26 | + [_tableView.heightAnchor constraintEqualToAnchor:_scrollView.heightAnchor multiplier:1.0].active = YES; |
| 27 | + [self refreshAccounts]; |
16 | 28 | // Do view setup here. |
17 | 29 | } |
18 | 30 |
|
| 31 | +- (void)refreshAccounts { |
| 32 | + accounts = [SAMKeychain accountsForService:NSBundle.mainBundle.bundleIdentifier]; |
| 33 | + [_tableView reloadData]; |
| 34 | +} |
| 35 | + |
| 36 | +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { |
| 37 | + return accounts.count; |
| 38 | +} |
| 39 | + |
| 40 | +- (id _Nullable)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row { |
| 41 | + if ([tableColumn.identifier isEqualToString:@"appleIDColumn"]) { |
| 42 | + // Apple ID |
| 43 | + return accounts[row][kSAMKeychainAccountKey]; |
| 44 | + } |
| 45 | + else { |
| 46 | + // Last modified |
| 47 | + return [dateFormatter stringFromDate:accounts[row][kSAMKeychainLastModifiedKey]]; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +- (BOOL)tableView:(NSTableView *)tableView shouldSelectTableColumn:(NSTableColumn *)tableColumn { |
| 52 | + return NO; |
| 53 | +} |
| 54 | + |
| 55 | +- (void)tableViewSelectionDidChange:(NSNotification *)notification { |
| 56 | + BOOL enableButtons = (_tableView.selectedRow != -1); |
| 57 | + _modifyButton.enabled = enableButtons; |
| 58 | + _removeButton.enabled = enableButtons; |
| 59 | + _setAsDefaultButton.enabled = enableButtons; |
| 60 | +} |
| 61 | + |
19 | 62 | @end |
0 commit comments