JXFriendViewController.m 64 KB

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