SyncContactsViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-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 "SyncContactsViewController.h"
  21. #import "UserSettings.h"
  22. #import "LicenseStore.h"
  23. #import "MDMSetup.h"
  24. @interface SyncContactsViewController ()
  25. @end
  26. @implementation SyncContactsViewController {
  27. MDMSetup *mdmSetup;
  28. }
  29. - (instancetype)initWithCoder:(NSCoder *)coder
  30. {
  31. self = [super initWithCoder:coder];
  32. if (self) {
  33. mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  34. }
  35. return self;
  36. }
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. self.syncContactsSwitch.on = YES;
  40. [self setup];
  41. }
  42. - (void)viewWillAppear:(BOOL)animated {
  43. [super viewWillAppear:animated];
  44. if ([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]) {
  45. self.syncContactsSwitch.on = [UserSettings sharedUserSettings].syncContacts;
  46. self.syncContactsSwitch.enabled = false;
  47. } else {
  48. [UserSettings sharedUserSettings].syncContacts = self.syncContactsSwitch.on;
  49. }
  50. }
  51. - (IBAction)syncContactSwitchChanged:(id)sender {
  52. [UserSettings sharedUserSettings].syncContacts = _syncContactsSwitch.on;
  53. }
  54. - (void)setup {
  55. if ([LicenseStore requiresLicenseKey]) {
  56. _titleLabel.text = [BundleUtil localizedStringForKey:@"id_sync_title_work"];
  57. _descriptionLabel.text = [BundleUtil localizedStringForKey:@"id_sync_description_work"];
  58. } else {
  59. _titleLabel.text = [BundleUtil localizedStringForKey:@"id_sync_title"];
  60. _descriptionLabel.text = [BundleUtil localizedStringForKey:@"id_sync_description"];
  61. }
  62. _syncContactsLabel.text = [BundleUtil localizedStringForKey:@"id_sync_contacts"];
  63. self.moreView.mainView = self.mainContentView;
  64. self.moreView.moreMessageText = [BundleUtil localizedStringForKey:@"more_information_sync_contacts"];
  65. _syncContactsView.layer.cornerRadius = 3;
  66. _syncContactsView.layer.borderColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1].CGColor;
  67. _syncContactsView.layer.borderWidth = 0.5;
  68. self.syncContactsSwitch.enabled = ![mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC];
  69. _syncContactsSwitch.onTintColor = [Colors mainThemeDark];
  70. }
  71. - (BOOL)isInputValid {
  72. if ([self.moreView isShown]) {
  73. return NO;
  74. }
  75. return YES;
  76. }
  77. @end