123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- //
- // JXSearchVC.m
- // shiku_im
- //
- // Created by IMAC on 2019/8/6.
- // Copyright © 2019 Reese. All rights reserved.
- //
- #import "JXSearchVC.h"
- #import "JXRoomMember.h"
- #import "JXChatViewController.h"
- #import "JXSearchListVC.h"
- #import "JXSearchShowCell.h"
- #import "JXSearchMoreCell.h"
- #import "JXSearchRecordCell.h"
- #import "JXClearAllRecordCell.h"
- #import "JXXMPP.h"
- #import "JXRoomPool.h"
- #import "JXChatViewC.h"
- @interface JXSearchVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate,JXSearchListDelegate, JXSearchRecordCellDelegate>
- {
- CGRect bounds;
- CGFloat cornerRadius;
- }
- @property (nonatomic,strong)UIView *baseView;
- @property (nonatomic,strong)UITableView *searchRecordView;
- @property (nonatomic,strong)UITableView *tableview;
- @property (nonatomic,strong)UISearchBar *searchbar;
- @property (nonatomic,strong)NSString *tableName;
- @property (nonatomic,strong)NSMutableArray *sectionArray;//tableView模块数组
- @property (nonatomic,strong)NSMutableDictionary *sectionDictonary;//tableView模块数据
- @property (nonatomic,strong)NSMutableArray *contactsArray;//联系人
- @property (nonatomic,strong)NSMutableArray *groupArray;//群组
- @property (nonatomic,strong)NSMutableDictionary *groupDictionary;
- @property (nonatomic,strong)NSMutableArray *publicArray;//公众号
- @property (nonatomic,strong)NSMutableArray *recordArray;//聊天记录
- @property (nonatomic,strong)NSMutableDictionary *msgDictionary;//消息字典
- @property (nonatomic,strong)NSMutableArray *searchRecordArray;
- //@property (nonatomic,strong)UIButton *cancelBtn;
- @property (nonatomic,strong)UIButton *backbtn;
- @property (nonatomic,strong)JXSearchListVC *searchListVC;
- @property (nonatomic,assign)BOOL isShow;
- @end
- @implementation JXSearchVC
- - (instancetype)initWithTable:(NSString *)table{
- self = [super init];
- if (self) {
- self.sectionArray = [NSMutableArray array];
- self.sectionDictonary = [NSMutableDictionary dictionary];
- self.contactsArray = [NSMutableArray array];
- self.groupArray = [NSMutableArray array];
- self.groupDictionary = [NSMutableDictionary dictionary];
- self.publicArray = [NSMutableArray array];
- self.recordArray = [NSMutableArray array];
- self.msgDictionary = [NSMutableDictionary dictionary];
- self.tableName = table;
- self.searchRecordArray = [[JXUserObject sharedInstance] fetchAllSearchRecordWithTable:self.tableName];
- _isShow = NO;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self creatView];
- cornerRadius = 7;
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- if (!_isShow) {
- [self.searchbar becomeFirstResponder];
- _isShow = YES;
- }
- }
- #pragma mark -- 界面控件
- - (void)creatView{
- UIView *stastusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, SCREEN_BAR)];
- if (THESIMPLESTYLE) {
- stastusBarView.backgroundColor = [UIColor whiteColor];
- }else{
- stastusBarView.backgroundColor = [g_theme themeColor];
- }
- [self.view addSubview:stastusBarView];
- //基础view
- self.baseView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_BAR, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_BAR)];
- self.baseView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.baseView];
- //导航栏
- UINavigationBar *bar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 44)];
- if (THESIMPLESTYLE) {
- bar.barTintColor = [UIColor whiteColor];
- }else{
- bar.barTintColor = [g_theme themeColor];
- }
- bar.translucent = NO;
- //搜索框
- // self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 5, JX_SCREEN_WIDTH-20, 33)];
- self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(40, 5, JX_SCREEN_WIDTH-55, 33)];
- self.searchbar.delegate = self;
- self.searchbar.placeholder = SEARCH;
- // self.searchbar.showsCancelButton = YES;
- //搜索框样式
- NSString *version = [UIDevice currentDevice].systemVersion;
- UITextField *searchField;
- if (version.doubleValue >= 13.0) {
- // 这里是对 13.0 以上的iOS系统进行处理
- NSUInteger Views = [self.searchbar.subviews count];
- for(int i = 0; i < Views; i++) {
- if([[self.searchbar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
- searchField = [self.searchbar.subviews objectAtIndex:i];
- }
- }
- //这里设置相关属性
- } else {
- // 这里是对 13.0 以下的iOS系统进行处理
- searchField = [self.searchbar valueForKey:@"_searchField"];
- //这里设置相关属性
- }
-
-
- // UITextField *seachTextFild = [self.searchbar valueForKey:@"_searchField"];
- searchField.tintColor = [g_theme themeColor];
- searchField.backgroundColor = HEXCOLOR(0xf2f2f2);
- UIView *backView = [self subViewOfClassName:@"_UISearchBarSearchFieldBackgroundView" toView:self.searchbar];
- backView.layer.cornerRadius = 5;
- backView.layer.masksToBounds = YES;
- backView.backgroundColor = HEXCOLOR(0xf2f2f2);
- // //自定义取消按钮样式
- // self.cancelBtn = [self.searchbar valueForKey:@"_cancelButton"];
- // [self.cancelBtn setTitle:CANCEL forState:UIControlStateNormal];
- // if (THESIMPLESTYLE) {
- // [self.cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- // }else{
- // [self.cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- // }
- [bar addSubview:self.searchbar];
- self.backbtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 11, 20, 20)];
- if (THESIMPLESTYLE) {
- [self.backbtn setBackgroundImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
- }else{
- [self.backbtn setBackgroundImage:[UIImage imageNamed:@"title_back"] forState:UIControlStateNormal];
-
- }
- [self.backbtn addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
- [bar addSubview:self.backbtn];
- [self.baseView addSubview:bar];
- //关键字查询信息的tableView
- self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW)];
- self.tableview.tag = 1;
- self.tableview.dataSource = self;
- self.tableview.delegate = self;
- self.tableview.backgroundColor = HEXCOLOR(0xf2f2f2);
- UIView *tableHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 8)];
- tableHead.backgroundColor = HEXCOLOR(0xf2f2f2);
- self.tableview.tableHeaderView = tableHead;
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 8)];
- view.backgroundColor = HEXCOLOR(0xf2f2f2);
- self.tableview.tableFooterView = view;
- self.tableview.separatorColor = HEXCOLOR(0xd9d9d9);
- [self.baseView addSubview:self.tableview];
- //指定内容查找
- self.searchRecordView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW)];
- self.searchRecordView.tag = 2;
- self.searchRecordView.delegate = self;
- self.searchRecordView.dataSource = self;
- self.searchRecordView.backgroundColor = HEXCOLOR(0xf2f2f2);
- self.searchRecordView.separatorColor = HEXCOLOR(0xd9d9d9);
- UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 8)];
- view2.backgroundColor = HEXCOLOR(0xf2f2f2);
- self.searchRecordView.tableFooterView = view2;
-
- [self.baseView addSubview:self.searchRecordView];
- }
- - (UIView*)subViewOfClassName:(NSString*)className toView:(UIView *)view{
- for (UIView* subView in view.subviews) {
- if ([NSStringFromClass(subView.class) isEqualToString:className]) {
- return subView;
- }
- UIView* resultFound = [self subViewOfClassName:className toView:subView];
- if (resultFound) {
- return resultFound;
- }
- }
- return nil;
- }
- #pragma mark -- 数据的计算
- //tavleview模块的行数
- - (NSInteger)displayCount:(NSMutableDictionary *)dic withArray:(NSMutableArray *)array withNumber:(NSInteger )i{
- if ([self arrayFromDictionary:dic forKey:array[i]].count == 0) {
- return 0;
- }
- if ([self arrayFromDictionary:dic forKey:array[i]].count != 0 && [self arrayFromDictionary:dic forKey:array[i]].count < 4) {
- return [self arrayFromDictionary:dic forKey:array[i]].count +1;
- }
- return 5;
- }
- //
- - (NSMutableArray *)arrayFromDictionary:(NSMutableDictionary *)dic forKey:(NSString *)key{
- NSMutableArray *array = [dic objectForKey:key];
- return array;
- }
- //读取某用户或群组对象
- - (JXUserObject *)readFromDictionary:(NSMutableDictionary *)dic withArray:(NSMutableArray *)array withNumber1:(NSInteger )i number2:(NSInteger )j{
- NSMutableArray* array1 = [dic objectForKey:array[i]];
- JXUserObject *user = array1[j];
- return user;
- }
- //添加显示的模块数和模块名
- - (void)displaySection{
- [self.sectionArray removeAllObjects];
- [self updateSectionWithContentArray:self.contactsArray withString:CONTACT];
- [self updateSectionWithContentArray:self.groupArray withString:GROUP];
- [self updateSectionWithContentArray:self.publicArray withString:PUBLIC];
- [self updateSectionWithContentArray:self.recordArray withString:RECORD];
- }
- //更新搜索到的数据
- - (void)updateSectionWithContentArray:(NSMutableArray *)array2 withString:(NSString *)str{
- if (array2.count !=0) {
- if (![self.sectionArray containsObject:str]) {
- [self.sectionArray addObject:str];
- }
- [self.sectionDictonary setObject:array2 forKey:str];
- }else{
- if ([self.sectionArray containsObject:str]) {
- [self.sectionArray removeObject:str];
- }
- if ([[self.sectionDictonary allKeys] containsObject:str]) {
- [self.sectionDictonary removeObjectForKey:str];
- }
- }
- }
- #pragma mark -- 获取数据
- //获取联系人数据
- - (void)getContactsWithText:(NSString *)text{
- NSMutableArray *array = [[JXUserObject sharedInstance] searchContacts:text];
- [self.contactsArray removeAllObjects];
- if (array.count != 0) {
- [self.contactsArray addObjectsFromArray:array];
- }
- }
- //获取群聊数据
- - (void)getGroupWithText:(NSString *)text{
- NSMutableArray *array1 = [[JXUserObject sharedInstance] searchGroup:text withContent:@"userNickname"];
- NSMutableArray *array2 = [[JXUserObject sharedInstance] searchGroupMember:text];
- [self.groupArray removeAllObjects];
- [self.groupDictionary removeAllObjects];
- if (array1.count != 0) {
- [self.groupArray addObjectsFromArray:array1];
- NSMutableArray *roomArray = [NSMutableArray array];
- for (JXUserObject *user2 in self.groupArray) {
- [roomArray addObject:user2.roomId];
- }
- for (memberData *member in array2) {
- JXUserObject *user = [[JXUserObject sharedInstance] groupForRoomId:member.roomId];
- if (![roomArray containsObject:user.roomId]) {
- [self.groupArray addObject:user];
- [self.groupDictionary setValue:member.userNickName forKey:user.roomId];
- }
- }
- }else{
- for (memberData *member in array2) {
- JXUserObject *user = [[JXUserObject sharedInstance] groupForRoomId:member.roomId];
- [self.groupArray addObject:user];
- [self.groupDictionary setValue:member.userNickName forKey:user.roomId];
-
- }
- }
- }
- //获取公众号数据
- - (void)getPublicWithText:(NSString *)text{
- NSMutableArray *array = [[JXUserObject sharedInstance] searchPublic:text];
- [self.publicArray removeAllObjects];
- if (array.count != 0) {
- [self.publicArray addObjectsFromArray:array];
- }
- }
- //获取聊天记录数据
- - (void)getChatRecordWithText:(NSString *)text{
- NSMutableArray *array = [NSMutableArray array];
- [self.recordArray removeAllObjects];
- self.msgDictionary = [[JXUserObject sharedInstance] searchChatRecordWithText:text];
- array = [[JXUserObject sharedInstance] getAllContactsAndGroup];
- for (JXUserObject *user in array) {
- if ([[self.msgDictionary allKeys] containsObject:user.userId] && ![self.recordArray containsObject:user]) {
- NSMutableArray *msgArr = [self.msgDictionary objectForKey:user.userId];
- if (msgArr.count > 0) {
- [self.recordArray addObject:user];
- }
- }
- }
- }
- - (NSInteger)getMsgCountWithUserId:(NSString *)userId{
- NSMutableArray *array = [self.msgDictionary objectForKey:userId];
- return array.count;
- }
- //判断哪个模块
- - (BOOL)compareSectionSring:(NSString *)str withIndexPath:(NSIndexPath *)indexPath{
- return [self arrayFromDictionary:self.sectionDictonary forKey:str].count != 0 && [self.sectionArray indexOfObject:str] == indexPath.section;
- }
- //返回标记搜索查找的字符串
- - (NSMutableAttributedString *)showSearchTextColor:(NSString *)str{
- NSRange range = [str rangeOfString:self.searchbar.text options:NSCaseInsensitiveSearch];
- NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str];
- if (range.location != NSNotFound) {
- [string addAttribute:NSForegroundColorAttributeName value:[g_theme themeColor] range:range];
- }
- return string;
- }
- #pragma mark -- searchBar的代理
- - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
-
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
- if (searchText.length == 0) {
- [self.searchRecordView reloadData];
- [self.baseView bringSubviewToFront:self.searchRecordView];
- }else{
- [self.baseView bringSubviewToFront:self.tableview];
- [self getContactsWithText:searchText];
- [self getGroupWithText:searchText];
- [self getPublicWithText:searchText];
- [self getChatRecordWithText:searchText];
- [self displaySection];
- if (self.sectionArray.count == 0) {
- self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
- }else{
- self.tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- }
- [self.tableview reloadData];
- }
- }
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
- [g_navigation dismissViewController:self animated:YES];
- }
- - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
- [self.searchbar becomeFirstResponder];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
- [self.searchbar resignFirstResponder];
- // [self.cancelBtn setEnabled:YES];
- }
- #pragma mark -- tableView的代理和数据源
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- [self.searchbar resignFirstResponder];
- // [self.cancelBtn setEnabled:YES];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (tableView.tag == 1) {
- if (indexPath.row == 0) {
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"sectionNameCell"];
- cell.textLabel.text = self.sectionArray[indexPath.section];
- cell.textLabel.textColor = HEXCOLOR(0x999999);
- cell.textLabel.font = [UIFont systemFontOfSize:14];
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- cell.textLabel.center = cell.center;
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 8, 0, 8)];
- cell.userInteractionEnabled = NO;
- return cell;
- }
- if (indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3) {
- JXSearchShowCell *cell = [[JXSearchShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"chatCell" withNewStyle:JXSearchShowCellStyleUser];
- JXUserObject *user = [self readFromDictionary:self.sectionDictonary withArray:self.sectionArray withNumber1:indexPath.section number2:indexPath.row-1];
- NSMutableAttributedString *nameAString = [self showSearchTextColor:user.userNickname];
- if ([self compareSectionSring:CONTACT withIndexPath:indexPath]) {
- if ([user.userNickname localizedCaseInsensitiveContainsString:self.searchbar.text]) {
- cell.aboveAttributedText = nameAString;
- }else{
- cell.aboveText = user.userNickname;
- NSMutableAttributedString *string1 = [self showSearchTextColor:user.userId];
- NSMutableAttributedString *string2 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@:",USERNUMBER]];
- [string2 appendAttributedString:string1];
- cell.belowAttributedText = string2;
- }
- [g_server getHeadImageSmall:user.userId userName:user.userNickname imageView:cell.headImgView];
- }
- if ([self compareSectionSring:GROUP withIndexPath:indexPath]) {
- NSString *str = user.roomId;
- NSString *containString = [self.groupDictionary objectForKey:str];
- if (![containString localizedStandardContainsString:self.searchbar.text]) {
- cell.aboveAttributedText = nameAString;
- }else{
- cell.aboveText = user.userNickname;
- NSMutableAttributedString *string3 = [self showSearchTextColor:containString];
- NSMutableAttributedString *string4 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@: ",CONTAIN]];
- [string4 appendAttributedString:string3];
- cell.belowAttributedText = string4;
- }
- [g_server getRoomHeadImageSmall:user.userId roomId:user.roomId imageView:cell.headImgView];
- }
- if ([self compareSectionSring:PUBLIC withIndexPath:indexPath]){
- cell.aboveAttributedText = nameAString;
- [g_server getHeadImageSmall:user.userId userName:user.userNickname imageView:cell.headImgView];
- }
- if ([self compareSectionSring:RECORD withIndexPath:indexPath]) {
- cell.aboveText = user.userNickname;
- NSInteger i = [self getMsgCountWithUserId:user.userId];
- NSString *str = [NSString stringWithFormat:@"%ld%@",(long)i,RECORDNUMBERS];
- cell.belowText = str;
- if (user.roomId) {
- [g_server getRoomHeadImageSmall:user.userId roomId:user.roomId imageView:cell.headImgView];
- }else{
- [g_server getHeadImageSmall:user.userId userName:user.userNickname imageView:cell.headImgView];
- }
- }
-
- if (indexPath.row == 3) {
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 8, 0, 8)];
- }
- return cell;
- }
- if (indexPath.row == 4) {
- JXSearchMoreCell *cell = [[JXSearchMoreCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"moreSearchCell"];
- cell.imgName = @"search_icon";
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.moreName = [NSString stringWithFormat:@"%@%@",MORE,self.sectionArray[indexPath.section]];
- return cell;
- }
- }
- if (indexPath.row == 0) {
- JXClearAllRecordCell *cell = [[JXClearAllRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"historycell" withTitle:@"history"];
- cell.imageView.image = [UIImage imageNamed:@"the_historical_record"];
- cell.textLabel.text = Localized(@"JX_HistoryRecord");
- cell.textLabel.font = [UIFont systemFontOfSize:15];
- cell.textLabel.textColor = HEXCOLOR(0x999999);
- cell.userInteractionEnabled = NO;
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 0)];
- return cell;
- }
- if (indexPath.row == _searchRecordArray.count + 1) {
- JXClearAllRecordCell *cell = [[JXClearAllRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"deleteallcell"];
- cell.textLabel.text = Localized(@"JX_ClearAllRecords");
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- cell.textLabel.font = [UIFont systemFontOfSize:15];
- cell.textLabel.textColor = HEXCOLOR(0xda4434);
- return cell;
- }
- JXSearchRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"searchRecirdCell"];
- if (!cell) {
- cell = [[JXSearchRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"searchRecirdCell"];
- }
- cell.delegate = self;
- cell.textLabel.text = self.searchRecordArray[indexPath.row - 1];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
- if (tableView.tag == 1) {
- cell.backgroundColor = UIColor.clearColor;
- CAShapeLayer *layer = [[CAShapeLayer alloc] init];
- CGMutablePathRef pathRef = CGPathCreateMutable();
- bounds = CGRectInset(cell.bounds, 8, 0);
- if (indexPath.row == 0) {
- CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
- CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
- }
- if (indexPath.row > 0 && indexPath.row != [tableView numberOfRowsInSection:indexPath.section] - 1) {
- CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), 0);
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), 0);
- CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
- }
- if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
- CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
- CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
- CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
-
- if ([cell isKindOfClass:[JXSearchShowCell class]]) {
- [((JXSearchShowCell *)cell) cutSelectedView];
- }
- }
- layer.path = pathRef;
- CFRelease(pathRef);
- layer.fillColor = [UIColor whiteColor].CGColor;
- UIView *backView = [[UIView alloc] initWithFrame:bounds];
- [backView.layer addSublayer:layer];
- backView.backgroundColor = [UIColor clearColor];
- cell.backgroundView = backView;
- }
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- if (tableView.tag == 1) {
- return self.sectionArray.count;
- }
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- if (tableView.tag == 1) {
- return [self displayCount:self.sectionDictonary withArray:self.sectionArray withNumber:section];
- }
- if (self.searchRecordArray.count == 0) {
- return 0;
- }
- return self.searchRecordArray.count + 2;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (tableView.tag == 1) {
- if (indexPath.row == 0) {
- return 44;
- }
- if (indexPath.row == 4) {
- return 50;
- }
- return 60;
- }
- // if (indexPath.row == 0) {
- // return 30;
- // }
- // if (indexPath.row == _searchRecordArray.count + 1) {
- // return 30;
- // }
- return 50;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- if (tableView.tag == 1) {
- if (section == _sectionArray.count - 1) {
- return 0;
- }
- return 10;
- }
- return 0;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- if (tableView.tag == 1) {
- if (section == _sectionArray.count - 1) {
- return nil;
- }
- UITableViewHeaderFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"tableHeaderFooter"];
- if (!footer) {
- footer = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"tableHeaderFooter"];
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 10)];
- view.backgroundColor = HEXCOLOR(0xf2f2f2);
- [footer addSubview:view];
- }
- return footer;
- }
- return nil;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if (tableView.tag == 1) {
- if (indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3){
- if ([self compareSectionSring:CONTACT withIndexPath:indexPath] || [self compareSectionSring:PUBLIC withIndexPath:indexPath]){
- JXUserObject *user = [self readFromDictionary:self.sectionDictonary withArray:self.sectionArray withNumber1:indexPath.section number2:indexPath.row-1];
- JXChatViewC *chatView = [[JXChatViewC alloc] init];
- chatView.chatPerson = user;
- [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
- [g_navigation pushViewController:chatView animated:YES];
- }
- if ([self compareSectionSring:GROUP withIndexPath:indexPath]) {
- JXUserObject *user = [self readFromDictionary:self.sectionDictonary withArray:self.sectionArray withNumber1:indexPath.section number2:indexPath.row-1];
- roomData * roomdata = [[roomData alloc] init];
- [roomdata getDataFromDict:[user toDictionary]];
- JXChatViewC *chatView = [JXChatViewC alloc];
- if ([user.groupStatus intValue] == 0) {
- chatView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
- }
- chatView.title = user.userNickname;
- chatView.roomJid = user.userId;
- chatView.roomId = user.roomId;
- chatView.groupStatus = user.groupStatus;
- chatView.room = roomdata;
- chatView.chatPerson = user;
- chatView = [chatView init];
- [g_navigation pushViewController:chatView animated:YES];
- [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
- }
- if ([self compareSectionSring:RECORD withIndexPath:indexPath]) {
- self.searchListVC = [[JXSearchListVC alloc] initWithLable:RECORD withSearchText:self.searchbar.text withUserArray:nil withGroupDictionary:nil withMsgDictionary:self.msgDictionary isChatRecord:YES enterChatRecord:YES withPeople:self.recordArray[indexPath.row-1]];
- [self showListView:indexPath];
- }
- // [self.cancelBtn setEnabled:YES];
- }
- if (indexPath.row == 4) {
- if ([self compareSectionSring:CONTACT withIndexPath:indexPath]) {
- self.searchListVC = [[JXSearchListVC alloc] initWithLable:CONTACT withSearchText:self.searchbar.text withUserArray:self.contactsArray withGroupDictionary:nil withMsgDictionary:nil isChatRecord:NO enterChatRecord:NO withPeople:nil];
- [self showListView:indexPath];
- }
- if ([self compareSectionSring:GROUP withIndexPath:indexPath]) {
- self.searchListVC = [[JXSearchListVC alloc] initWithLable:GROUP withSearchText:self.searchbar.text withUserArray:self.groupArray withGroupDictionary:self.groupDictionary withMsgDictionary:nil isChatRecord:NO enterChatRecord:NO withPeople:nil];
- [self showListView:indexPath];
- }
- if ([self compareSectionSring:PUBLIC withIndexPath:indexPath]) {
- self.searchListVC = [[JXSearchListVC alloc] initWithLable:PUBLIC withSearchText:self.searchbar.text withUserArray:self.publicArray withGroupDictionary:nil withMsgDictionary:nil isChatRecord:NO enterChatRecord:NO withPeople:nil];
- [self showListView:indexPath];
- }
- if ([self compareSectionSring:RECORD withIndexPath:indexPath]) {
- self.searchListVC = [[JXSearchListVC alloc] initWithLable:RECORD withSearchText:self.searchbar.text withUserArray:self.recordArray withGroupDictionary:nil withMsgDictionary:self.msgDictionary isChatRecord:YES enterChatRecord:NO withPeople:nil];
- [self showListView:indexPath];
- }
- [self.searchbar resignFirstResponder];
- // [self.cancelBtn setEnabled:YES];
- }
- BOOL saveSuccess = [[JXUserObject sharedInstance] insertSearchRecord:self.searchbar.text withTable:self.tableName];
- if (!saveSuccess) {
- NSLog(@"保存搜索记录失败");
- }
- [_searchRecordArray removeAllObjects];
- _searchRecordArray = [[JXUserObject sharedInstance] fetchAllSearchRecordWithTable:self.tableName];
- }
- if (tableView.tag == 2) {
- if (indexPath.row == _searchRecordArray.count + 1) {
- UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"" message:Localized(@"JX_WhetherToClearTheSearchHistory") preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:Localized(@"JX_Cencal") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:Localized(@"JX_Confirm") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [_searchRecordArray removeAllObjects];
- [[JXUserObject sharedInstance] deleteAllSearchRecordWithTable:self.tableName];
- [_searchRecordView reloadData];
- }];
- [alertCon addAction:sureAction];
- [alertCon addAction:cancelAction];
- [self presentViewController:alertCon animated:YES completion:nil];
- }else{
- self.searchbar.text = _searchRecordArray[indexPath.row - 1];
- [self searchBar:self.searchbar textDidChange:self.searchbar.text];
- }
- [self.searchRecordView deselectRowAtIndexPath:indexPath animated:YES];
- }
- }
- - (void)showListView:(NSIndexPath *)indexPath{
- self.searchListVC.view.backgroundColor = [UIColor clearColor];
- [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
- self.searchListVC.delegate = self;
- [self addChildViewController:self.searchListVC];
- [self.view addSubview:self.searchListVC.view];
- [self.searchbar resignFirstResponder];
- // [self.cancelBtn setEnabled:YES];
- }
- - (void)deleteCell:(JXSearchRecordCell *)cell{
- NSString *msg = cell.textLabel.text;
- [[JXUserObject sharedInstance] deleteOneSearchRecord:msg withTable:self.tableName];
- [_searchRecordArray removeAllObjects];
- _searchRecordArray = [[JXUserObject sharedInstance] fetchAllSearchRecordWithTable:self.tableName];
- [self.searchRecordView reloadData];
- }
- - (void)dismissView{
- [g_navigation dismissViewController:self animated:YES];
- }
- #pragma mark -- ListView代理
- - (void)saveSearchRecord:(NSString *)searchRecord{
- BOOL saveSuccess = [[JXUserObject sharedInstance] insertSearchRecord:searchRecord withTable:self.tableName];
- if (!saveSuccess) {
- NSLog(@"保存搜索记录失败");
- }
- [_searchRecordArray removeAllObjects];
- _searchRecordArray = [[JXUserObject sharedInstance] fetchAllSearchRecordWithTable:self.tableName];
- }
- - (void)tapSearchCancelBtn{
- [self.searchListVC removeFromParentViewController];
- [self.searchListVC.view removeFromSuperview];
- [g_navigation dismissViewController:self animated:YES];
- }
- - (void)tapBackBtn:(BOOL )hasRecord{
- if (hasRecord) {
- // self.searchListVC.backbtn.frame = CGRectMake(-20, 11, 20, 20);
- // self.searchListVC.searchbar.frame = CGRectMake(10, 5, JX_SCREEN_WIDTH-20, 33);
- [UIView animateWithDuration:0.3 animations:^{
- self.searchListVC.recordtableview.frame = CGRectMake(JX_SCREEN_WIDTH, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
- } completion:^(BOOL finished) {
- [self.searchListVC removeFromParentViewController];
- [self.searchListVC.view removeFromSuperview];
- }];
- }else{
- // self.searchListVC.backbtn.frame = CGRectMake(-20, 11, 20, 20);
- // self.searchListVC.searchbar.frame = CGRectMake(10, 5, JX_SCREEN_WIDTH-20, 33);
- [UIView animateWithDuration:0.3 animations:^{
- self.searchListVC.tableview.frame = CGRectMake(JX_SCREEN_WIDTH, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
- } completion:^(BOOL finished) {
- [self.searchListVC removeFromParentViewController];
- [self.searchListVC.view removeFromSuperview];
- }];
- }
- }
- - (void)listDidAppear:(BOOL )hasRecord{
- if (hasRecord) {
- // self.searchListVC.searchbar.frame = CGRectMake(40, 5, JX_SCREEN_WIDTH-50, 33);
- // self.searchListVC.backbtn.frame = CGRectMake(10, 11, 20, 20);
- [UIView animateWithDuration:0.3 animations:^{
- self.searchListVC.recordtableview.frame = CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
- }];
- }else{
- // self.searchListVC.searchbar.frame = CGRectMake(40, 5, JX_SCREEN_WIDTH-50, 33);
- // self.searchListVC.backbtn.frame = CGRectMake(10, 11, 20, 20);
- [UIView animateWithDuration:0.3 animations:^{
- self.searchListVC.tableview.frame = CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
- }];
- }
- }
- - (void)listWillDisappear:(BOOL)hasRecord {
-
- }
- @end
|