LinkEmailViewController.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "LinkEmailViewController.h"
  21. #import "MyIdentityStore.h"
  22. #import "ServerAPIConnector.h"
  23. #import "MBProgressHUD.h"
  24. #import "MDMSetup.h"
  25. @interface LinkEmailViewController ()
  26. @end
  27. @implementation LinkEmailViewController
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. _emailTextField.text = [MyIdentityStore sharedMyIdentityStore].linkedEmail;
  31. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  32. if ([mdmSetup readonlyProfile]) {
  33. _emailTextField.enabled = NO;
  34. } else {
  35. [_emailTextField becomeFirstResponder];
  36. }
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [Colors updateKeyboardAppearanceFor:self.emailTextField];
  41. self.tableView.rowHeight = 85.0;
  42. self.tableView.estimatedRowHeight = 85.0;
  43. }
  44. - (BOOL)shouldAutorotate {
  45. return YES;
  46. }
  47. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  48. if (SYSTEM_IS_IPAD) {
  49. return UIInterfaceOrientationMaskAll;
  50. }
  51. return UIInterfaceOrientationMaskAllButUpsideDown;
  52. }
  53. - (IBAction)cancelAction:(id)sender {
  54. [self dismissViewControllerAnimated:YES completion:nil];
  55. }
  56. - (IBAction)saveAction:(id)sender {
  57. if ([self.emailTextField.text isEqualToString:[MyIdentityStore sharedMyIdentityStore].linkedEmail]) {
  58. /* no change - nothing to do */
  59. [self dismissViewControllerAnimated:YES completion:nil];
  60. return;
  61. }
  62. self.navigationItem.rightBarButtonItem.enabled = NO;
  63. [self.emailTextField resignFirstResponder];
  64. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  65. ServerAPIConnector *conn = [[ServerAPIConnector alloc] init];
  66. [conn linkEmailWithStore:[MyIdentityStore sharedMyIdentityStore] email:self.emailTextField.text onCompletion:^(BOOL linked) {
  67. [MBProgressHUD hideHUDForView:self.view animated:YES];
  68. [self dismissViewControllerAnimated:YES completion:nil];
  69. if (self.emailTextField.text.length > 0 && !linked) {
  70. [UIAlertTemplate showAlertWithOwner:self title:NSLocalizedString(@"link_email_sent_title", nil) message:[NSString stringWithFormat:NSLocalizedString(@"link_email_sent_message", nil), self.emailTextField.text] actionOk:nil];
  71. }
  72. } onError:^(NSError *error) {
  73. [MBProgressHUD hideHUDForView:self.view animated:YES];
  74. self.navigationItem.rightBarButtonItem.enabled = YES;
  75. [UIAlertTemplate showAlertWithOwner:self title:error.localizedDescription message:error.localizedFailureReason actionOk:nil];
  76. }];
  77. }
  78. @end