NIMTeamNotifyUpdateViewController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // NIMTeamNotifyUpdateViewController.m
  3. // NIMKit
  4. //
  5. // Created by chris on 2017/9/20.
  6. // Copyright © 2017年 NetEase. All rights reserved.
  7. //
  8. #import "NIMTeamNotifyUpdateViewController.h"
  9. #import "NIMTeamCardRowItem.h"
  10. #import <NIMSDK/NIMSDK.h>
  11. #import "NIMGlobalMacro.h"
  12. #import "NIMKitProgressHUD.h"
  13. #import "UIView+Toast.h"
  14. @interface NIMTeamNotifyUpdateViewController ()<UITableViewDataSource,UITableViewDelegate>
  15. @property (nonatomic,strong) NIMTeam *team;
  16. @property (nonatomic,strong) UITableView *tableView;
  17. @property (nonatomic,strong) NSArray *bodyData; //表身数据
  18. @property (nonatomic,assign) NIMTeamNotifyState selectState;
  19. @end
  20. @implementation NIMTeamNotifyUpdateViewController
  21. - (instancetype)initTeam:(NIMTeam *)team
  22. {
  23. self = [super initWithNibName:nil bundle:nil];
  24. if (self)
  25. {
  26. _team = team;
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad
  31. {
  32. [super viewDidLoad];
  33. self.navigationItem.title = @"消息提醒";
  34. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(onDone:)];
  35. self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
  36. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  37. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  38. if (@available(iOS 15.0, *)) {
  39. self.tableView.sectionHeaderTopPadding = 0;
  40. }
  41. [self.view addSubview:self.tableView];
  42. self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
  43. self.tableView.delegate = self;
  44. self.tableView.dataSource = self;
  45. self.tableView.backgroundColor = NIMKit_UIColorFromRGB(0xecf1f5);
  46. self.selectState = [[NIMSDK sharedSDK].teamManager notifyStateForNewMsg:self.team.teamId];
  47. self.bodyData = [self buildBodyData];
  48. }
  49. - (void)onDone:(id)sender
  50. {
  51. if ([[NIMSDK sharedSDK].teamManager notifyStateForNewMsg:self.team.teamId] != self.selectState)
  52. {
  53. [NIMKitProgressHUD show];
  54. __weak typeof(self) weakSelf = self;
  55. [[NIMSDK sharedSDK].teamManager updateNotifyState:self.selectState inTeam:self.team.teamId completion:^(NSError * _Nullable error)
  56. {
  57. [NIMKitProgressHUD dismiss];
  58. if (!error)
  59. {
  60. [weakSelf.navigationController popViewControllerAnimated:YES];
  61. [weakSelf.navigationController.view makeToast:@"修改成功" duration:2.0 position:CSToastPositionCenter];
  62. }
  63. else
  64. {
  65. [weakSelf.view makeToast:@"修改失败" duration:2.0 position:CSToastPositionCenter];
  66. }
  67. }];
  68. }
  69. else
  70. {
  71. [self.navigationController popViewControllerAnimated:YES];
  72. }
  73. }
  74. - (NSArray*)buildBodyData
  75. {
  76. NIMTeamNotifyState state = self.selectState;
  77. NIMTeamCardRowItem *notifyAll = [[NIMTeamCardRowItem alloc] init];
  78. notifyAll.title = @"提醒所有消息";
  79. notifyAll.rowHeight = 50.f;
  80. notifyAll.type = (state == NIMTeamNotifyStateAll)? TeamCardRowItemTypeCheckMark : TeamCardRowItemTypeCommon;
  81. notifyAll.value = @(NIMTeamNotifyStateAll);
  82. NIMTeamCardRowItem *notifyManager = [[NIMTeamCardRowItem alloc] init];
  83. notifyManager.title = @"只提醒管理员消息";
  84. notifyManager.rowHeight = 50.f;
  85. notifyManager.type = (state == NIMTeamNotifyStateOnlyManager)? TeamCardRowItemTypeCheckMark : TeamCardRowItemTypeCommon;
  86. notifyManager.value = @(NIMTeamNotifyStateOnlyManager);
  87. NIMTeamCardRowItem *notifyNone = [[NIMTeamCardRowItem alloc] init];
  88. notifyNone.title = @"不提醒任何消息";
  89. notifyNone.rowHeight = 50.f;
  90. notifyNone.type = (state == NIMTeamNotifyStateNone)? TeamCardRowItemTypeCheckMark : TeamCardRowItemTypeCommon;
  91. notifyNone.value = @(NIMTeamNotifyStateNone);
  92. return @[@[notifyAll,notifyManager,notifyNone]];
  93. }
  94. #pragma mark - UITableViewDataSource
  95. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  96. return self.bodyData.count;
  97. }
  98. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  99. {
  100. NSArray *sectionData = self.bodyData[section];
  101. return sectionData.count;
  102. }
  103. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. id<NTESCardBodyData> bodyData = [self bodyDataAtIndexPath:indexPath];
  106. return bodyData.rowHeight;
  107. }
  108. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  109. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  110. view.backgroundColor = NIMKit_UIColorFromRGB(0xecf1f5);
  111. return view;
  112. }
  113. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  114. id<NTESCardBodyData> bodyData = [self bodyDataAtIndexPath:indexPath];
  115. static NSString *NIMTeamTableCellReuseId = @"cell";
  116. UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NIMTeamTableCellReuseId];
  117. if (!cell)
  118. {
  119. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NIMTeamTableCellReuseId];
  120. }
  121. cell.accessoryType = (bodyData.type == TeamCardRowItemTypeCheckMark)? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  122. cell.textLabel.text = bodyData.title;
  123. return cell;
  124. }
  125. #pragma mark - UITableViewDelegate
  126. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  127. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  128. NSArray *scections = self.bodyData[indexPath.section];
  129. id<NTESCardBodyData> bodyData = scections[indexPath.row];
  130. self.selectState = [[bodyData value] integerValue];
  131. self.bodyData = [self buildBodyData];
  132. [self.tableView reloadData];
  133. }
  134. - (id<NTESCardBodyData>)bodyDataAtIndexPath:(NSIndexPath*)indexpath{
  135. NSArray *sectionData = self.bodyData[indexpath.section];
  136. return sectionData[indexpath.row];
  137. }
  138. @end