JXAutoReplyAideVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // JXAutoReplyAideVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/5/14.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXAutoReplyAideVC.h"
  9. #import "JXReplyAideKeyManageVC.h"
  10. #import "UIImage+Color.h"
  11. @interface JXAutoReplyAideVC ()
  12. @property (nonatomic, strong) UIButton *addBtn;
  13. @property (nonatomic, strong) UIButton *delBtn;
  14. @property (nonatomic, strong) UIButton *replaceBtn;
  15. @property (nonatomic, strong) UIView *keyView;
  16. @property (nonatomic, strong) UIView *noKeyView;
  17. @property (nonatomic, strong) UIButton *manageBtn;
  18. @property (nonatomic, strong) NSMutableArray *keys;
  19. @property (nonatomic, strong) UIView *baseView;
  20. @property (nonatomic, strong) NSArray *groupHelperArr;
  21. @end
  22. @implementation JXAutoReplyAideVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.heightHeader = JX_SCREEN_TOP;
  27. self.heightFooter = 0;
  28. self.isGotoBack = YES;
  29. [self createHeadAndFoot];
  30. _keys = [[NSMutableArray alloc] init];
  31. self.title = self.model.name;
  32. [self customView];
  33. }
  34. - (void)viewWillAppear:(BOOL)animated {
  35. [super viewWillAppear:animated];
  36. self.groupHelperArr = [NSArray array];
  37. for (UIView *view in _keyView.subviews) {
  38. [view removeFromSuperview];
  39. }
  40. [g_server queryGroupHelper:self.roomId toView:self];
  41. }
  42. - (void)customView {
  43. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 20, 50, 50)];
  44. imageView.layer.cornerRadius = 50 / 2;
  45. imageView.layer.masksToBounds = YES;
  46. [self.tableBody addSubview:imageView];
  47. [imageView sd_setImageWithURL:[NSURL URLWithString:self.model.iconUrl] placeholderImage:[UIImage imageNamed:@"avatar_normal"]];
  48. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame) + 10, imageView.frame.origin.y, 200, imageView.frame.size.height)];
  49. label.font = [UIFont systemFontOfSize:16.0];
  50. label.text = self.model.name;
  51. [self.tableBody addSubview:label];
  52. _addBtn = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 65, 33, 50, 24)];
  53. _addBtn.custom_acceptEventInterval = 1.f;
  54. [_addBtn setTitle:Localized(@"JX_Add") forState:UIControlStateNormal];
  55. [_addBtn setTitle:Localized(@"JX_Delete") forState:UIControlStateSelected];
  56. [_addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  57. [_addBtn setBackgroundImage:[UIImage createImageWithColor:THEMECOLOR] forState:UIControlStateNormal];
  58. [_addBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0xFA2524)] forState:UIControlStateSelected];
  59. _addBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
  60. _addBtn.layer.cornerRadius = 3.0;
  61. _addBtn.layer.masksToBounds = YES;
  62. [_addBtn addTarget:self action:@selector(onAdd:) forControlEvents:UIControlEventTouchUpInside];
  63. [self.tableBody addSubview:_addBtn];
  64. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(imageView.frame) + 20, JX_SCREEN_WIDTH - 15, LINE_WH)];
  65. lineView.backgroundColor = THE_LINE_COLOR;
  66. [self.tableBody addSubview:lineView];
  67. label = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lineView.frame), JX_SCREEN_WIDTH - 30, 50)];
  68. label.font = [UIFont systemFontOfSize:14.0];
  69. label.numberOfLines = 0;
  70. label.textColor = [UIColor lightGrayColor];
  71. label.text = self.model.desc;
  72. [self.tableBody addSubview:label];
  73. lineView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(label.frame), JX_SCREEN_WIDTH, LINE_WH)];
  74. lineView.backgroundColor = THE_LINE_COLOR;
  75. [self.tableBody addSubview:lineView];
  76. UILabel *deveLab = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lineView.frame)+20, JX_SCREEN_WIDTH-30, 20)];
  77. deveLab.text = [NSString stringWithFormat:@"%@:%@",Localized(@"JX_Developer"),self.model.developer];
  78. deveLab.font = SYSFONT(15);
  79. deveLab.textColor = [UIColor lightGrayColor];
  80. [self.tableBody addSubview:deveLab];
  81. UILabel *tintLab = [[UILabel alloc] init];
  82. tintLab.text = [NSString stringWithFormat:Localized(@"JX_GroupAssistantsDisclaimer"),self.model.developer];
  83. tintLab.textColor = [UIColor lightGrayColor];
  84. tintLab.font = SYSFONT(15);
  85. tintLab.numberOfLines = 0;
  86. [self.tableBody addSubview:tintLab];
  87. CGSize size = [tintLab.text boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:tintLab.font} context:nil].size;
  88. tintLab.frame = CGRectMake(15, CGRectGetMaxY(deveLab.frame), JX_SCREEN_WIDTH-30, size.height);
  89. if (self.model.type == 1 || self.model.type == 2) {
  90. _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(tintLab.frame)+20, JX_SCREEN_WIDTH, self.tableBody.frame.size.height-CGRectGetMaxY(tintLab.frame)-20)];
  91. [self.tableBody addSubview:_baseView];
  92. lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 30)];
  93. lineView.backgroundColor = HEXCOLOR(0xF2F2F2);
  94. [_baseView addSubview:lineView];
  95. label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, JX_SCREEN_WIDTH - 15, 30)];
  96. label.font = [UIFont systemFontOfSize:14.0];
  97. label.numberOfLines = 0;
  98. label.textColor = [UIColor lightGrayColor];
  99. label.text = Localized(@"JX_GroupAddedKeywords");
  100. [lineView addSubview:label];
  101. _manageBtn = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 55, 0, 45, 30)];
  102. _manageBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
  103. [_manageBtn setTitle:Localized(@"JX_KeywordsAdministration") forState:UIControlStateNormal];
  104. [_manageBtn setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  105. [_manageBtn addTarget:self action:@selector(keyManage) forControlEvents:UIControlEventTouchUpInside];
  106. [lineView addSubview:_manageBtn];
  107. _keyView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(lineView.frame), JX_SCREEN_WIDTH, 0)];
  108. [_baseView addSubview:_keyView];
  109. _noKeyView = [[UIView alloc] initWithFrame:CGRectMake(0, (_baseView.frame.size.height-140)/2, JX_SCREEN_WIDTH, 140)];
  110. [_baseView addSubview:_noKeyView];
  111. imageView = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH - 50) / 2, 0, 50, 50)];
  112. imageView.image = [UIImage imageNamed:@"ALOGO_120"];
  113. [_noKeyView addSubview:imageView];
  114. label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame), JX_SCREEN_WIDTH, 30)];
  115. label.font = [UIFont systemFontOfSize:14.0];
  116. label.textAlignment = NSTextAlignmentCenter;
  117. label.textColor = [UIColor lightGrayColor];
  118. label.text = Localized(@"JX_NoKeywords");
  119. [_noKeyView addSubview:label];
  120. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH - 150)/2, CGRectGetMaxY(label.frame) + 10, 150, 30)];
  121. btn.layer.cornerRadius = 3.0;
  122. btn.layer.masksToBounds = YES;
  123. btn.backgroundColor = THEMECOLOR;
  124. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  125. [btn setTitle:Localized(@"JX_Add") forState:UIControlStateNormal];
  126. [btn addTarget:self action:@selector(keyManage) forControlEvents:UIControlEventTouchUpInside];
  127. [_noKeyView addSubview:btn];
  128. // _noKeyView.frame = CGRectMake(_noKeyView.frame.origin.x, _noKeyView.frame.origin.y, _noKeyView.frame.size.width, CGRectGetMaxY(btn.frame));
  129. // _noKeyView.center = CGPointMake(_noKeyView.center.x, _keyView.frame.size.height / 2 - 50);
  130. // _noKeyView.hidden = YES;
  131. }
  132. }
  133. - (void)onAdd:(UIButton *)button {
  134. if (button.selected) {
  135. for (JXGroupHeplerModel *hModel in self.groupHelperArr) {
  136. if ([hModel.helperId isEqualToString:self.model.helperId]) {
  137. [g_server deleteGroupHelper:hModel.groupHelperId toView:self];
  138. }
  139. }
  140. }else {
  141. [g_server addGroupHelper:self.roomId roomJid:self.roomJid helperId:self.model.helperId toView:self];
  142. }
  143. }
  144. - (void)keyManage {
  145. JXReplyAideKeyManageVC *vc = [[JXReplyAideKeyManageVC alloc] init];
  146. vc.keys = self.keys;
  147. vc.roomId = self.roomId;
  148. vc.helperId = self.model.helperId;
  149. vc.model = self.model;
  150. [g_navigation pushViewController:vc animated:YES];
  151. }
  152. - (void)createKeys {
  153. CGFloat y = 0;
  154. for (NSInteger i = 0; i < _keys.count; i ++) {
  155. NSDictionary *dic = _keys[i];
  156. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, y, JX_SCREEN_WIDTH - 15, 50)];
  157. label.font = [UIFont systemFontOfSize:16.0];
  158. label.text = [dic objectForKey:@"keyWord"];
  159. [_keyView addSubview:label];
  160. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(label.frame), JX_SCREEN_WIDTH - 15, LINE_WH)];
  161. lineView.backgroundColor = THE_LINE_COLOR;
  162. [_keyView addSubview:lineView];
  163. y = CGRectGetMaxY(lineView.frame);
  164. }
  165. _noKeyView.hidden = _keys.count > 0;
  166. _keyView.frame = CGRectMake(_keyView.frame.origin.x, _keyView.frame.origin.y, JX_SCREEN_WIDTH, y);
  167. self.tableBody.contentSize = CGSizeMake(0, CGRectGetMaxY(_keyView.frame));
  168. }
  169. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  170. [_wait stop];
  171. // 获取群助手
  172. if ([aDownload.action isEqualToString:act_queryGroupHelper]) {
  173. NSMutableArray *arr = [[NSMutableArray alloc] init];
  174. for (int i = 0; i < array1.count; i++) {
  175. JXGroupHeplerModel *model = [[JXGroupHeplerModel alloc] init];
  176. [model getDataWithDict:array1[i]];
  177. [arr addObject:model];
  178. }
  179. _groupHelperArr = arr.copy;
  180. BOOL isHide = NO;
  181. for (JXGroupHeplerModel *hModel in _groupHelperArr) {
  182. if ([hModel.helperId isEqualToString:self.model.helperId]) {
  183. isHide = YES;
  184. _keys = hModel.keywords.mutableCopy;
  185. [self createKeys];
  186. }
  187. }
  188. _addBtn.selected = isHide;
  189. self.baseView.hidden = !isHide;
  190. }
  191. if ([aDownload.action isEqualToString:act_addGroupHelper]) {
  192. NSDictionary *dict = @{@"delete" : @0};
  193. [g_notify postNotificationName:kUpdateChatVCGroupHelperData object:dict];
  194. [g_server showMsg:Localized(@"JX_AddSuccess")];
  195. self.addBtn.selected = YES;
  196. self.baseView.hidden = NO;
  197. [g_server queryGroupHelper:self.roomId toView:self];
  198. }
  199. if ([aDownload.action isEqualToString:act_deleteGroupHelper]) {
  200. NSDictionary *dict = @{@"delete" : @1};
  201. [g_notify postNotificationName:kUpdateChatVCGroupHelperData object:dict];
  202. [g_server showMsg:Localized(@"JXAlert_DeleteOK")];
  203. self.addBtn.selected = NO;
  204. self.baseView.hidden = YES;
  205. }
  206. }
  207. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  208. [_wait stop];
  209. return show_error;
  210. }
  211. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  212. [_wait stop];
  213. return show_error;
  214. }
  215. -(void) didServerConnectStart:(JXConnection*)aDownload{
  216. [_wait start];
  217. }
  218. @end