CreatePasswordTrigger.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2014-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 "CreatePasswordTrigger.h"
  21. #import "BackupPasswordViewController.h"
  22. #import "BackupPasswordVerifyViewController.h"
  23. @interface CreatePasswordTrigger () <PasswordCallback, UINavigationControllerDelegate>
  24. @property UIViewController *viewController;
  25. @end
  26. CreatePasswordTrigger *createPasswordTriggerInstance;
  27. @implementation CreatePasswordTrigger
  28. + (instancetype)createPasswordTriggerOn:(UIViewController *)viewController {
  29. CreatePasswordTrigger *createPasswordTrigger = [[CreatePasswordTrigger alloc] initWithViewController:viewController];
  30. createPasswordTriggerInstance = createPasswordTrigger;
  31. return createPasswordTrigger;
  32. }
  33. - (instancetype)initWithViewController: (UIViewController *) viewController {
  34. self = [super init];
  35. if (self) {
  36. self.viewController = viewController;
  37. }
  38. return self;
  39. }
  40. - (void)presentPasswordUI {
  41. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"CreatePassword" bundle:nil];
  42. UINavigationController *navigationController = (UINavigationController *) [storyboard instantiateInitialViewController];
  43. navigationController.delegate = self;
  44. if (createPasswordTriggerInstance) {
  45. [createPasswordTriggerInstance.viewController presentViewController:navigationController animated:YES completion:nil];
  46. }
  47. }
  48. #pragma mark - UINavigationControllerDelegate
  49. -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)vc animated:(BOOL)animated {
  50. if ([vc isKindOfClass: [BackupPasswordViewController class]]) {
  51. BackupPasswordViewController *passwordVC = (BackupPasswordViewController *) vc;
  52. passwordVC.passwordTitle = _passwordTitle;
  53. passwordVC.passwordAdditionalText = _passwordAdditionalText;
  54. }
  55. if ([vc isKindOfClass: [BackupPasswordVerifyViewController class]]) {
  56. BackupPasswordVerifyViewController *passwordVerify = (BackupPasswordVerifyViewController *) vc;
  57. passwordVerify.passwordCallback = self;
  58. }
  59. }
  60. #pragma mark - PasswordCallback
  61. - (void)passwordResult:(NSString *)password fromViewController:(UIViewController *)viewController{
  62. if (_passwordCallback) {
  63. [_passwordCallback passwordResult: password fromViewController: viewController];
  64. }
  65. }
  66. @end