KKPasscodeGracePeriodViewController.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // KKPasscodeGracePeriodViewController.m
  3. // Threema
  4. //
  5. // Copyright (c) 2012 Threema GmbH. All rights reserved.
  6. //
  7. #import "KKPasscodeGracePeriodViewController.h"
  8. #import "KKPasscodeSettingsViewController.h"
  9. #import "KKKeychain.h"
  10. #import "KKPasscodeLock.h"
  11. #import "BundleUtil.h"
  12. @interface KKPasscodeGracePeriodViewController ()
  13. @end
  14. @implementation KKPasscodeGracePeriodViewController {
  15. int _gracePeriod;
  16. NSIndexPath *selectedIndexPath;
  17. }
  18. static int gracePeriods[] = {0, 60, 300, 900, 3600, 14400};
  19. - (id)initWithStyle:(UITableViewStyle)style
  20. {
  21. self = [super initWithStyle:style];
  22. if (self) {
  23. }
  24. return self;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.title = KKPasscodeLockLocalizedString(@"Require Passcode", @"");
  29. }
  30. - (void)viewWillAppear:(BOOL)animated {
  31. [super viewWillAppear:animated];
  32. _gracePeriod = [[KKKeychain getStringForKey:@"grace_period"] intValue];
  33. }
  34. #pragma mark - Table view data source
  35. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  36. {
  37. return 1;
  38. }
  39. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  40. {
  41. return sizeof(gracePeriods) / sizeof(int);
  42. }
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  44. {
  45. static NSString *CellIdentifier = @"GracePeriodCell";
  46. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  47. if (!cell) {
  48. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  49. cell.selectionStyle = UITableViewCellSelectionStyleBlue;
  50. }
  51. cell.textLabel.text = [KKPasscodeSettingsViewController textForGracePeriod:gracePeriods[indexPath.row] shortForm:NO];
  52. if (gracePeriods[indexPath.row] == _gracePeriod) {
  53. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  54. selectedIndexPath = indexPath;
  55. } else
  56. cell.accessoryType = UITableViewCellAccessoryNone;
  57. return cell;
  58. }
  59. #pragma mark - Table view delegate
  60. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  61. {
  62. _gracePeriod = gracePeriods[indexPath.row];
  63. [KKKeychain setString:[NSString stringWithFormat:@"%d", _gracePeriod] forKey:@"grace_period"];
  64. if (selectedIndexPath != nil)
  65. [self.tableView cellForRowAtIndexPath:selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
  66. [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
  67. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  68. selectedIndexPath = indexPath;
  69. }
  70. @end