PrivacySettingsViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 "PrivacySettingsViewController.h"
  21. #import "UserSettings.h"
  22. #import "ContactStore.h"
  23. #import "UIDefines.h"
  24. #import "MDMSetup.h"
  25. @interface PrivacySettingsViewController ()
  26. @end
  27. @implementation PrivacySettingsViewController {
  28. MDMSetup *mdmSetup;
  29. }
  30. - (instancetype)initWithCoder:(NSCoder *)coder
  31. {
  32. self = [super initWithCoder:coder];
  33. if (self) {
  34. mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  35. }
  36. return self;
  37. }
  38. - (void)viewDidLoad
  39. {
  40. [super viewDidLoad];
  41. self.readReceiptsSwitch.on = [UserSettings sharedUserSettings].sendReadReceipts;
  42. [[ValidationLogger sharedValidationLogger] logString:[NSString stringWithFormat:@"Read receipts bug: Show flag %@", self.readReceiptsSwitch.on ? @"true" : @"false"]];
  43. self.syncContactsSwitch.on = [UserSettings sharedUserSettings].syncContacts;
  44. self.typingIndicatorSwitch.on = [UserSettings sharedUserSettings].sendTypingIndicator;
  45. self.blockUnknownSwitch.on = [UserSettings sharedUserSettings].blockUnknown;
  46. self.poiSwitch.on = [UserSettings sharedUserSettings].enablePoi;
  47. [self disabledCellsForMDM];
  48. [self.tableView reloadData];
  49. }
  50. - (void)viewWillAppear:(BOOL)animated {
  51. [super viewWillAppear:animated];
  52. self.tableView.rowHeight = UITableViewAutomaticDimension;
  53. if (@available(iOS 11.0, *)) {
  54. self.tableView.estimatedRowHeight = UITableViewAutomaticDimension;
  55. } else {
  56. self.tableView.estimatedRowHeight = 44.0;
  57. }
  58. [self.tableView reloadData];
  59. }
  60. - (BOOL)shouldAutorotate {
  61. return YES;
  62. }
  63. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  64. if (SYSTEM_IS_IPAD) {
  65. return UIInterfaceOrientationMaskAll;
  66. }
  67. return UIInterfaceOrientationMaskAllButUpsideDown;
  68. }
  69. - (IBAction)readReceiptsChanged:(id)sender {
  70. [UserSettings sharedUserSettings].sendReadReceipts = self.readReceiptsSwitch.on;
  71. }
  72. - (IBAction)syncContactsChanged:(id)sender {
  73. [UserSettings sharedUserSettings].syncContacts = self.syncContactsSwitch.on;
  74. if (self.syncContactsSwitch.on) {
  75. [[ContactStore sharedContactStore] synchronizeAddressBookForceFullSync:YES ignoreMinimumInterval:YES onCompletion:nil onError:nil];
  76. }
  77. }
  78. - (IBAction)typingIndicatorChanged:(id)sender {
  79. [UserSettings sharedUserSettings].sendTypingIndicator = self.typingIndicatorSwitch.on;
  80. }
  81. - (IBAction)blockUnknownChanged:(id)sender {
  82. [UserSettings sharedUserSettings].blockUnknown = self.blockUnknownSwitch.on;
  83. [self.tableView reloadData];
  84. }
  85. - (IBAction)poiChanged:(id)sender {
  86. [UserSettings sharedUserSettings].enablePoi = self.poiSwitch.on;
  87. }
  88. - (void)disabledCellsForMDM {
  89. BOOL isBlockUnknownManaged = [mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN];
  90. self.blockUnknownCell.userInteractionEnabled = !isBlockUnknownManaged;
  91. self.blockUnknownLabel.enabled = !isBlockUnknownManaged;
  92. self.blockUnknownSwitch.enabled = !isBlockUnknownManaged;
  93. BOOL isContactSyncManaged = [mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC];
  94. self.syncContactsCell.userInteractionEnabled = !isContactSyncManaged;
  95. self.syncContactsLabel.enabled = !isContactSyncManaged;
  96. self.syncContactsSwitch.enabled = !isContactSyncManaged;
  97. }
  98. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  99. NSInteger sections = [super numberOfSectionsInTableView:tableView];
  100. return sections;
  101. }
  102. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
  103. NSString *footer;
  104. switch (section) {
  105. case 0:
  106. if ([UserSettings sharedUserSettings].blockUnknown) {
  107. footer = NSLocalizedString(@"block_unknown_on", nil);
  108. } else {
  109. footer = NSLocalizedString(@"block_unknown_off", nil);
  110. }
  111. if ([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN] || [mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]) {
  112. footer = [NSString stringWithFormat:@"%@\n\n%@", footer, NSLocalizedString(@"disabled_by_device_policy", nil)];
  113. }
  114. return footer;
  115. default:
  116. return nil;
  117. }
  118. }
  119. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  120. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  121. }
  122. @end