JXSearchChatLogVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. //
  2. // JXSearchChatLogVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/6/25.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXSearchChatLogVC.h"
  9. #import "JXCell.h"
  10. #import "JXChatViewController.h"
  11. #import "JXRoomPool.h"
  12. #import "JXSearchFileLogVC.h"
  13. #import "JXSearchImageLogVC.h"
  14. @interface JXSearchChatLogVC () <UITextFieldDelegate>
  15. @property (nonatomic, strong) UITextField *seekTextField;
  16. @property (nonatomic, strong) NSMutableArray *array;
  17. @property (nonatomic,strong) UIView *selectView;
  18. @end
  19. @implementation JXSearchChatLogVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.heightHeader = JX_SCREEN_TOP;
  24. self.heightFooter = 0;
  25. self.isGotoBack = YES;
  26. self.isShowFooterPull = NO;
  27. self.isShowHeaderPull = NO;
  28. [self createHeadAndFoot];
  29. self.title = Localized(@"JX_FindChatContent");
  30. _array = [NSMutableArray array];
  31. //搜索输入框
  32. UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, 55)];
  33. // backView.backgroundColor = HEXCOLOR(0xf0f0f0);
  34. [self.view addSubview:backView];
  35. _seekTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, backView.frame.size.width - 30, 35)];
  36. _seekTextField.placeholder = [NSString stringWithFormat:@"%@", Localized(@"JX_SearchChatLog")];
  37. _seekTextField.textColor = [UIColor blackColor];
  38. [_seekTextField setFont:SYSFONT(14)];
  39. _seekTextField.backgroundColor = HEXCOLOR(0xf0f0f0);
  40. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_search"]];
  41. UIView *leftView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
  42. // imageView.center = CGPointMake(leftView.frame.size.width/2, leftView.frame.size.height/2);
  43. imageView.center = leftView.center;
  44. [leftView addSubview:imageView];
  45. _seekTextField.leftView = leftView;
  46. _seekTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  47. _seekTextField.leftViewMode = UITextFieldViewModeAlways;
  48. _seekTextField.borderStyle = UITextBorderStyleNone;
  49. _seekTextField.layer.masksToBounds = YES;
  50. _seekTextField.layer.cornerRadius = 3.f;
  51. _seekTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  52. _seekTextField.delegate = self;
  53. _seekTextField.returnKeyType = UIReturnKeyGoogle;
  54. [backView addSubview:_seekTextField];
  55. [_seekTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  56. self.tableView.tableHeaderView = backView;
  57. [self createSelectView];
  58. }
  59. - (void)createSelectView {
  60. if (!_selectView) {
  61. _selectView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.tableView.frame.size.width, self.tableView.frame.size.height - 50)];
  62. [self.tableView addSubview:_selectView];
  63. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectViewTap:)];
  64. [_selectView addGestureRecognizer:tap];
  65. UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, _selectView.frame.size.width, 30)];
  66. tip.textAlignment = NSTextAlignmentCenter;
  67. tip.textColor = [UIColor lightGrayColor];
  68. tip.text = Localized(@"JX_SearchChatContentQuickly");
  69. tip.font = [UIFont systemFontOfSize:14.0];
  70. [_selectView addSubview:tip];
  71. NSMutableArray *items = @[Localized(@"JX_Image"), Localized(@"JX_Video"), Localized(@"JX_File"), Localized(@"JXLink"), Localized(@"JX_Trading")].mutableCopy;
  72. if (![g_config.enablePayModule boolValue]) {
  73. [items removeObject:Localized(@"JX_Trading")];
  74. }
  75. CGFloat itemW = 100;
  76. CGFloat itemH = 60;
  77. CGFloat marginX = (JX_SCREEN_WIDTH - (itemW * 3)) / 2;
  78. CGFloat itemX = marginX;
  79. CGFloat itemY = CGRectGetMaxY(tip.frame) + 10;
  80. UIButton *lastItem= nil;
  81. for (NSInteger i = 0; i < items.count; i ++) {
  82. if (i % 3 == 0) {
  83. itemX = marginX;
  84. if (lastItem) {
  85. itemY = CGRectGetMaxY(lastItem.frame);
  86. }else {
  87. itemY = CGRectGetMaxY(tip.frame) + 10;
  88. }
  89. }else {
  90. itemX = CGRectGetMaxX(lastItem.frame);
  91. itemY = lastItem.frame.origin.y;
  92. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(itemX, ((itemH - 20) / 2) + itemY, LINE_WH, 20)];
  93. lineView.backgroundColor = THE_LINE_COLOR;
  94. [_selectView addSubview:lineView];
  95. }
  96. NSString *itemTitle = items[i];
  97. UIButton *item = [[UIButton alloc] initWithFrame:CGRectMake(itemX, itemY, itemW, itemH)];
  98. [item setTitle:itemTitle forState:UIControlStateNormal];
  99. [item setTitleColor:HEXCOLOR(0x576b95) forState:UIControlStateNormal];
  100. item.titleLabel.font = [UIFont systemFontOfSize:16.0];
  101. item.tag = i;
  102. [item addTarget:self action:@selector(itemAction:) forControlEvents:UIControlEventTouchUpInside];
  103. [_selectView addSubview:item];
  104. lastItem = item;
  105. }
  106. }
  107. }
  108. - (void)itemAction:(UIButton *)btn {
  109. NSInteger type = 0;
  110. switch (btn.tag) {
  111. case 0:{
  112. JXSearchImageLogVC *vc = [[JXSearchImageLogVC alloc] init];
  113. vc.isImage = YES;
  114. vc.user = self.user;
  115. [g_navigation pushViewController:vc animated:YES];
  116. return;
  117. }
  118. break;
  119. case 1:{
  120. JXSearchImageLogVC *vc = [[JXSearchImageLogVC alloc] init];
  121. vc.isImage = NO;
  122. vc.user = self.user;
  123. [g_navigation pushViewController:vc animated:YES];
  124. return;
  125. }
  126. break;
  127. case 2:
  128. type = FileLogType_file;
  129. break;
  130. case 3:
  131. type = FileLogType_Link;
  132. break;
  133. case 4:
  134. type = FileLogType_transact;
  135. break;
  136. default:
  137. break;
  138. }
  139. JXSearchFileLogVC *vc = [[JXSearchFileLogVC alloc] init];
  140. vc.type = type;
  141. vc.user = self.user;
  142. vc.isGroup = YES;
  143. [g_navigation pushViewController:vc animated:YES];
  144. }
  145. - (void)selectViewTap:(UITapGestureRecognizer *)tap {
  146. [self.view endEditing:YES];
  147. }
  148. - (void) textFieldDidChange:(UITextField *)textField {
  149. [_array removeAllObjects];
  150. if (textField.text.length <= 0) {
  151. _selectView.hidden = NO;
  152. [self.tableView reloadData];
  153. return;
  154. }
  155. _selectView.hidden = YES;
  156. NSArray * resultArray = [[JXMessageObject sharedInstance] fetchSearchMessageWithUserId:self.user.userId String:textField.text];
  157. for (JXMessageObject *msg in resultArray) {
  158. if(msg.content.length > 0) {
  159. JXMsgAndUserObject *searchObj = [[JXMsgAndUserObject alloc] init];
  160. searchObj.user = self.user;
  161. searchObj.message = msg;
  162. [_array addObject:searchObj];
  163. }
  164. }
  165. [self.tableView reloadData];
  166. }
  167. #pragma mark ---------tableView协议----------------
  168. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  169. {
  170. NSString* cellName = [NSString stringWithFormat:@"msg"];
  171. JXCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  172. JXMsgAndUserObject * dict = (JXMsgAndUserObject*) [_array objectAtIndex:indexPath.row];
  173. if(cell==nil){
  174. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];;
  175. [_table addToPool:cell];
  176. }
  177. cell.delegate = self;
  178. cell.didTouch = @selector(onHeadImage:);
  179. cell.didDragout=@selector(onDrag:);
  180. // [cell msgCellDataSet:dict indexPath:indexPath];
  181. cell.title = dict.user.userNickname;
  182. cell.userId = dict.user.userId;
  183. cell.bage = [NSString stringWithFormat:@"%d",[dict.user.msgsNew intValue]];
  184. cell.index = (int)indexPath.row;
  185. cell.bottomTitle = [TimeUtil getTimeStrStyle1:[dict.message.timeSend timeIntervalSince1970]];
  186. cell.headImageView.tag = (int)indexPath.row;
  187. cell.headImageView.delegate = cell.delegate;
  188. cell.headImageView.didTouch = cell.didTouch;
  189. [cell.lbTitle setText:cell.title];
  190. cell.lbTitle.tag = cell.index;
  191. if(dict.user.lastInput.length > 0) {
  192. NSString *str = Localized(@"JX_Draft");
  193. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",str, dict.user.lastInput]];
  194. NSRange range = [[NSString stringWithFormat:@"%@%@",str, dict.user.lastInput] rangeOfString:str];
  195. [attr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
  196. cell.lbSubTitle.attributedText = attr;
  197. }else {
  198. [cell setSubtitle:[dict.message getLastContent]];
  199. }
  200. [cell.timeLabel setText:cell.bottomTitle];
  201. cell.bageNumber.delegate = cell.delegate;
  202. cell.bageNumber.didDragout = cell.didDragout;
  203. cell.bage = cell.bage;
  204. if ([dict.user.userId isEqualToString:FRIEND_CENTER_USERID]) {
  205. cell.bageNumber.lb.hidden = YES;
  206. CGRect frame = cell.bageNumber.frame;
  207. frame.size = CGSizeMake(10, 10);
  208. cell.bageNumber.frame = frame;
  209. }else {
  210. cell.bageNumber.lb.hidden = NO;
  211. CGRect frame = cell.bageNumber.frame;
  212. frame.size = CGSizeMake(18, 18);
  213. cell.bageNumber.frame = frame;
  214. }
  215. NSString * roomIdStr = dict.user.roomId;
  216. cell.roomId = roomIdStr;
  217. cell.isSmall = NO;
  218. [cell headImageViewImageWithUserId:dict.user.userId roomId:roomIdStr];
  219. [self doAutoScroll:indexPath];
  220. // cell.selectionStyle = UITableViewCellSelectionStyleNone;
  221. if (dict.user.topTime) {
  222. cell.contentView.backgroundColor = HEXCOLOR(0xF0F1F2);
  223. }else {
  224. cell.contentView.backgroundColor = [UIColor whiteColor];
  225. }
  226. if (indexPath.row == [_array count]-1) {
  227. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,0);
  228. }else {
  229. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,LINE_WH);
  230. }
  231. return cell;
  232. }
  233. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  234. {
  235. return 1;
  236. }
  237. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  238. {
  239. return _array.count;
  240. }
  241. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  242. {
  243. return 68;
  244. }
  245. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  246. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  247. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  248. JXMsgAndUserObject *p=[_array objectAtIndex:indexPath.row];
  249. int lineNum = 0;
  250. if (_seekTextField.text.length > 0) {
  251. lineNum = [p.message getLineNumWithUserId:p.user.userId];
  252. }
  253. JXChatViewController *sendView=[JXChatViewController alloc];
  254. sendView.scrollLine = lineNum;
  255. sendView.title = p.user.userNickname;
  256. if([p.user.roomFlag intValue] > 0 || p.user.roomId.length > 0){
  257. if(g_xmpp.isLogined != 1){
  258. // 掉线后点击title重连
  259. [g_xmpp showXmppOfflineAlert];
  260. return;
  261. }
  262. sendView.roomJid = p.user.userId;
  263. sendView.roomId = p.user.roomId;
  264. sendView.groupStatus = p.user.groupStatus;
  265. if ([p.user.groupStatus intValue] == 0) {
  266. sendView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:p.user.userId title:p.user.userNickname lastDate:nil isNew:NO];
  267. }
  268. if (p.user.roomFlag) {
  269. NSDictionary * groupDict = [p.user toDictionary];
  270. roomData * roomdata = [[roomData alloc] init];
  271. [roomdata getDataFromDict:groupDict];
  272. sendView.room = roomdata;
  273. }
  274. }
  275. sendView.lastMsg = p.message;
  276. sendView.chatPerson = p.user;
  277. sendView = [sendView init];
  278. // [g_App.window addSubview:sendView.view];
  279. [g_navigation pushViewController:sendView animated:YES];
  280. sendView.view.hidden = NO;
  281. }
  282. - (void)didReceiveMemoryWarning {
  283. [super didReceiveMemoryWarning];
  284. // Dispose of any resources that can be recreated.
  285. }
  286. /*
  287. #pragma mark - Navigation
  288. // In a storyboard-based application, you will often want to do a little preparation before navigation
  289. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  290. // Get the new view controller using [segue destinationViewController].
  291. // Pass the selected object to the new view controller.
  292. }
  293. */
  294. @end