123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2012-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- #import "BackupPasswordViewController.h"
- #import "BackupPasswordVerifyViewController.h"
- #import "UIDefines.h"
- @interface BackupPasswordViewController ()
- @end
- @implementation BackupPasswordViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- [Colors updateKeyboardAppearanceFor:self.passwordField];
-
- self.tableView.rowHeight = 85.0;
- self.tableView.estimatedRowHeight = 85.0;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActiveNotification:) name:UIApplicationWillResignActiveNotification object:nil];
-
-
- if (self.passwordField.text.length < kMinimumPasswordLength) {
- self.navigationItem.rightBarButtonItem.enabled = NO;
- } else {
- self.navigationItem.rightBarButtonItem.enabled = YES;
- }
-
- self.passwordField.delegate = self;
-
- [self.passwordField becomeFirstResponder];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- self.passwordField.delegate = nil;
-
- [[NSNotificationCenter defaultCenter] removeObserver:UIApplicationDidEnterBackgroundNotification];
- }
- - (void)setPasswordTitle:(NSString *)passwordTitle {
- if (passwordTitle && [passwordTitle length] > 0) {
- _titleNavigationItem.title = passwordTitle;
- }
- }
- -(NSString *)passwordTitle {
- return _titleNavigationItem.title;
- }
- - (BOOL)shouldAutorotate {
- return YES;
- }
- -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
- if (SYSTEM_IS_IPAD) {
- return UIInterfaceOrientationMaskAll;
- }
-
- return UIInterfaceOrientationMaskAllButUpsideDown;
- }
- - (IBAction)nextAction:(id)sender {
- if (self.passwordField.text.length < kMinimumPasswordLength) {
- [UIAlertTemplate showAlertWithOwner:self title:NSLocalizedString(@"password_too_short_title", nil) message:NSLocalizedString(@"password_too_short_message", nil) actionOk:nil];
- return;
- } else {
- [self performSegueWithIdentifier:@"VerifyPassword" sender:self];
- }
- }
- - (IBAction)cancelAction:(id)sender {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- if ([segue.identifier isEqualToString:@"VerifyPassword"]) {
- BackupPasswordVerifyViewController *verifyVc = (BackupPasswordVerifyViewController*)segue.destinationViewController;
- verifyVc.chosenPassword = self.passwordField.text;
- }
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
-
- NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
- if (newText.length < kMinimumPasswordLength) {
- self.navigationItem.rightBarButtonItem.enabled = NO;
- } else {
- self.navigationItem.rightBarButtonItem.enabled = YES;
- }
-
- return YES;
- }
- - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
- if (textField.text.length < kMinimumPasswordLength) {
- return NO;
- }
- return YES;
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [self nextAction:textField];
-
- return NO;
- }
- #pragma mark - UITableViewDataSource
- -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
- return _passwordAdditionalText;
- }
- #pragma mark - Notifications
- - (void)applicationWillResignActiveNotification:(NSNotification*)note {
- [self dismissViewControllerAnimated:NO completion:nil];
- }
- @end
|