ChatSettingController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // ChatSettingController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/22.
  6. //
  7. #import "ChatSettingController.h"
  8. #import "ChatSettingCell.h"
  9. #import "UDManager.h"
  10. #import "UserNetApi.h"
  11. @interface ChatSettingController ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView * tableView;
  13. @property (nonatomic, strong) UIView * borderView;
  14. @property (nonatomic, strong) UIButton * saveBtn;
  15. @property (nonatomic, strong) NSMutableDictionary * settingDict;
  16. @property (nonatomic, strong) NSMutableArray * titlesArray;
  17. @end
  18. @implementation ChatSettingController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self getChatSettingData];
  22. [self configUI];
  23. }
  24. - (void)viewWillAppear:(BOOL)animated{
  25. [self setNavigationBarHidden:NO animated:NO];
  26. }
  27. - (void)configUI{
  28. [self setNavigationTitle:NSLocalizedString(@"userCenter-liaotsz", @"")];
  29. // 设置导航栏背景色
  30. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  31. // 设置标题颜色和字体
  32. [self setNavigationTitleColor:[UIColor whiteColor] font:SYSBFONT(18)];
  33. // 设置返回按钮
  34. [self setBackButtonTitle:@""];
  35. [self setBackButtonColor:[UIColor whiteColor]];
  36. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  37. [self.view addSubview:bgImageView];
  38. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.right.top.bottom.mas_equalTo(0);
  40. }];
  41. [self.view addSubview:self.tableView];
  42. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_equalTo(SCREEN_TOP+20);
  44. make.height.mas_equalTo(350);
  45. make.left.mas_equalTo(20);
  46. make.right.mas_equalTo(-20);
  47. }];
  48. [self.view addSubview:self.saveBtn];
  49. [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_equalTo(20);
  51. make.right.mas_equalTo(-20);
  52. make.top.mas_equalTo(self.tableView.mas_bottom).offset(20);
  53. make.height.mas_equalTo(46);
  54. }];
  55. }
  56. #pragma mark api
  57. - (void)getChatSettingData{
  58. NSDictionary * userInfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  59. [UserNetApi getChatSetting:userInfo[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  60. NSLog(@"chat setting:%@",result);
  61. if ([result jk_hasKey:@"data"]) {
  62. self.settingDict = [NSMutableDictionary dictionaryWithDictionary:result[@"data"]];
  63. [self.tableView reloadData];
  64. }else{
  65. self.settingDict = [NSMutableDictionary dictionaryWithDictionary:@{
  66. @"canAddFriend":@"1",
  67. @"addFriendValidate":@"1",
  68. @"canSendMessage":@"1",
  69. @"canSoundRemind":@"1",
  70. @"canVoiceRemind":@"1",
  71. @"showMobile":@"1",
  72. @"showEmail":@"1",
  73. @"createBy":@""
  74. }];
  75. }
  76. } fail:^(NSError * _Nonnull error) {
  77. }];
  78. }
  79. - (void)updateChatSetting:(NSDictionary *)param{
  80. [UserNetApi updateChatSetting:param succ:^(int code, NSDictionary * _Nullable result) {
  81. if ([result jk_hasKey:@"msg"]) {
  82. [MBProgressHUD showWithText:result[@"msg"]];
  83. }
  84. } fail:^(NSError * _Nonnull error) {
  85. // [MBProgressHUD showWithText:@"操作失败"];
  86. }];
  87. }
  88. #pragma mark event
  89. - (void)saveButtonClicked{
  90. [self updateChatSetting:self.settingDict];
  91. }
  92. #pragma mark tableView delegate
  93. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  94. return self.titlesArray.count;
  95. }
  96. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  97. ChatSettingCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(ChatSettingCell.class) forIndexPath:indexPath];
  98. cell.titleLbl.text = self.titlesArray[indexPath.row];
  99. switch (indexPath.row) {
  100. case 0:
  101. cell.stateSwitch.on = [self.settingDict[@"canAddFriend"] isEqualToString:@"1"];
  102. break;
  103. case 1:
  104. cell.stateSwitch.on = [self.settingDict[@"addFriendValidate"] isEqualToString:@"1"];
  105. break;
  106. case 2:
  107. cell.stateSwitch.on = [self.settingDict[@"canSendMessage"] isEqualToString:@"1"];
  108. break;
  109. case 3:
  110. cell.stateSwitch.on = [self.settingDict[@"canSoundRemind"] isEqualToString:@"1"];
  111. break;
  112. case 4:
  113. cell.stateSwitch.on = [self.settingDict[@"canVoiceRemind"] isEqualToString:@"1"];
  114. break;
  115. case 5:
  116. cell.stateSwitch.on = [self.settingDict[@"showMobile"] isEqualToString:@"1"];
  117. break;
  118. case 6:
  119. cell.stateSwitch.on = [self.settingDict[@"showEmail"] isEqualToString:@"1"];
  120. break;
  121. default:
  122. break;
  123. }
  124. weakSelf(self);
  125. cell.stateSwitchChangeValue = ^(BOOL isOn) {
  126. NSString * keyString = @"";
  127. switch (indexPath.row) {
  128. case 0:
  129. keyString = @"canAddFriend";
  130. break;
  131. case 1:
  132. keyString = @"addFriendValidate";
  133. break;
  134. case 2:
  135. keyString = @"canSendMessage";
  136. break;
  137. case 3:
  138. keyString = @"canSoundRemind";
  139. break;
  140. case 4:
  141. keyString = @"canVoiceRemind";
  142. break;
  143. case 5:
  144. keyString = @"showMobile";
  145. break;
  146. case 6:
  147. keyString = @"showEmail";
  148. break;
  149. default:
  150. break;
  151. }
  152. [weakself.settingDict setValue:isOn?@"1":@"0" forKey:keyString];
  153. };
  154. return cell;
  155. }
  156. #pragma mark lazy
  157. - (UITableView *)tableView{
  158. if (!_tableView) {
  159. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  160. _tableView.delegate = self;
  161. _tableView.dataSource =self;
  162. _tableView.backgroundColor = UIColor.clearColor;
  163. _tableView.separatorColor = globalColor(GCTypeGreen);
  164. _tableView.layer.cornerRadius = 5.f;
  165. _tableView.layer.borderColor = globalColor(GCTypeGreen).CGColor;
  166. _tableView.layer.borderWidth = 0.5f;
  167. _tableView.scrollEnabled = NO;
  168. [_tableView registerClass:ChatSettingCell.class forCellReuseIdentifier:NSStringFromClass(ChatSettingCell.class)];
  169. }
  170. return _tableView;
  171. }
  172. - (UIButton *)saveBtn{
  173. if (!_saveBtn) {
  174. _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  175. [_saveBtn setTitle:NSLocalizedString(@"EGroupCtr-baocun", @"") forState:UIControlStateNormal];
  176. [_saveBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  177. _saveBtn.titleLabel.font = SYSMFONT(16);
  178. [_saveBtn setBackgroundColor:globalColor(GCTypeGreen)];
  179. _saveBtn.layer.cornerRadius = 5.f;
  180. _saveBtn.layer.masksToBounds = YES;
  181. [_saveBtn addTarget:self action:@selector(saveButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  182. }
  183. return _saveBtn;
  184. }
  185. - (NSMutableArray *)titlesArray{
  186. if (!_titlesArray) {
  187. _titlesArray = [NSMutableArray arrayWithArray:@[NSLocalizedString(@"ChatSetting_addFriend", @""),NSLocalizedString(@"ChatSetting_review", @""),NSLocalizedString(@"ChatSetting_privateChat", @""),NSLocalizedString(@"ChatSetting_audioRemind", @""),NSLocalizedString(@"ChatSetting_vedioRemind", @""),NSLocalizedString(@"ChatSetting_mobileDisplay", @""),NSLocalizedString(@"ChatSetting_emialDisplay", @"")]];
  188. }
  189. return _titlesArray;
  190. }
  191. #pragma mark statusBar
  192. - (UIStatusBarStyle)preferredStatusBarStyle{
  193. return UIStatusBarStyleLightContent;
  194. }
  195. @end