JXFriendViewController.m 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. //
  2. // JXFriendViewController.h.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "JXFriendViewController.h"
  8. #import "JXChatViewController.h"
  9. #import "AppDelegate.h"
  10. #import "JXLabel.h"
  11. #import "JXImageView.h"
  12. #import "JXCell.h"
  13. #import "JXRoomPool.h"
  14. #import "JXTableView.h"
  15. #import "JXNewFriendViewController.h"
  16. #import "menuImageView.h"
  17. #import "FMDatabase.h"
  18. #import "JXProgressVC.h"
  19. #import "JXTopSiftJobView.h"
  20. #import "JXUserInfoVC.h"
  21. #import "BMChineseSort.h"
  22. #import "JXGroupViewController.h"
  23. #import "OrganizTreeViewController.h"
  24. #import "JXTabMenuView.h"
  25. #import "JXPublicNumberVC.h"
  26. #import "JXBlackFriendVC.h"
  27. #import "JX_DownListView.h"
  28. #import "JXNewRoomVC.h"
  29. #import "JXNearVC.h"
  30. #import "JXSearchUserVC.h"
  31. #import "JXScanQRViewController.h"
  32. #import "JXLabelVC.h"
  33. #import "JXAddressBookVC.h"
  34. #import "JXSearchVC.h"
  35. #import "JXLabelObject.h"
  36. #import "CYWebCustomerServiceVC.h"
  37. #import "CYGroupSendHelperViewController.h"
  38. #import "JXSelectFriendsVC.h"
  39. #define HEIGHT 54
  40. #define IMAGE_HEIGHT 45 // 图片宽高
  41. #define INSET_HEIGHT 10 // 图片文字间距
  42. @interface JXFriendViewController ()<UITextFieldDelegate,JXSelectMenuViewDelegate>
  43. @property (nonatomic, strong) JXUserObject * currentUser;
  44. //排序后的出现过的拼音首字母数组
  45. @property(nonatomic,strong)NSMutableArray *indexArray;
  46. //排序好的结果数组
  47. @property(nonatomic,strong)NSMutableArray *letterResultArr;
  48. @property (nonatomic, strong) UITextField *seekTextField;
  49. @property (nonatomic, strong) NSMutableArray *searchArray;
  50. @property (nonatomic, strong) UILabel *friendNewMsgNum;
  51. @property (nonatomic, strong) UILabel *abNewMsgNum;
  52. @property (nonatomic, strong) UIButton *moreBtn;
  53. @property (nonatomic, strong) UIView *menuView;
  54. @property (nonatomic, assign) CGFloat btnHeight; // 按钮的真实高度
  55. @property (nonatomic,copy)NSArray *customerArr; //客服信息
  56. @end
  57. @implementation JXFriendViewController
  58. - (id)init
  59. {
  60. self = [super init];
  61. if (self) {
  62. self.isOneInit = YES;
  63. self.heightHeader = JX_SCREEN_TOP;
  64. self.heightFooter = JX_SCREEN_BOTTOM;
  65. if (_isMyGoIn) {
  66. self.isGotoBack = YES;
  67. self.heightFooter = 0;
  68. }
  69. // self.view.frame = g_window.bounds;
  70. [self createHeadAndFoot];
  71. [self buildTop];
  72. // CGRect frame = self.tableView.frame;
  73. // frame.origin.y += 40;
  74. // frame.size.height -= 40;
  75. // self.tableView.frame = frame;
  76. [self customView];
  77. _selMenu = 0;
  78. // self.title = Localized(@"JXInputVC_Friend");
  79. self.title = Localized(@"JX_MailList");
  80. [g_notify addObserver:self selector:@selector(newFriend:) name:kXMPPNewFriendNotifaction object:nil];
  81. [g_notify addObserver:self selector:@selector(newRequest:) name:kXMPPNewRequestNotifaction object:nil];
  82. [g_notify addObserver:self selector:@selector(newReceipt:) name:kXMPPReceiptNotifaction object:nil];
  83. [g_notify addObserver:self selector:@selector(onSendTimeout:) name:kXMPPSendTimeOutNotifaction object:nil];
  84. [g_notify addObserver:self selector:@selector(friendRemarkNotif:) name:kFriendRemark object:nil];
  85. [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];
  86. [g_notify addObserver:self selector:@selector(friendListRefresh:) name:kFriendListRefresh object:nil];
  87. [g_notify addObserver:self selector:@selector(refreshABNewMsgCount:) name:kRefreshAddressBookNotif object:nil];
  88. [g_notify addObserver:self selector:@selector(contactRegisterNotif:) name:kMsgComeContactRegister object:nil];
  89. [g_notify addObserver:self selector:@selector(newRequest:) name:kFriendPassNotif object:nil];
  90. [g_notify addObserver:self selector:@selector(refresh) name:kOfflineOperationUpdateUserSet object:nil];
  91. [g_notify addObserver:self selector:@selector(updateLabels:) name:kXMPPMessageUpadtePasswordNotification object:nil];
  92. // [g_server customerLinkList:self];
  93. [self setupCustomerLinkList];
  94. [self refresh];
  95. }
  96. return self;
  97. }
  98. - (void)updateLabels:(NSNotification *)noti {
  99. JXMessageObject *msg = noti.object;
  100. if ([msg.objectId isEqualToString:SYNC_LABEL]) {
  101. // 同步标签
  102. [g_server friendGroupListToView:self];
  103. }
  104. }
  105. - (void)friendListRefresh:(NSNotification *)notif {
  106. [self refresh];
  107. }
  108. - (void)contactRegisterNotif:(NSNotification *)notif {
  109. JXMessageObject *msg = notif.object;
  110. NSDictionary *dict = (NSDictionary *)msg.content;
  111. if ([msg.content isKindOfClass:[NSString class]]) {
  112. SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  113. dict = [resultParser objectWithString:msg.content];
  114. }
  115. JXAddressBook *addressBook = [[JXAddressBook alloc] init];
  116. addressBook.toUserId = [NSString stringWithFormat:@"%@",dict[@"toUserId"]];
  117. addressBook.toUserName = dict[@"toUserName"];
  118. addressBook.toTelephone = dict[@"toTelephone"];
  119. addressBook.telephone = dict[@"telephone"];
  120. addressBook.registerEd = dict[@"registerEd"];
  121. addressBook.registerTime = [NSDate dateWithTimeIntervalSince1970:[dict[@"registerTime"] longLongValue]];
  122. addressBook.isRead = [NSNumber numberWithBool:0];
  123. [addressBook insert];
  124. [self refreshABNewMsgCount:nil];
  125. }
  126. - (void)refreshABNewMsgCount:(NSNotification *)notif {
  127. [self refresh];
  128. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  129. newobj.user = [[JXUserObject sharedInstance] getUserById:FRIEND_CENTER_USERID];
  130. [self showNewMsgCount:[newobj.user.msgsNew integerValue]];
  131. }
  132. #pragma mark 接受新消息广播
  133. -(void)newMsgCome:(NSNotification *)notifacation
  134. {
  135. JXMessageObject *msg = notifacation.object;
  136. if (![msg isAddFriendMsg]) {
  137. return;
  138. }
  139. NSString* s;
  140. s = [msg getTableName];
  141. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  142. newobj.user = [[JXUserObject sharedInstance] getUserById:s];
  143. [self showNewMsgCount:[newobj.user.msgsNew integerValue]];
  144. }
  145. - (void) showNewMsgCount:(NSInteger)friendNewMsgNum {
  146. if (friendNewMsgNum >= 10 && friendNewMsgNum <= 99) {
  147. self.friendNewMsgNum.font = SYSFONT(12);
  148. }else if (friendNewMsgNum > 0 && friendNewMsgNum < 10) {
  149. self.friendNewMsgNum.font = SYSFONT(13);
  150. }else if(friendNewMsgNum > 99){
  151. self.friendNewMsgNum.font = SYSFONT(9);
  152. }
  153. self.friendNewMsgNum.text = [NSString stringWithFormat:@"%ld",friendNewMsgNum];
  154. if (friendNewMsgNum <= 0) {
  155. self.friendNewMsgNum.hidden = YES;
  156. }else{
  157. self.friendNewMsgNum.hidden = NO;
  158. }
  159. NSMutableArray *abUread = [[JXAddressBook sharedInstance] doFetchUnread];
  160. if (abUread.count >= 10 && abUread.count <= 99) {
  161. self.friendNewMsgNum.font = SYSFONT(12);
  162. }else if (abUread.count > 0 && abUread.count < 10) {
  163. self.friendNewMsgNum.font = SYSFONT(13);
  164. }else if(abUread.count > 99){
  165. self.friendNewMsgNum.font = SYSFONT(9);
  166. }
  167. self.abNewMsgNum.text = [NSString stringWithFormat:@"%ld",abUread.count];
  168. if (abUread.count <= 0) {
  169. self.abNewMsgNum.hidden = YES;
  170. }else {
  171. self.abNewMsgNum.hidden = NO;
  172. }
  173. NSInteger num = friendNewMsgNum + abUread.count;
  174. // if (num <= 0) {
  175. // [g_mainVC.tb setBadge:1 title:@"0"];
  176. // }else {
  177. // [g_mainVC.tb setBadge:1 title:[NSString stringWithFormat:@"%ld", num]];
  178. // }
  179. if (num <= 0) {
  180. int number = 0;
  181. if (g_App.linkArray.count == 0) {
  182. number = 1;
  183. }else if(g_App.linkArray.count == 1){
  184. number = 2;
  185. }else if(g_App.linkArray.count == 2){
  186. number = 3;
  187. }
  188. [g_mainVC.tb setBadge:number title:@"0"];
  189. }else {
  190. int number = 0;
  191. if (g_App.linkArray.count == 0) {
  192. number = 1;
  193. }else if(g_App.linkArray.count == 1){
  194. number = 2;
  195. }else if(g_App.linkArray.count == 2){
  196. number = 3;
  197. }
  198. [g_mainVC.tb setBadge:number title:[NSString stringWithFormat:@"%ld", num]];
  199. }
  200. }
  201. -(void)newRequest:(NSNotification *)notifacation
  202. {
  203. [self getFriend];
  204. }
  205. - (void)scrollToPageUp {
  206. [self getFriend];
  207. }
  208. -(void)buildTop{
  209. //刷新好友列表
  210. // UIButton * getFriendBtn = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-35, JX_SCREEN_TOP - 34, 30, 30)];
  211. // getFriendBtn.custom_acceptEventInterval = .25f;
  212. // [getFriendBtn addTarget:self action:@selector(getFriend) forControlEvents:UIControlEventTouchUpInside];
  213. //// [getFriendBtn setImage:[UIImage imageNamed:@"synchro_friends"] forState:UIControlStateNormal];
  214. // [getFriendBtn setBackgroundImage:[UIImage imageNamed:@"synchro_friends"] forState:UIControlStateNormal];
  215. // [self.tableHeader addSubview:getFriendBtn];
  216. self.moreBtn = [UIFactory createButtonWithImage:@"im_003_more_button_black"
  217. highlight:nil
  218. target:self
  219. selector:@selector(onMore:)];
  220. self.moreBtn.custom_acceptEventInterval = 1.0f;
  221. self.moreBtn.frame = CGRectMake(JX_SCREEN_WIDTH - 18-BTN_RANG_UP*2, JX_SCREEN_TOP - 18-BTN_RANG_UP*2, 18+BTN_RANG_UP*2, 18+BTN_RANG_UP*2);
  222. [self.tableHeader addSubview:self.moreBtn];
  223. }
  224. - (void) customView {
  225. //顶部筛选控件
  226. // _topSiftView = [[JXTopSiftJobView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, 40)];
  227. // _topSiftView.delegate = self;
  228. // _topSiftView.isShowMoreParaBtn = NO;
  229. // _topSiftView.dataArray = [[NSArray alloc] initWithObjects:Localized(@"JXInputVC_FriendList"),Localized(@"JX_BlackList"), nil];
  230. // // _topSiftView.searchForType = SearchForPos;
  231. // [self.view addSubview:_topSiftView];
  232. //搜索输入框
  233. backView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, 55)];
  234. // backView.backgroundColor = HEXCOLOR(0xf0f0f0);
  235. [self.view addSubview:backView];
  236. self.tableView.tableHeaderView = backView;
  237. // [seekImgView release];
  238. // UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(backView.frame.size.width-5-45, 5, 45, 30)];
  239. // [cancelBtn setTitle:Localized(@"JX_Cencal") forState:UIControlStateNormal];
  240. // [cancelBtn setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  241. // [cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
  242. // cancelBtn.titleLabel.font = SYSFONT(14.0);
  243. // [backView addSubview:cancelBtn];
  244. _seekTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, backView.frame.size.width - 30, 35)];
  245. _seekTextField.placeholder = Localized(@"JX_Seach");
  246. _seekTextField.textColor = [UIColor blackColor];
  247. [_seekTextField setFont:SYSFONT(14)];
  248. _seekTextField.backgroundColor = HEXCOLOR(0xf0f0f0);
  249. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_search"]];
  250. UIView *leftView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
  251. // imageView.center = CGPointMake(leftView.frame.size.width/2, leftView.frame.size.height/2);
  252. imageView.center = leftView.center;
  253. [leftView addSubview:imageView];
  254. _seekTextField.leftView = leftView;
  255. _seekTextField.leftViewMode = UITextFieldViewModeAlways;
  256. _seekTextField.borderStyle = UITextBorderStyleNone;
  257. _seekTextField.layer.masksToBounds = YES;
  258. _seekTextField.layer.cornerRadius = 5;
  259. _seekTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  260. _seekTextField.delegate = self;
  261. _seekTextField.returnKeyType = UIReturnKeyGoogle;
  262. [backView addSubview:_seekTextField];
  263. [_seekTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  264. // int h = 0;
  265. // JXImageView* iv;
  266. // iv = [self createButton:Localized(@"JXNewFriendVC_NewFirend") drawTop:NO drawBottom:YES icon:@"im_10001" click:@selector(newFriendAction:) superView:backView];
  267. // iv.frame = CGRectMake(0, CGRectGetMaxY(lineView.frame), JX_SCREEN_WIDTH, HEIGHT);
  268. // h = iv.frame.size.height + iv.frame.origin.y;
  269. _menuView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_seekTextField.frame), JX_SCREEN_WIDTH, 190)];
  270. [backView addSubview:_menuView];
  271. int inset = 0;
  272. int n = 0;
  273. int m = 0;
  274. int X = 0;
  275. int Y = inset;
  276. UIButton *button;
  277. // 新的朋友
  278. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JXNewFriendVC_NewFirend") icon:@"friend_newFriend" action:@selector(newFriendAction:)];
  279. [_menuView addSubview:button];
  280. // 图片在button中的左右间隙
  281. int leftInset = (button.frame.size.width - IMAGE_HEIGHT)/2;
  282. self.friendNewMsgNum = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.size.width-leftInset - 10, 20-5, 20, 20)];
  283. self.friendNewMsgNum.backgroundColor = HEXCOLOR(0xEF2D37);
  284. self.friendNewMsgNum.font = SYSFONT(12);
  285. self.friendNewMsgNum.textAlignment = NSTextAlignmentCenter;
  286. self.friendNewMsgNum.layer.cornerRadius = self.friendNewMsgNum.frame.size.width / 2;
  287. self.friendNewMsgNum.layer.masksToBounds = YES;
  288. self.friendNewMsgNum.textColor = [UIColor whiteColor];
  289. self.friendNewMsgNum.hidden = YES;
  290. self.friendNewMsgNum.text = @"99";
  291. [button addSubview:self.friendNewMsgNum];
  292. // iv = [self createButton:Localized(@"JX_ManyPerChat") drawTop:NO drawBottom:YES icon:@"function_icon_join_group_apply" click:@selector(myGroupAction:) superView:backView];
  293. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  294. // h += iv.frame.size.height;
  295. // 我的同事
  296. n = (n + 1) >= 4 ? 0 : n + 1;
  297. m += 1;
  298. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  299. Y = m >=4 ? button.frame.size.height+inset : inset;
  300. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"OrganizVC_Organiz") icon:@"friend_colleagues" action:@selector(myColleaguesAction:)];
  301. [_menuView addSubview:button];
  302. // 手机联系人
  303. n = (n + 1) >= 4 ? 0 : n + 1;
  304. m += 1;
  305. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  306. Y = m >=4 ? button.frame.size.height+inset : inset;
  307. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_MobilePhoneContacts") icon:@"friend_phone_list" action:@selector(addressBookAction:)];
  308. [_menuView addSubview:button];
  309. self.abNewMsgNum = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.size.width-leftInset - 10, 20-5, 20, 20)];
  310. self.abNewMsgNum.backgroundColor = [UIColor redColor];
  311. self.abNewMsgNum.font = SYSFONT(12);
  312. self.abNewMsgNum.textAlignment = NSTextAlignmentCenter;
  313. self.abNewMsgNum.layer.cornerRadius = self.abNewMsgNum.frame.size.width / 2;
  314. self.abNewMsgNum.layer.masksToBounds = YES;
  315. self.abNewMsgNum.textColor = [UIColor whiteColor];
  316. self.abNewMsgNum.hidden = YES;
  317. self.abNewMsgNum.text = @"99";
  318. [button addSubview:self.abNewMsgNum];
  319. // 公众号
  320. n = (n + 1) >= 4 ? 0 : n + 1;
  321. m += 1;
  322. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  323. Y = m >=4 ? button.frame.size.height+inset : inset;
  324. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_PublicNumber") icon:@"friend_public" action:@selector(publicNumberAction:)];
  325. [_menuView addSubview:button];
  326. // 群组
  327. n = (n + 1) >= 4 ? 0 : n + 1;
  328. m += 1;
  329. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  330. Y = m >=4 ? button.frame.size.height+inset : inset;
  331. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_ManyPerChat") icon:@"friend_group_list" action:@selector(myGroupAction:)];
  332. [_menuView addSubview:button];
  333. // 黑名单
  334. n = (n + 1) >= 4 ? 0 : n + 1;
  335. m += 1;
  336. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  337. Y = m >=4 ? button.frame.size.height+inset : inset;
  338. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_BlackList") icon:@"friend_black_list" action:@selector(blackFriendAction:)];
  339. [_menuView addSubview:button];
  340. // 我的设备
  341. // BOOL isMultipleLogin = [g_myself.multipleDevices intValue] > 0 ? YES : NO;
  342. // if (isMultipleLogin) {
  343. // n = (n + 1) >= 4 ? 0 : n + 1;
  344. // m += 1;
  345. // X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  346. // Y = m >=4 ? button.frame.size.height+inset : inset;
  347. // button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_MyDevices") icon:@"friend_device" action:@selector(myDeviceAction:)];
  348. // [_menuView addSubview:button];
  349. // }
  350. n = (n + 1) >= 4 ? 0 : n + 1;
  351. m += 1;
  352. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  353. Y = m >=4 ? button.frame.size.height+inset : inset;
  354. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:@"群发助手" icon:@"friend_colleagues" action:@selector(groupHelperAction:)];
  355. [_menuView addSubview:button];
  356. // 标签
  357. n = (n + 1) >= 4 ? 0 : n + 1;
  358. m += 1;
  359. X = JX_SCREEN_WIDTH/4 * (n >= 4 ? 0 : n);
  360. Y = m >=4 ? button.frame.size.height+inset : inset;
  361. button = [self createButtonWithFrame:CGRectMake(X, Y, JX_SCREEN_WIDTH/4, 0) title:Localized(@"JX_Label") icon:@"friend_label" action:@selector(labelAction:)];
  362. [_menuView addSubview:button];
  363. // iv = [self createButton:Localized(@"JX_Label") drawTop:NO drawBottom:YES icon:@"label" click:@selector(labelAction:) superView:backView];
  364. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  365. // h += iv.frame.size.height;
  366. //
  367. // iv = [self createButton:Localized(@"JX_PublicNumber") drawTop:NO drawBottom:YES icon:@"im_10000" click:@selector(publicNumberAction:) superView:backView];
  368. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  369. // h += iv.frame.size.height;
  370. // BOOL isMultipleLogin = [[g_default objectForKey:kISMultipleLogin] boolValue];
  371. // BOOL isMultipleLogin = [g_myself.multipleDevices intValue] > 0 ? YES : NO;
  372. // if (isMultipleLogin) {
  373. // iv = [self createButton:Localized(@"JX_MyDevices") drawTop:NO drawBottom:YES icon:@"feb" click:@selector(myDeviceAction:) superView:backView];
  374. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  375. // h += iv.frame.size.height;
  376. // }
  377. // iv = [self createButton:Localized(@"JX_BlackList") drawTop:NO drawBottom:YES icon:@"im_black" click:@selector(blackFriendAction:) superView:backView];
  378. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  379. // h += iv.frame.size.height;
  380. //
  381. // iv = [self createButton:Localized(@"OrganizVC_Organiz") drawTop:NO drawBottom:YES icon:@"im_colleague" click:@selector(myColleaguesAction:) superView:backView];
  382. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  383. // h += iv.frame.size.height;
  384. //
  385. // iv = [self createButton:Localized(@"JX_MobilePhoneContacts") drawTop:NO drawBottom:YES icon:@"sk_ic_pc" click:@selector(addressBookAction:) superView:backView];
  386. // iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  387. // h += iv.frame.size.height;
  388. // self.abNewMsgNum = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 35, (HEIGHT - 15) / 2, 15, 15)];
  389. // self.abNewMsgNum.backgroundColor = [UIColor redColor];
  390. // self.abNewMsgNum.font = [UIFont systemFontOfSize:11.0];
  391. // self.abNewMsgNum.textAlignment = NSTextAlignmentCenter;
  392. // self.abNewMsgNum.layer.cornerRadius = self.abNewMsgNum.frame.size.width / 2;
  393. // self.abNewMsgNum.layer.masksToBounds = YES;
  394. // self.abNewMsgNum.textColor = [UIColor whiteColor];
  395. // self.abNewMsgNum.text = @"99";
  396. // [iv addSubview:self.abNewMsgNum];
  397. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  398. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  399. newobj.user = [[JXUserObject sharedInstance] getUserById:FRIEND_CENTER_USERID];
  400. [self showNewMsgCount:[newobj.user.msgsNew integerValue]];
  401. });
  402. _btnHeight = button.frame.size.height;
  403. [self showMenuView];
  404. if (_isMyGoIn) {
  405. [self hideMenuView];
  406. }
  407. [self setFooterView];
  408. }
  409. - (void) setFooterView {
  410. if (_array.count > 0) {
  411. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 44)];
  412. label.textColor = HEXCOLOR(0x999999);
  413. label.textAlignment = NSTextAlignmentCenter;
  414. label.font = SYSFONT(16);
  415. label.text = [NSString stringWithFormat:@"%ld%@",_array.count,Localized(@"JX_ContactsNumber")];
  416. self.tableView.tableFooterView = label;
  417. }else {
  418. self.tableView.tableFooterView = nil;
  419. }
  420. }
  421. - (void)showMenuView { // 显示菜单栏
  422. _menuView.hidden = NO;
  423. CGRect backFrame = backView.frame;
  424. backFrame.size.height = _btnHeight*2 + 20 + 55;
  425. backView.frame = backFrame;
  426. CGRect menuFrame = _menuView.frame;
  427. menuFrame.size.height = _btnHeight*2 + 20;
  428. _menuView.frame = menuFrame;
  429. self.tableView.tableHeaderView = backView;
  430. }
  431. - (void)hideMenuView { // 隐藏菜单栏
  432. _menuView.hidden = YES;
  433. CGRect backFrame = backView.frame;
  434. backFrame.size.height = 55;
  435. backView.frame = backFrame;
  436. self.tableView.tableHeaderView = backView;
  437. }
  438. #pragma mark 右上角更多
  439. -(void)onMore:(UIButton *)sender{
  440. NSArray *role = MY_USER_ROLE;
  441. if ([g_App.config.hideSearchByFriends intValue] == 1 && ([g_App.config.isCommonFindFriends intValue] == 0 || role.count > 0)) {
  442. [self onSearch];
  443. }else {
  444. NSMutableArray *titles = [NSMutableArray arrayWithArray:@[Localized(@"JX_LaunchGroupChat"), Localized(@"JX_Scan"), Localized(@"JXNearVC_NearPer"),Localized(@"JX_SearchPublicNumber")]];
  445. NSMutableArray *images = [NSMutableArray arrayWithArray:@[@"message_creat_group_black", @"messaeg_scnning_black", @"message_near_person_black",@"message_search_publicNumber"]];
  446. NSMutableArray *sels = [NSMutableArray arrayWithArray:@[@"onNewRoom", @"showScanViewController", @"onNear",@"searchPublicNumber"]];
  447. if ([g_App.config.isCommonCreateGroup intValue] == 1 && role.count <= 0) {
  448. [titles removeObject:Localized(@"JX_LaunchGroupChat")];
  449. [images removeObject:@"message_creat_group_black"];
  450. [sels removeObject:@"onNewRoom"];
  451. }
  452. if ([g_App.config.isOpenPositionService intValue] == 1) {
  453. [titles removeObject:Localized(@"JXNearVC_NearPer")];
  454. [images removeObject:@"message_near_person_black"];
  455. [sels removeObject:@"onNear"];
  456. }
  457. if (![g_App.config.enableMpModule boolValue]) {
  458. [titles removeObject:Localized(@"JX_SearchPublicNumber")];
  459. [images removeObject:@"message_search_publicNumber"];
  460. [sels removeObject:@"searchPublicNumber"];
  461. }
  462. JX_SelectMenuView *menuView = [[JX_SelectMenuView alloc] initWithTitle:titles image:images cellHeight:44];
  463. menuView.sels = sels;
  464. menuView.delegate = self;
  465. [g_App.window addSubview:menuView];
  466. }
  467. // _control.hidden = YES;
  468. // UIWindow *window = [[UIApplication sharedApplication].delegate window];
  469. // CGRect moreFrame = [self.tableHeader convertRect:self.moreBtn.frame toView:window];
  470. //
  471. // JX_SelectMenuView *menuView = [[JX_SelectMenuView alloc] initWithTitle:@[Localized(@"JX_LaunchGroupChat"), Localized(@"JX_AddFriends"), Localized(@"JX_Scan"), Localized(@"JXNearVC_NearPer")] image:@[@"message_creat_group_black", @"message_add_friend_black", @"messaeg_scnning_black", @"message_near_person_black"] cellHeight:45];
  472. // menuView.delegate = self;
  473. // [g_App.window addSubview:menuView];
  474. // JX_DownListView * downListView = [[JX_DownListView alloc] initWithFrame:self.view.bounds];
  475. // downListView.listContents = @[Localized(@"JX_LaunchGroupChat"), Localized(@"JX_AddFriends"), Localized(@"JX_Scan"), Localized(@"JXNearVC_NearPer")];
  476. // downListView.listImages = @[@"message_creat_group_black", @"message_add_friend_black", @"messaeg_scnning_black", @"message_near_person_black"];
  477. //
  478. // __weak typeof(self) weakSelf = self;
  479. // [downListView downlistPopOption:^(NSInteger index, NSString *content) {
  480. //
  481. // [weakSelf moreListActionWithIndex:index];
  482. //
  483. // } whichFrame:moreFrame animate:YES];
  484. // [downListView show];
  485. // self.treeView.editing = !self.treeView.editing;
  486. }
  487. - (void)didMenuView:(JX_SelectMenuView *)MenuView WithIndex:(NSInteger)index {
  488. NSString *method = MenuView.sels[index];
  489. SEL _selector = NSSelectorFromString(method);
  490. [self performSelectorOnMainThread:_selector withObject:nil waitUntilDone:YES];
  491. // NSArray *role = MY_USER_ROLE;
  492. // // 显示搜索好友
  493. // BOOL isShowSearch = [g_App.config.hideSearchByFriends boolValue] && (![g_App.config.isCommonFindFriends boolValue] || role.count > 0);
  494. // //显示创建房间
  495. // BOOL isShowRoom = [g_App.config.isCommonCreateGroup intValue] == 0 || role.count > 0;
  496. // //显示附近的人
  497. // BOOL isShowPosition = [g_App.config.isOpenPositionService intValue] == 0;
  498. // switch (index) {
  499. // case 0:
  500. // if (isShowRoom) {
  501. // [self onNewRoom];
  502. // }else {
  503. // if (isShowSearch) {
  504. // [self onSearch];
  505. // }else {
  506. // [self showScanViewController];
  507. // }
  508. // }
  509. // break;
  510. // case 1:
  511. // if (isShowRoom && isShowSearch) {
  512. // [self onSearch];
  513. // }else {
  514. // if ((isShowRoom && !isShowSearch) || (!isShowRoom && isShowSearch)) {
  515. // [self showScanViewController];
  516. // }else if (!isShowRoom && !isShowSearch) {
  517. // if (isShowPosition) {
  518. // [self onNear];
  519. // }else {
  520. // [self searchPublicNumber];
  521. // }
  522. // }
  523. // }
  524. // break;
  525. // case 2:
  526. // if (isShowSearch && isShowRoom) {
  527. // [self showScanViewController];
  528. // }else {
  529. // if ((isShowRoom && !isShowSearch) || (!isShowRoom && isShowSearch)) {
  530. // if (isShowPosition) {
  531. // [self onNear];
  532. // }else {
  533. // [self searchPublicNumber];
  534. // }
  535. // }
  536. // }
  537. // break;
  538. // case 3:
  539. // if (isShowPosition) {
  540. // [self onNear];
  541. // }else {
  542. // [self searchPublicNumber];
  543. // }
  544. // break;
  545. // case 4:
  546. // [self searchPublicNumber];
  547. // break;
  548. // default:
  549. // break;
  550. // }
  551. }
  552. // 搜索公众号
  553. - (void)searchPublicNumber {
  554. JXSearchUserVC *searchUserVC = [JXSearchUserVC alloc];
  555. searchUserVC.type = JXSearchTypePublicNumber;
  556. searchUserVC = [searchUserVC init];
  557. [g_navigation pushViewController:searchUserVC animated:YES];
  558. }
  559. - (void) moreListActionWithIndex:(NSInteger)index {
  560. }
  561. // 创建群组
  562. -(void)onNewRoom{
  563. JXNewRoomVC* vc = [[JXNewRoomVC alloc]init];
  564. [g_navigation pushViewController:vc animated:YES];
  565. }
  566. // 附近的人
  567. -(void)onNear{
  568. JXNearVC * nearVc = [[JXNearVC alloc] init];
  569. [g_navigation pushViewController:nearVc animated:YES];
  570. }
  571. //搜索好友
  572. -(void)onSearch{
  573. JXSearchUserVC* vc = [JXSearchUserVC alloc];
  574. vc.delegate = self;
  575. vc.didSelect = @selector(doSearch:);
  576. vc.type = JXSearchTypeUser;
  577. vc = [vc init];
  578. [g_navigation pushViewController:vc animated:YES];
  579. [self cancelBtnAction];
  580. }
  581. -(void)doSearch:(searchData*)p{
  582. JXNearVC *nearVC = [[JXNearVC alloc]init];
  583. nearVC.isSearch = YES;
  584. [g_navigation pushViewController:nearVC animated:YES];
  585. [nearVC doSearch:p];
  586. }
  587. // 扫一扫
  588. -(void)showScanViewController{
  589. // button.enabled = NO;
  590. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  591. // button.enabled = YES;
  592. // });
  593. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  594. if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
  595. {
  596. [g_server showMsg:Localized(@"JX_CanNotopenCenmar")];
  597. return;
  598. }
  599. JXScanQRViewController * scanVC = [[JXScanQRViewController alloc] init];
  600. // [g_window addSubview:scanVC.view];
  601. [g_navigation pushViewController:scanVC animated:YES];
  602. }
  603. // 新朋友
  604. - (void)newFriendAction:(JXImageView *)imageView {
  605. // 清空角标
  606. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  607. newobj.user = [[JXUserObject sharedInstance] getUserById:FRIEND_CENTER_USERID];
  608. newobj.message = [[JXMessageObject alloc] init];
  609. newobj.message.toUserId = FRIEND_CENTER_USERID;
  610. newobj.user.msgsNew = [NSNumber numberWithInt:0];
  611. [newobj.message updateNewMsgsTo0];
  612. NSArray *friends = [[JXFriendObject sharedInstance] fetchAllFriendsFromLocal];
  613. for (NSInteger i = 0; i < friends.count; i ++) {
  614. JXFriendObject *friend = friends[i];
  615. if ([friend.msgsNew integerValue] > 0) {
  616. [friend updateNewMsgUserId:friend.userId num:0];
  617. [friend updateNewFriendLastContent];
  618. }
  619. }
  620. [self showNewMsgCount:0];
  621. JXNewFriendViewController* vc = [[JXNewFriendViewController alloc]init];
  622. [g_navigation pushViewController:vc animated:YES];
  623. }
  624. // 群组
  625. - (void)myGroupAction:(JXImageView *)imageView {
  626. JXGroupViewController *vc = [[JXGroupViewController alloc] init];
  627. [g_navigation pushViewController:vc animated:YES];
  628. }
  629. // 我的同事
  630. - (void)myColleaguesAction:(JXImageView *)imageView {
  631. OrganizTreeViewController *vc = [[OrganizTreeViewController alloc] init];
  632. [g_navigation pushViewController:vc animated:YES];
  633. }
  634. // 公众号
  635. - (void)publicNumberAction:(JXImageView *)imageView {
  636. JXPublicNumberVC *vc = [[JXPublicNumberVC alloc] init];
  637. [g_navigation pushViewController:vc animated:YES];
  638. }
  639. // 黑名单
  640. - (void)blackFriendAction:(JXImageView *)imageView {
  641. JXBlackFriendVC *vc = [[JXBlackFriendVC alloc] init];
  642. vc.title = Localized(@"JX_BlackList");
  643. [g_navigation pushViewController:vc animated:YES];
  644. }
  645. // 我的设备
  646. - (void)myDeviceAction:(JXImageView *)imageView {
  647. JXBlackFriendVC *vc = [[JXBlackFriendVC alloc] init];
  648. vc.isDevice = YES;
  649. vc.title = Localized(@"JX_MyDevices");
  650. [g_navigation pushViewController:vc animated:YES];
  651. }
  652. // 群发助手
  653. - (void)groupHelperAction:(JXImageView *)imageView {
  654. CYGroupSendHelperViewController *vc = [[CYGroupSendHelperViewController alloc] init];
  655. [g_navigation pushViewController:vc animated:YES];
  656. }
  657. // 标签
  658. - (void)labelAction:(JXImageView *)imageView {
  659. JXLabelVC *vc = [[JXLabelVC alloc] init];
  660. [g_navigation pushViewController:vc animated:YES];
  661. }
  662. // 手机通讯录
  663. - (void)addressBookAction:(JXImageView *)imageView {
  664. JXAddressBookVC *vc = [[JXAddressBookVC alloc] init];
  665. NSMutableArray *arr = [[JXAddressBook sharedInstance] doFetchUnread];
  666. vc.abUreadArr = arr;
  667. [g_navigation pushViewController:vc animated:YES];
  668. [[JXAddressBook sharedInstance] updateUnread];
  669. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  670. newobj.user = [[JXUserObject sharedInstance] getUserById:FRIEND_CENTER_USERID];
  671. [self showNewMsgCount:[newobj.user.msgsNew integerValue]];
  672. }
  673. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom icon:(NSString*)icon click:(SEL)click superView:(UIView *)superView{
  674. JXImageView* btn = [[JXImageView alloc] init];
  675. btn.backgroundColor = [UIColor whiteColor];
  676. btn.userInteractionEnabled = YES;
  677. btn.didTouch = click;
  678. btn.delegate = self;
  679. [superView addSubview:btn];
  680. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(42 + 14 + 14, 0, 200, HEIGHT)];
  681. p.text = title;
  682. p.font = g_factory.font16;
  683. p.backgroundColor = [UIColor clearColor];
  684. p.textColor = HEXCOLOR(0x323232);
  685. // p.delegate = self;
  686. // p.didTouch = click;
  687. [btn addSubview:p];
  688. if(icon){
  689. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(14, (HEIGHT-42)/2, 42, 42)];
  690. iv.image = [UIImage imageNamed:icon];
  691. iv.layer.cornerRadius = iv.frame.size.width / 2;
  692. iv.layer.masksToBounds = YES;
  693. [btn addSubview:iv];
  694. }
  695. if(drawTop){
  696. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,LINE_WH)];
  697. line.backgroundColor = THE_LINE_COLOR;
  698. [btn addSubview:line];
  699. }
  700. if(drawBottom){
  701. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0,HEIGHT-LINE_WH,JX_SCREEN_WIDTH,LINE_WH)];
  702. line.backgroundColor = THE_LINE_COLOR;
  703. [btn addSubview:line];
  704. }
  705. // if(click){
  706. // UIImageView* iv;
  707. // iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-INSETS-20-3, 16, 20, 20)];
  708. // iv.image = [UIImage imageNamed:@"set_list_next"];
  709. // [btn addSubview:iv];
  710. //
  711. // }
  712. return btn;
  713. }
  714. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  715. [textField resignFirstResponder];
  716. JXSearchVC *vc = [[JXSearchVC alloc] initWithTable:@"friendsearchrecord"];
  717. [g_navigation pushViewController:vc animated:YES];
  718. }
  719. - (void) textFieldDidChange:(UITextField *)textField {
  720. if (textField.text.length <= 0) {
  721. if (!self.isMyGoIn) {
  722. [self showMenuView];
  723. }
  724. [self getArrayData];
  725. [self.tableView reloadData];
  726. return;
  727. }else {
  728. [self hideMenuView];
  729. }
  730. [_searchArray removeAllObjects];
  731. if (_selMenu == 0) {
  732. _searchArray = [[JXUserObject sharedInstance] fetchFriendsFromLocalWhereLike:textField.text];
  733. }else if (_selMenu == 1){
  734. _searchArray = [[JXUserObject sharedInstance] fetchBlackFromLocalWhereLike:textField.text];
  735. }
  736. [self.tableView reloadData];
  737. }
  738. - (void) cancelBtnAction {
  739. if (_seekTextField.text.length > 0) {
  740. _seekTextField.text = nil;
  741. [self getArrayData];
  742. }
  743. [_seekTextField resignFirstResponder];
  744. [self.tableView reloadData];
  745. }
  746. -(void)onClick:(UIButton*)sender{
  747. }
  748. //筛选点击
  749. - (void)topItemBtnClick:(UIButton *)btn{
  750. [self checkAfterScroll:(btn.tag-100)];
  751. [_topSiftView resetAllParaBtn];
  752. }
  753. - (void)checkAfterScroll:(CGFloat)offsetX{
  754. if (offsetX == 0) {
  755. _selMenu = 0;
  756. }else {
  757. _selMenu = 1;
  758. }
  759. [self scrollToPageUp];
  760. }
  761. - (void)getFriend{
  762. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  763. }
  764. //-(void)actionSegment:(UISegmentedControl*)sender{
  765. // _selMenu = (int)sender.selectedSegmentIndex;
  766. // [self refresh];
  767. //}
  768. - (void)viewDidLoad
  769. {
  770. [super viewDidLoad];
  771. _array=[[NSMutableArray alloc] init];
  772. [self refresh];
  773. }
  774. - (void)viewDidDisappear:(BOOL)animated {
  775. [super viewDidDisappear:animated];
  776. // 离开时重置_isMyGoIn
  777. if (_isMyGoIn) {
  778. _isMyGoIn = NO;
  779. }
  780. }
  781. - (void)viewWillAppear:(BOOL)animated
  782. {
  783. [super viewWillAppear:animated];
  784. }
  785. - (void)didReceiveMemoryWarning
  786. {
  787. [super didReceiveMemoryWarning];
  788. // Dispose of any resources that can be recreated.
  789. }
  790. #pragma mark ---------tableView协议----------------
  791. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  792. {
  793. if (_seekTextField.text.length > 0) {
  794. return 1;
  795. }
  796. return [self.indexArray count];
  797. }
  798. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  799. if (_seekTextField.text.length > 0) {
  800. return Localized(@"JXFriend_searchTitle");
  801. }
  802. return [self.indexArray objectAtIndex:section];
  803. }
  804. -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
  805. UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
  806. header.tintColor = HEXCOLOR(0xF2F2F2);
  807. [header.textLabel setTextColor:HEXCOLOR(0x999999)];
  808. [header.textLabel setFont:SYSFONT(15)];
  809. }
  810. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  811. if (_seekTextField.text.length > 0) {
  812. return _searchArray.count;
  813. }
  814. return [(NSArray *)[self.letterResultArr objectAtIndex:section] count];
  815. }
  816. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  817. if (_seekTextField.text.length > 0) {
  818. return nil;
  819. }
  820. return self.indexArray;
  821. }
  822. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  823. return index;
  824. }
  825. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  826. {
  827. JXUserObject *user;
  828. if (_seekTextField.text.length > 0) {
  829. user = _searchArray[indexPath.row];
  830. }else{
  831. user = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  832. }
  833. JXCell *cell=nil;
  834. NSString* cellName = [NSString stringWithFormat:@"msg_%d_%ld",_refreshCount,indexPath.row];
  835. cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  836. if(cell==nil){
  837. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  838. [_table addToPool:cell];
  839. // cell.headImage = user.userHead;
  840. // user = nil;
  841. }
  842. // cell.title = user.userNickname;
  843. cell.title = [self multipleLoginIsOnlineTitle:user];
  844. // cell.subtitle = user.userId;
  845. cell.index = (int)indexPath.row;
  846. cell.delegate = self;
  847. cell.didTouch = @selector(onHeadImage:);
  848. // cell.bottomTitle = [TimeUtil formatDate:user.timeCreate format:@"MM-dd HH:mm"];
  849. // [cell setForTimeLabel:[TimeUtil formatDate:user.timeCreate format:@"MM-dd HH:mm"]];
  850. cell.timeLabel.frame = CGRectMake(JX_SCREEN_WIDTH - 120-20, 9, 115, 20);
  851. cell.userId = user.userId;
  852. [cell.lbTitle setText:cell.title];
  853. //添加爱心标志---特别关心标志
  854. // cell.notPushImageView.image = [UIImage imageNamed:@"collection_me_simple"];
  855. if ([user.veryCare intValue] == 1) {
  856. cell.specialCareImageView.hidden = NO;
  857. }else {
  858. cell.specialCareImageView.hidden = YES;
  859. }
  860. cell.dataObj = user;
  861. // cell.headImageView.tag = (int)indexPath.row;
  862. // cell.headImageView.delegate = cell.delegate;
  863. // cell.headImageView.didTouch = cell.didTouch;
  864. cell.isSmall = YES;
  865. [cell headImageViewImageWithUserId:user.userId roomId:nil];
  866. if (indexPath.section == self.letterResultArr.count-1 && indexPath.row == [(NSArray *)[self.letterResultArr objectAtIndex:indexPath.section] count]-1) {
  867. cell.lineView.frame = CGRectMake(0, cell.lineView.frame.origin.y, JX_SCREEN_WIDTH, cell.lineView.frame.size.height);
  868. }else if (indexPath.row == [(NSArray *)[self.letterResultArr objectAtIndex:indexPath.section] count]-1) {
  869. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,0);
  870. }else {
  871. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,LINE_WH);
  872. }
  873. return cell;
  874. }
  875. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  876. // if (_seekTextField.text.length > 0 || section != self.letterResultArr.count-1) {
  877. // return 0;
  878. // }
  879. // return 0;
  880. //}
  881. //
  882. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  883. // if (_seekTextField.text.length > 0 || section != self.letterResultArr.count-1) {
  884. // return nil;
  885. // }
  886. // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 44)];
  887. // label.textColor = HEXCOLOR(0x999999);
  888. // label.textAlignment = NSTextAlignmentCenter;
  889. // label.font = SYSFONT(16);
  890. // label.text = [NSString stringWithFormat:@"%ld位联系人",_array.count];
  891. //
  892. // return label;
  893. //}
  894. - (NSString *)multipleLoginIsOnlineTitle:(JXUserObject *)user {
  895. NSString *isOnline;
  896. if ([user.isOnLine intValue] == 1) {
  897. isOnline = [NSString stringWithFormat:@"(%@)", Localized(@"JX_OnLine")];
  898. }else {
  899. isOnline = [NSString stringWithFormat:@"(%@)", Localized(@"JX_OffLine")];
  900. }
  901. NSString *title = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  902. if ([user.userId isEqualToString:ANDROID_USERID] || [user.userId isEqualToString:PC_USERID] || [user.userId isEqualToString:MAC_USERID]) {
  903. title = [title stringByAppendingString:isOnline];
  904. }
  905. return title;
  906. }
  907. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  908. { [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  909. JXCell * cell = [_table cellForRowAtIndexPath:indexPath];
  910. cell.selected = NO;
  911. // 黑名单列表不能点击
  912. if (_selMenu == 1) {
  913. return;
  914. }
  915. JXUserObject *user;
  916. if (_seekTextField.text.length > 0) {
  917. user = _searchArray[indexPath.row];
  918. }else{
  919. user = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  920. }
  921. if([user.userId isEqualToString:FRIEND_CENTER_USERID]){
  922. JXNewFriendViewController* vc = [[JXNewFriendViewController alloc]init];
  923. // [g_App.window addSubview:vc.view];
  924. [g_navigation pushViewController:vc animated:YES];
  925. // [vc release];
  926. return;
  927. }
  928. JXChatViewController *sendView=[JXChatViewController alloc];
  929. if([user.roomFlag intValue] > 0 || user.roomId.length > 0){
  930. sendView.roomJid = user.userId;
  931. sendView.roomId = user.roomId;
  932. [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  933. }
  934. sendView.title = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  935. sendView.chatPerson = user;
  936. sendView = [sendView init];
  937. // [g_App.window addSubview:sendView.view];
  938. [g_navigation pushViewController:sendView animated:YES];
  939. JXMessageObject *msg = [[JXMessageObject alloc] init];
  940. msg.toUserId = user.userId;
  941. [msg updateNewMsgsTo0];
  942. [g_notify postNotificationName:kChatViewDisappear object:nil];
  943. // [sendView release];
  944. }
  945. -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
  946. if (_seekTextField.text.length <= 0){
  947. if (_selMenu == 0) {
  948. JXUserObject *user = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  949. if (user.userId.length <= 5) {
  950. return NO;
  951. }else{
  952. return YES;
  953. }
  954. }else{
  955. return YES;
  956. }
  957. }else{
  958. return NO;
  959. }
  960. }
  961. //-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
  962. // if (_selMenu == 0) {
  963. // return UITableViewCellEditingStyleDelete;
  964. // }else{
  965. // return UITableViewCellEditingStyleNone;
  966. // }
  967. //}
  968. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  969. if (_selMenu == 0) {
  970. UITableViewRowAction *deleteBtn = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:Localized(@"JX_Delete") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  971. JXUserObject *user = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  972. _currentUser = user;
  973. [g_server delFriend:user.userId toView:self];
  974. }];
  975. return @[deleteBtn];
  976. }
  977. else {
  978. UITableViewRowAction *cancelBlackBtn = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:Localized(@"REMOVE") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  979. JXUserObject *user = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  980. _currentUser = user;
  981. [g_server delBlacklist:user.userId toView:self];
  982. }];
  983. return @[cancelBlackBtn];
  984. }
  985. }
  986. //-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  987. // if (_selMenu == 0 && editingStyle == UITableViewCellEditingStyleDelete) {
  988. // JXUserObject *user=_array[indexPath.row];
  989. // _currentUser = user;
  990. // [g_server delFriend:user.userId toView:self];
  991. // }
  992. //}
  993. - (void)dealloc {
  994. [g_notify removeObserver:self];
  995. // [_table release];
  996. [_array removeAllObjects];
  997. // [_array release];
  998. // [super dealloc];
  999. }
  1000. -(void)getArrayData{
  1001. switch (_selMenu) {
  1002. case 0:{
  1003. //获取好友列表
  1004. // if (self.isOneInit) {//是否新建
  1005. // [g_server listAttention:0 userId:MY_USER_ID toView:self];
  1006. // self.isOneInit = NO;
  1007. // }
  1008. //从数据库获取好友staus为2且不是room的
  1009. _array=[[JXUserObject sharedInstance] fetchAllFriendsFromLocal];
  1010. //选择拼音 转换的 方法
  1011. BMChineseSortSetting.share.sortMode = 2; // 1或2
  1012. //排序 Person对象
  1013. [BMChineseSort sortAndGroup:_array key:@"userNickname" finish:^(bool isSuccess, NSMutableArray *unGroupArr, NSMutableArray *sectionTitleArr, NSMutableArray<NSMutableArray *> *sortedObjArr) {
  1014. if (isSuccess) {
  1015. self.indexArray = sectionTitleArr;
  1016. self.letterResultArr = sortedObjArr;
  1017. [_table reloadData];
  1018. }
  1019. }];
  1020. // //根据Person对象的 name 属性 按中文 对 Person数组 排序
  1021. // self.indexArray = [BMChineseSort IndexWithArray:_array Key:@"userNickname"];
  1022. // self.letterResultArr = [BMChineseSort sortObjectArray:_array Key:@"userNickname"];
  1023. //
  1024. self.isShowFooterPull = NO;
  1025. }
  1026. break;
  1027. case 1:{
  1028. //获取黑名單列表
  1029. //从数据库获取好友staus为-1的
  1030. _array=[[JXUserObject sharedInstance] fetchAllBlackFromLocal];
  1031. //选择拼音 转换的 方法
  1032. BMChineseSortSetting.share.sortMode = 2; // 1或2
  1033. //排序 Person对象
  1034. [BMChineseSort sortAndGroup:_array key:@"userNickname" finish:^(bool isSuccess, NSMutableArray *unGroupArr, NSMutableArray *sectionTitleArr, NSMutableArray<NSMutableArray *> *sortedObjArr) {
  1035. if (isSuccess) {
  1036. self.indexArray = sectionTitleArr;
  1037. self.letterResultArr = sortedObjArr;
  1038. [_table reloadData];
  1039. }
  1040. }];
  1041. //根据Person对象的 name 属性 按中文 对 Person数组 排序
  1042. // self.indexArray = [BMChineseSort IndexWithArray:_array Key:@"userNickname"];
  1043. // self.letterResultArr = [BMChineseSort sortObjectArray:_array Key:@"userNickname"];
  1044. }
  1045. break;
  1046. case 2:{
  1047. _array=[[JXUserObject sharedInstance] fetchAllRoomsFromLocal];
  1048. //选择拼音 转换的 方法
  1049. BMChineseSortSetting.share.sortMode = 2; // 1或2
  1050. //排序 Person对象
  1051. [BMChineseSort sortAndGroup:_array key:@"userNickname" finish:^(bool isSuccess, NSMutableArray *unGroupArr, NSMutableArray *sectionTitleArr, NSMutableArray<NSMutableArray *> *sortedObjArr) {
  1052. if (isSuccess) {
  1053. self.indexArray = sectionTitleArr;
  1054. self.letterResultArr = sortedObjArr;
  1055. [_table reloadData];
  1056. }
  1057. }];
  1058. }
  1059. // //根据Person对象的 name 属性 按中文 对 Person数组 排序
  1060. // self.indexArray = [BMChineseSort IndexWithArray:_array Key:@"userNickname"];
  1061. // self.letterResultArr = [BMChineseSort sortObjectArray:_array Key:@"userNickname"];
  1062. break;
  1063. }
  1064. [self setFooterView];
  1065. }
  1066. //服务器返回数据
  1067. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  1068. //更新本地好友
  1069. if ([aDownload.action isEqualToString:act_AttentionList]) {
  1070. [_wait stop];
  1071. [self stopLoading];
  1072. JXProgressVC * pv = [JXProgressVC alloc];
  1073. // 服务端不会返回新朋友 , 减去新朋友
  1074. pv.dbFriends = (long)[_array count] - 1;
  1075. pv.dataArray = array1;
  1076. pv = [pv init];
  1077. // [g_window addSubview:pv.view];
  1078. }
  1079. if ([aDownload.action isEqualToString:act_FriendDel]) {
  1080. [_currentUser doSendMsg:XMPP_TYPE_DELALL content:nil];
  1081. }
  1082. if([aDownload.action isEqualToString:act_BlacklistDel]){
  1083. [_currentUser doSendMsg:XMPP_TYPE_NOBLACK content:nil];
  1084. }
  1085. if( [aDownload.action isEqualToString:act_UserGet] ){
  1086. [_wait stop];
  1087. JXUserObject* user = [[JXUserObject alloc]init];
  1088. [user getDataFromDict:dict];
  1089. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  1090. vc.user = user;
  1091. vc.fromAddType = 6;
  1092. vc = [vc init];
  1093. // [g_window addSubview:vc.view];
  1094. [g_navigation pushViewController:vc animated:YES];
  1095. }
  1096. // 同步标签
  1097. if ([aDownload.action isEqualToString:act_FriendGroupList]) {
  1098. for (NSInteger i = 0; i < array1.count; i ++) {
  1099. NSDictionary *dict = array1[i];
  1100. JXLabelObject *labelObj = [[JXLabelObject alloc] init];
  1101. labelObj.groupId = dict[@"groupId"];
  1102. labelObj.groupName = dict[@"groupName"];
  1103. labelObj.userId = dict[@"userId"];
  1104. NSArray *userIdList = dict[@"userIdList"];
  1105. NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
  1106. if (userIdListStr.length > 0) {
  1107. labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
  1108. }
  1109. [labelObj insert];
  1110. }
  1111. // 删除服务器上已经删除的
  1112. NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  1113. for (NSInteger i = 0; i < arr.count; i ++) {
  1114. JXLabelObject *locLabel = arr[i];
  1115. BOOL flag = NO;
  1116. for (NSInteger j = 0; j < array1.count; j ++) {
  1117. NSDictionary * dict = array1[j];
  1118. if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
  1119. flag = YES;
  1120. break;
  1121. }
  1122. }
  1123. if (!flag) {
  1124. [locLabel delete];
  1125. }
  1126. }
  1127. _array = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  1128. for (JXLabelObject *labelObj in _array) {
  1129. NSString *userIdStr = labelObj.userIdList;
  1130. NSArray *userIds = [userIdStr componentsSeparatedByString:@","];
  1131. if (userIdStr.length <= 0) {
  1132. userIds = nil;
  1133. }
  1134. NSMutableArray *newUserIds = [userIds mutableCopy];
  1135. for (NSInteger i = 0; i < userIds.count; i ++) {
  1136. NSString *userId = userIds[i];
  1137. NSString *userName = [JXUserObject getUserNameWithUserId:userId];
  1138. if (!userName || userName.length <= 0) {
  1139. [newUserIds removeObject:userId];
  1140. }
  1141. }
  1142. NSString *string = [newUserIds componentsJoinedByString:@","];
  1143. labelObj.userIdList = string;
  1144. [labelObj update];
  1145. }
  1146. }
  1147. if ([aDownload.action isEqualToString:act_customerLinkList]){
  1148. self.customerArr = array1;
  1149. CGRect backFrame = backView.frame;
  1150. backFrame.size.height = backFrame.size.height + 50* self.customerArr.count;
  1151. backView.frame = backFrame ;
  1152. if (self.customerArr.count == 0) {
  1153. return;
  1154. }
  1155. int cY = _menuView.frame.origin.y + _menuView.frame.size.height;
  1156. for (int i = 0; i < self.customerArr.count; i++) {
  1157. UIView *customerView = [[UIView alloc] initWithFrame:CGRectMake(0, cY + 50 * i, self_width, 50)];
  1158. // customerView.backgroundColor = [UIColor redColor];
  1159. UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, .5)];
  1160. lineView2.backgroundColor = HEXCOLOR(0xdcdcdc);
  1161. [customerView addSubview:lineView2];
  1162. UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(15, lineView2.frame.origin.y+5, 40, 40)];
  1163. NSString *fileURL = self.customerArr[i][@"path"];
  1164. NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
  1165. UIImage *image = [UIImage imageWithData:data];
  1166. if (image) {
  1167. imageView2.image = image;
  1168. }else {
  1169. imageView2.image = [UIImage imageNamed:@"im_10000"];
  1170. }
  1171. [customerView addSubview:imageView2];
  1172. UIButton *customerBtn = [[UIButton alloc] initWithFrame:CGRectMake(imageView2.frame.origin.x+imageView2.frame.size.width + 20, imageView2.frame.origin.y, self_width-imageView2.frame.size.width-15+20, 40)];
  1173. // [customerBtn setTitle:@"威尼斯客服" forState:UIControlStateNormal];
  1174. if (self.customerArr[i][@"name"]) {
  1175. [customerBtn setTitle:self.customerArr[i][@"name"] forState:UIControlStateNormal];
  1176. }else {
  1177. // imageView2.image = [UIImage imageNamed:@"im_10000"];
  1178. [customerBtn setTitle:@"--" forState:UIControlStateNormal];
  1179. }
  1180. // [customerBtn ]
  1181. customerBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  1182. // customerBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  1183. // customerBtn.backgroundColor = UIColor.redColor;
  1184. [customerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  1185. [customerBtn addTarget:self action:@selector(customerClick:) forControlEvents:UIControlEventTouchUpInside];
  1186. customerBtn.tag = i+1;
  1187. [customerView addSubview:customerBtn];
  1188. UILabel *hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(self_width - 40, customerBtn.frame.origin.y + customerBtn.frame.size.height - 15, 40, 15)];
  1189. if (self.customerArr[i][@"type"]) {
  1190. hintLabel.text = self.customerArr[i][@"type"];
  1191. }else{
  1192. hintLabel.text = @"--";
  1193. }
  1194. hintLabel.font = [UIFont systemFontOfSize:13];
  1195. hintLabel.backgroundColor = UIColor.clearColor;
  1196. hintLabel.textColor = UIColor.blackColor;
  1197. hintLabel.textAlignment = NSTextAlignmentCenter;
  1198. [customerView addSubview:hintLabel];
  1199. [backView addSubview:customerView];
  1200. }
  1201. }
  1202. }
  1203. - (void)setupCustomerLinkList {
  1204. self.customerArr = g_App.customerLinkListArray;
  1205. CGRect backFrame = backView.frame;
  1206. backFrame.size.height = backFrame.size.height + 50* self.customerArr.count;
  1207. backView.frame = backFrame ;
  1208. if (self.customerArr.count == 0) {
  1209. return;
  1210. }
  1211. int cY = _menuView.frame.origin.y + _menuView.frame.size.height;
  1212. for (int i = 0; i < self.customerArr.count; i++) {
  1213. UIView *customerView = [[UIView alloc] initWithFrame:CGRectMake(0, cY + 50 * i, self_width, 50)];
  1214. // customerView.backgroundColor = [UIColor redColor];
  1215. UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, .5)];
  1216. lineView2.backgroundColor = HEXCOLOR(0xdcdcdc);
  1217. [customerView addSubview:lineView2];
  1218. UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(15, lineView2.frame.origin.y+5, 40, 40)];
  1219. NSString *fileURL = self.customerArr[i][@"path"];
  1220. NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
  1221. UIImage *image = [UIImage imageWithData:data];
  1222. if (image) {
  1223. imageView2.image = image;
  1224. }else {
  1225. imageView2.image = [UIImage imageNamed:@"im_10000"];
  1226. }
  1227. [customerView addSubview:imageView2];
  1228. UIButton *customerBtn = [[UIButton alloc] initWithFrame:CGRectMake(imageView2.frame.origin.x+imageView2.frame.size.width + 20, imageView2.frame.origin.y, self_width-imageView2.frame.size.width-15+20, 40)];
  1229. // [customerBtn setTitle:@"威尼斯客服" forState:UIControlStateNormal];
  1230. if (self.customerArr[i][@"name"]) {
  1231. [customerBtn setTitle:self.customerArr[i][@"name"] forState:UIControlStateNormal];
  1232. }else {
  1233. // imageView2.image = [UIImage imageNamed:@"im_10000"];
  1234. [customerBtn setTitle:@"--" forState:UIControlStateNormal];
  1235. }
  1236. // [customerBtn ]
  1237. customerBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  1238. // customerBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  1239. // customerBtn.backgroundColor = UIColor.redColor;
  1240. [customerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  1241. [customerBtn addTarget:self action:@selector(customerClick:) forControlEvents:UIControlEventTouchUpInside];
  1242. customerBtn.tag = i+1;
  1243. [customerView addSubview:customerBtn];
  1244. UILabel *hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(self_width - 40, customerBtn.frame.origin.y + customerBtn.frame.size.height - 15, 40, 15)];
  1245. if (self.customerArr[i][@"type"]) {
  1246. hintLabel.text = self.customerArr[i][@"type"];
  1247. }else{
  1248. hintLabel.text = @"--";
  1249. }
  1250. hintLabel.font = [UIFont systemFontOfSize:13];
  1251. hintLabel.backgroundColor = UIColor.clearColor;
  1252. hintLabel.textColor = UIColor.blackColor;
  1253. hintLabel.textAlignment = NSTextAlignmentCenter;
  1254. [customerView addSubview:hintLabel];
  1255. [backView addSubview:customerView];
  1256. }
  1257. }
  1258. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  1259. [_wait hide];
  1260. [self stopLoading];
  1261. return hide_error;
  1262. }
  1263. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  1264. [_wait hide];
  1265. [self stopLoading];
  1266. return hide_error;
  1267. }
  1268. -(void) didServerConnectStart:(JXConnection*)aDownload{
  1269. // [_wait start];
  1270. }
  1271. -(void)refresh{
  1272. [self stopLoading];
  1273. _refreshCount++;
  1274. [_array removeAllObjects];
  1275. // [_array release];
  1276. [self getArrayData];
  1277. _friendArray = [g_server.myself fetchAllFriendsOrNotFromLocal];
  1278. [_table reloadData];
  1279. }
  1280. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  1281. {
  1282. return 59;
  1283. }
  1284. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1285. [self.view endEditing:YES];
  1286. }
  1287. //-(void)scrollToPageUp{
  1288. // [self refresh];
  1289. //}
  1290. -(void)newFriend:(NSObject*)sender{
  1291. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1292. [self refresh];
  1293. });
  1294. }
  1295. -(void)onHeadImage:(id)dataObj{
  1296. JXUserObject *p = (JXUserObject *)dataObj;
  1297. if([p.userId isEqualToString:FRIEND_CENTER_USERID] || [p.userId isEqualToString:CALL_CENTER_USERID])
  1298. return;
  1299. _currentUser = p;
  1300. // [g_server getUser:p.userId toView:self];
  1301. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  1302. vc.userId = p.userId;
  1303. vc.user = p;
  1304. vc.fromAddType = 6;
  1305. vc = [vc init];
  1306. [g_navigation pushViewController:vc animated:YES];
  1307. p = nil;
  1308. }
  1309. -(void)onSendTimeout:(NSNotification *)notifacation//超时未收到回执
  1310. {
  1311. // NSLog(@"onSendTimeout");
  1312. [_wait stop];
  1313. // [g_App showAlert:Localized(@"JXAlert_SendFilad")];
  1314. // [JXMyTools showTipView:Localized(@"JXAlert_SendFilad")];
  1315. }
  1316. -(void)newReceipt:(NSNotification *)notifacation{//新回执
  1317. // NSLog(@"newReceipt");
  1318. JXMessageObject *msg = (JXMessageObject *)notifacation.object;
  1319. if(msg == nil)
  1320. return;
  1321. if(![msg isAddFriendMsg])
  1322. return;
  1323. [_wait stop];
  1324. if([msg.type intValue] == XMPP_TYPE_DELALL){
  1325. if([msg.toUserId isEqualToString:_currentUser.userId] || [msg.fromUserId isEqualToString:_currentUser.userId]){
  1326. [_array removeObject:_currentUser];
  1327. _currentUser = nil;
  1328. [self getArrayData];
  1329. [_table reloadData];
  1330. // [g_App showAlert:Localized(@"JXAlert_DeleteFirend")];
  1331. }
  1332. }
  1333. if([msg.type intValue] == XMPP_TYPE_BLACK){//拉黑
  1334. for (JXUserObject *obj in _array) {
  1335. if ([obj.userId isEqualToString:_currentUser.userId]) {
  1336. [_array removeObject:obj];
  1337. break;
  1338. }
  1339. }
  1340. [self getArrayData];
  1341. [self.tableView reloadData];
  1342. }
  1343. if([msg.type intValue] == XMPP_TYPE_NOBLACK){
  1344. // _currentUser.status = [NSNumber numberWithInt:friend_status_friend];
  1345. // int status = [_currentUser.status intValue];
  1346. // [_currentUser update];
  1347. if (!_currentUser) {
  1348. return;
  1349. }
  1350. [[JXXMPP sharedInstance].blackList removeObject:_currentUser.userId];
  1351. [JXMessageObject msgWithFriendStatus:_currentUser.userId status:friend_status_friend];
  1352. for (JXUserObject *obj in _array) {
  1353. if ([obj.userId isEqualToString:_currentUser.userId]) {
  1354. [_array removeObject:obj];
  1355. break;
  1356. }
  1357. }
  1358. [self getArrayData];
  1359. [self.tableView reloadData];
  1360. // [g_App showAlert:Localized(@"JXAlert_MoveBlackList")];
  1361. }
  1362. if([msg.type intValue] == XMPP_TYPE_PASS){//通过
  1363. [self getFriend];
  1364. }
  1365. }
  1366. - (void)friendRemarkNotif:(NSNotification *)notif {
  1367. JXUserObject *user = notif.object;
  1368. for (int i = 0; i < _array.count; i ++) {
  1369. JXUserObject *user1 = _array[i];
  1370. if ([user.userId isEqualToString:user1.userId]) {
  1371. user1.userNickname = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  1372. user1.remarkName = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  1373. [_table reloadData];
  1374. break;
  1375. }
  1376. }
  1377. }
  1378. - (UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title icon:(NSString *)iconName action:(SEL)action {
  1379. UIButton *button = [[UIButton alloc] init];
  1380. button.frame = frame;
  1381. [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
  1382. UIImageView *imgV = [[UIImageView alloc] init];
  1383. imgV.frame = CGRectMake((button.frame.size.width-IMAGE_HEIGHT)/2, 20, IMAGE_HEIGHT, IMAGE_HEIGHT);
  1384. imgV.image = [UIImage imageNamed:iconName];
  1385. [button addSubview:imgV];
  1386. CGSize size = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(14)} context:nil].size;
  1387. UILabel *lab = [[UILabel alloc] init];
  1388. lab.text = title;
  1389. lab.font = SYSFONT(14);
  1390. lab.textAlignment = NSTextAlignmentCenter;
  1391. lab.textColor = HEXCOLOR(0x323232);
  1392. if (size.width >= button.frame.size.width) {
  1393. size.width = button.frame.size.width-20;
  1394. }
  1395. lab.frame = CGRectMake(0, CGRectGetMaxY(imgV.frame)+INSET_HEIGHT, size.width, size.height);
  1396. CGPoint center = lab.center;
  1397. center.x = imgV.center.x;
  1398. lab.center = center;
  1399. CGRect btnFrame = button.frame;
  1400. btnFrame.size.height = CGRectGetMaxY(imgV.frame)+INSET_HEIGHT+size.height;
  1401. button.frame = btnFrame;
  1402. [button addSubview:lab];
  1403. return button;
  1404. }
  1405. -(void)customerClick:(UIButton *)sender{
  1406. // UIButton *btn = (UIButton *)[self.view viewWithTag:sender.tag];
  1407. if (self.customerArr[sender.tag - 1][@"link"]) {
  1408. CYWebCustomerServiceVC *vc = [[CYWebCustomerServiceVC alloc] init];
  1409. vc.titleName = self.customerArr[sender.tag - 1][@"name"];
  1410. vc.link = self.customerArr[sender.tag - 1][@"link"];
  1411. [self presentViewController:vc animated:YES completion:^{
  1412. }];
  1413. }else {
  1414. NSLog(@"链接不存在!!!!!!!!");
  1415. }
  1416. }
  1417. @end