BackupPasswordVerifyViewController.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "BackupPasswordVerifyViewController.h"
  21. #import "BackupIdentityViewController.h"
  22. #import "UIDefines.h"
  23. #import "MyIdentityStore.h"
  24. @interface BackupPasswordVerifyViewController ()
  25. @end
  26. @implementation BackupPasswordVerifyViewController {
  27. NSString *backupData;
  28. }
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32. [Colors updateKeyboardAppearanceFor:self.passwordField];
  33. self.tableView.rowHeight = 85.0;
  34. self.tableView.estimatedRowHeight = 85.0;
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. if (self.passwordField.text.length < kMinimumPasswordLength) {
  39. self.navigationItem.rightBarButtonItem.enabled = NO;
  40. } else {
  41. self.navigationItem.rightBarButtonItem.enabled = YES;
  42. }
  43. self.passwordField.delegate = self;
  44. }
  45. - (void)viewDidAppear:(BOOL)animated {
  46. [super viewDidAppear:animated];
  47. [self.passwordField becomeFirstResponder];
  48. }
  49. - (void)viewWillDisappear:(BOOL)animated {
  50. [super viewWillDisappear:animated];
  51. self.passwordField.delegate = nil;
  52. }
  53. - (BOOL)shouldAutorotate {
  54. return YES;
  55. }
  56. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  57. if (SYSTEM_IS_IPAD) {
  58. return UIInterfaceOrientationMaskAll;
  59. }
  60. return UIInterfaceOrientationMaskAllButUpsideDown;
  61. }
  62. - (IBAction)nextAction:(id)sender {
  63. if (![self.passwordField.text isEqualToString:self.chosenPassword]) {
  64. [UIAlertTemplate showAlertWithOwner:self title:NSLocalizedString(@"password_mismatch_title", nil) message:NSLocalizedString(@"password_mismatch_message", nil) actionOk:nil];
  65. return;
  66. }
  67. if (_passwordCallback) {
  68. self.navigationItem.rightBarButtonItem.enabled = NO;
  69. [_passwordCallback passwordResult: self.chosenPassword fromViewController: self];
  70. }
  71. }
  72. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  73. if ([segue.identifier isEqualToString:@"ShowBackup"]) {
  74. BackupIdentityViewController *idVc = (BackupIdentityViewController*)segue.destinationViewController;
  75. idVc.backupData = backupData;
  76. }
  77. }
  78. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  79. NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
  80. if (newText.length < kMinimumPasswordLength) {
  81. self.navigationItem.rightBarButtonItem.enabled = NO;
  82. } else {
  83. self.navigationItem.rightBarButtonItem.enabled = YES;
  84. }
  85. return YES;
  86. }
  87. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  88. if (textField.text.length < kMinimumPasswordLength) {
  89. return NO;
  90. }
  91. return YES;
  92. }
  93. @end