WFCUMessageSettingViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // MessageNotificationViewController.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain lee on 07/01/2018.
  6. // Copyright © 2018 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUMessageSettingViewController.h"
  9. #import "WFCUSwitchTableViewCell.h"
  10. #import "UIColor+YH.h"
  11. #import "WFCUGeneralSwitchTableViewCell.h"
  12. #import "WFCUSelectNoDisturbingTimeViewController.h"
  13. #ifdef WFC_PTT
  14. #import <PttClient/WFPttClient.h>
  15. #endif
  16. #import "WFCUConfigManager.h"
  17. @interface WFCUMessageSettingViewController () <UITableViewDataSource, UITableViewDelegate>
  18. @property (nonatomic, strong)UITableView *tableView;
  19. @property(nonatomic, assign)BOOL isNoDisturb;
  20. @property(nonatomic, assign)int startMins;
  21. @property(nonatomic, assign)int endMins;
  22. @end
  23. @implementation WFCUMessageSettingViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.title = WFCString(@"NewMessageNotification");
  27. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  28. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  29. self.tableView.delegate = self;
  30. self.tableView.dataSource = self;
  31. if (@available(iOS 15, *)) {
  32. self.tableView.sectionHeaderTopPadding = 0;
  33. }
  34. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  36. [self.tableView reloadData];
  37. [self.view addSubview:self.tableView];
  38. NSInteger interval = [[NSTimeZone systemTimeZone] secondsFromGMTForDate:[NSDate date]];
  39. self.startMins = 21 * 60 - interval/60; //本地21:00
  40. self.endMins = 7 * 60 - interval/60; //本地7:00
  41. if (self.endMins < 0) {
  42. self.endMins += 24 * 60;
  43. }
  44. [[WFCCIMService sharedWFCIMService] getNoDisturbingTimes:^(int startMins, int endMins) {
  45. self.startMins = startMins;
  46. self.endMins = endMins;
  47. self.isNoDisturb = YES;
  48. } error:^(int error_code) {
  49. self.isNoDisturb = NO;
  50. }];
  51. }
  52. - (void)didReceiveMemoryWarning {
  53. [super didReceiveMemoryWarning];
  54. // Dispose of any resources that can be recreated.
  55. }
  56. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. return 48;
  58. }
  59. - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
  60. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  63. if (section == 0) {
  64. return 0.1;
  65. } else {
  66. return 9;
  67. }
  68. }
  69. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  70. if (section == 0) {
  71. return nil;
  72. } else {
  73. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 9)];
  74. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  75. return view;
  76. }
  77. }
  78. //#pragma mark - Table view data source
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  80. int count = 4;
  81. if([[WFCCIMService sharedWFCIMService] isCommercialServer] && ![[WFCCIMService sharedWFCIMService] isGlobalDisableSyncDraft]) {
  82. count ++;
  83. }
  84. #ifdef WFC_PTT
  85. count ++;
  86. #endif
  87. return count;
  88. }
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. if (section == 0) {
  91. return 1;
  92. } else if (section == 1) {
  93. return 1;
  94. } else if (section == 2) {
  95. return 1;
  96. } else if (section == 3) {
  97. if (self.isNoDisturb) {
  98. return 2;
  99. }
  100. return 1;
  101. } else if(section == 4) {
  102. if([[WFCCIMService sharedWFCIMService] isCommercialServer] && ![[WFCCIMService sharedWFCIMService] isGlobalDisableSyncDraft]) {
  103. return 1;
  104. //草稿
  105. } else {
  106. //Ptt
  107. #ifdef WFC_PTT
  108. if([WFPttClient sharedClient].enablePtt) {
  109. return 2;
  110. }
  111. return 1;
  112. #endif
  113. }
  114. return 1;
  115. } else if(section == 5) {
  116. //Ptt
  117. #ifdef WFC_PTT
  118. if([WFPttClient sharedClient].enablePtt) {
  119. return 2;
  120. }
  121. return 1;
  122. #endif
  123. }
  124. return 0;
  125. }
  126. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  127. if (indexPath.section == 3) {
  128. if (indexPath.row == 0) {
  129. WFCUGeneralSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"switch"];
  130. if(cell == nil) {
  131. cell = [[WFCUGeneralSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"switch"];
  132. }
  133. cell.detailTextLabel.text = nil;
  134. cell.accessoryType = UITableViewCellAccessoryNone;
  135. cell.accessoryView = nil;
  136. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  137. cell.textLabel.text = WFCString(@"NoDisturb");
  138. cell.on = self.isNoDisturb;
  139. __weak typeof(self)ws = self;
  140. cell.onSwitch = ^(BOOL value, int type, void (^handleBlock)(BOOL success)) {
  141. if (value) {
  142. [[WFCCIMService sharedWFCIMService] setNoDisturbingTimes:ws.startMins endMins:ws.endMins success:^{
  143. ws.isNoDisturb = YES;
  144. [ws.tableView reloadData];
  145. handleBlock(YES);
  146. } error:^(int error_code) {
  147. handleBlock(NO);
  148. }];
  149. } else {
  150. [[WFCCIMService sharedWFCIMService] clearNoDisturbingTimes:^{
  151. ws.isNoDisturb = NO;
  152. [ws.tableView reloadData];
  153. handleBlock(YES);
  154. } error:^(int error_code) {
  155. handleBlock(NO);
  156. }];
  157. }
  158. };
  159. return cell;
  160. } else {
  161. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  162. if (!cell) {
  163. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  164. }
  165. cell.textLabel.text = WFCString(@"SilentPeriods");
  166. NSInteger interval = [[NSTimeZone systemTimeZone] secondsFromGMTForDate:[NSDate date]];
  167. cell.detailTextLabel.text = [NSString stringWithFormat:@"%02d:%02d-%02d:%02d", (self.startMins/60+(int)interval/3600)%24, self.startMins%60, (self.endMins/60+(int)interval/3600)%24, self.endMins%60];
  168. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  169. return cell;
  170. }
  171. }
  172. WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
  173. if(cell == nil) {
  174. cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:nil];
  175. }
  176. cell.detailTextLabel.text = nil;
  177. cell.accessoryType = UITableViewCellAccessoryNone;
  178. cell.accessoryView = nil;
  179. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  180. if (indexPath.section == 0) {
  181. cell.textLabel.text = WFCString(@"ReceiveNewMessageNotification");
  182. cell.type = SwitchType_Setting_Global_Silent;
  183. } else if(indexPath.section == 1) {
  184. cell.textLabel.text = WFCString(@"ReceiveVoipNotification");
  185. cell.type = SwitchType_Setting_Voip_Silent;
  186. } else if(indexPath.section == 2) {
  187. cell.textLabel.text = WFCString(@"NotificationShowMessageDetail");
  188. cell.type = SwitchType_Setting_Show_Notification_Detail;
  189. } else if(indexPath.section == 4 || indexPath.section == 5) {
  190. if(indexPath.section == 4 && [[WFCCIMService sharedWFCIMService] isCommercialServer] && ![[WFCCIMService sharedWFCIMService] isGlobalDisableSyncDraft]) {
  191. cell.textLabel.text = WFCString(@"SyncDraft");
  192. cell.type = SwitchType_Setting_Sync_Draft;
  193. } else {
  194. #ifdef WFC_PTT
  195. WFCUGeneralSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"switch2"];
  196. if(cell == nil) {
  197. cell = [[WFCUGeneralSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"switch2"];
  198. }
  199. cell.detailTextLabel.text = nil;
  200. cell.accessoryType = UITableViewCellAccessoryNone;
  201. cell.accessoryView = nil;
  202. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  203. if(indexPath.row == 0) {
  204. cell.textLabel.text = @"开启对讲功能";
  205. cell.on = [WFPttClient sharedClient].enablePtt;
  206. __weak typeof(self)ws = self;
  207. cell.onSwitch = ^(BOOL value, int type, void (^handleBlock)(BOOL success)) {
  208. [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"WFC_PTT_ENABLED"];
  209. [[NSUserDefaults standardUserDefaults] synchronize];
  210. [WFPttClient sharedClient].enablePtt = value;
  211. [ws.tableView reloadData];
  212. };
  213. } else {
  214. cell.textLabel.text = @"对讲保持后台激活";
  215. cell.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"WFC_PTT_BACKGROUND_KEEPALIVE"];
  216. cell.onSwitch = ^(BOOL value, int type, void (^handleBlock)(BOOL success)) {
  217. [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"WFC_PTT_BACKGROUND_KEEPALIVE"];
  218. [[NSUserDefaults standardUserDefaults] synchronize];
  219. [WFPttClient sharedClient].playSilent = @(value);
  220. };
  221. }
  222. return cell;
  223. #endif
  224. }
  225. }
  226. return cell;
  227. }
  228. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  229. if (indexPath.section == 3 && indexPath.row == 1) {
  230. WFCUSelectNoDisturbingTimeViewController *vc = [[WFCUSelectNoDisturbingTimeViewController alloc] init];
  231. vc.startMins = self.startMins;
  232. vc.endMins = self.endMins;
  233. __weak typeof(self)ws = self;
  234. vc.onSelectTime = ^(int startMins, int endMins) {
  235. ws.startMins = startMins;
  236. ws.endMins = endMins;
  237. [[WFCCIMService sharedWFCIMService] setNoDisturbingTimes:ws.startMins endMins:ws.endMins success:^{
  238. ws.isNoDisturb = YES;
  239. [ws.tableView reloadData];
  240. } error:^(int error_code) {
  241. }];
  242. };
  243. [self.navigationController pushViewController:vc animated:YES];
  244. }
  245. }
  246. @end