JXPublicNumberVC.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // JXPublicNumberVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/6/4.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXPublicNumberVC.h"
  9. #import "JXCell.h"
  10. #import "JXChatViewController.h"
  11. #import "JXSearchUserVC.h"
  12. #import "JXTransferNoticeVC.h"
  13. #import "JXUserInfoVC.h"
  14. @interface JXPublicNumberVC ()
  15. @property (nonatomic, strong) NSMutableArray *array;
  16. @property (nonatomic, assign) NSInteger currentIndex;
  17. @end
  18. @implementation JXPublicNumberVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. self.heightHeader = JX_SCREEN_TOP;
  23. self.heightFooter = 0;
  24. self.isGotoBack = YES;
  25. self.isShowHeaderPull = NO;
  26. self.isShowFooterPull = NO;
  27. _array = [NSMutableArray array];
  28. self.title = Localized(@"JX_PublicNumber");
  29. [self createHeadAndFoot];
  30. [self setupSearchPublicNumber];
  31. [self getServerData];
  32. [g_notify addObserver:self selector:@selector(newReceipt:) name:kXMPPReceiptNotifaction object:nil];
  33. }
  34. -(void)newReceipt:(NSNotification *)notifacation{//新回执
  35. // NSLog(@"newReceipt");
  36. JXMessageObject *msg = (JXMessageObject *)notifacation.object;
  37. if(msg == nil)
  38. return;
  39. if(![msg isAddFriendMsg])
  40. return;
  41. [_wait stop];
  42. if([msg.type intValue] == XMPP_TYPE_DELALL){//删除好友
  43. [self getServerData];
  44. [g_notify postNotificationName:kXMPPNewFriendNotifaction object:nil];
  45. }
  46. }
  47. - (void)setupSearchPublicNumber {
  48. if ([g_config.enableMpModule boolValue]) {
  49. UIButton *moreBtn = [UIFactory createButtonWithImage:@"search_publicNumber_black"
  50. highlight:nil
  51. target:self
  52. selector:@selector(searchPublicNumber)];
  53. moreBtn.custom_acceptEventInterval = 1.0f;
  54. moreBtn.frame = CGRectMake(JX_SCREEN_WIDTH - 18-15, JX_SCREEN_TOP - 18-15, 18, 18);
  55. [self.tableHeader addSubview:moreBtn];
  56. }
  57. }
  58. - (void)searchPublicNumber {
  59. JXSearchUserVC *searchUserVC = [JXSearchUserVC alloc];
  60. searchUserVC.type = JXSearchTypePublicNumber;
  61. searchUserVC = [searchUserVC init];
  62. [g_navigation pushViewController:searchUserVC animated:YES];
  63. }
  64. - (void)getServerData {
  65. self.array = [[JXUserObject sharedInstance] fetchSystemUser];
  66. [self.tableView reloadData];
  67. }
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  69. return _array.count;
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  72. return 59;
  73. }
  74. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. JXUserObject *user = _array[indexPath.row];
  77. JXCell *cell=nil;
  78. NSString* cellName = @"JXCell";
  79. cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  80. if(cell==nil){
  81. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  82. [_table addToPool:cell];
  83. }
  84. cell.title = user.userNickname;
  85. cell.index = (int)indexPath.row;
  86. cell.delegate = self;
  87. // cell.didTouch = @selector(onHeadImage:);
  88. [cell setForTimeLabel:[TimeUtil formatDate:user.timeCreate format:@"MM-dd HH:mm"]];
  89. cell.timeLabel.frame = CGRectMake(JX_SCREEN_WIDTH - 115-15, 59/2-10, 115, 20);
  90. cell.userId = user.userId;
  91. [cell.lbTitle setText:cell.title];
  92. cell.dataObj = user;
  93. // cell.headImageView.tag = (int)indexPath.row;
  94. // cell.headImageView.delegate = cell.delegate;
  95. // cell.headImageView.didTouch = cell.didTouch;
  96. cell.isSmall = YES;
  97. [cell headImageViewImageWithUserId:nil roomId:nil];
  98. return cell;
  99. }
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  101. JXCell* cell = (JXCell*)[tableView cellForRowAtIndexPath:indexPath];
  102. cell.selected = NO;
  103. JXUserObject *user = _array[indexPath.row];
  104. if ([user.userId intValue] == [SHIKU_TRANSFER intValue]) {
  105. JXTransferNoticeVC *noticeVC = [[JXTransferNoticeVC alloc] init];
  106. [g_navigation pushViewController:noticeVC animated:YES];
  107. return;
  108. }
  109. if([user.userType intValue] == 2 && [user.status intValue] != 2){
  110. JXUserInfoVC* userVC = [JXUserInfoVC alloc];
  111. userVC.userId = user.userId;
  112. userVC.user = user;
  113. userVC.fromAddType = 6;
  114. userVC = [userVC init];
  115. [g_navigation pushViewController:userVC animated:YES];
  116. return;
  117. }
  118. JXChatViewController *sendView=[JXChatViewController alloc];
  119. sendView.scrollLine = 0;
  120. sendView.title = user.userNickname;
  121. sendView.chatPerson = user;
  122. sendView = [sendView init];
  123. [g_navigation pushViewController:sendView animated:YES];
  124. sendView.view.hidden = NO;
  125. }
  126. // 进入编辑模式,按下出现的编辑按钮后,进行删除操作
  127. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  128. if (editingStyle == UITableViewCellEditingStyleDelete) {
  129. JXUserObject *user = _array[indexPath.row];
  130. _currentIndex = indexPath.row;
  131. [g_server delAttention:user.userId toView:self];
  132. }
  133. }
  134. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  135. JXUserObject *user = _array[indexPath.row];
  136. if ([user.userId intValue] == 10000) {
  137. return NO;
  138. }
  139. return YES;
  140. }
  141. // 定义编辑样式
  142. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  143. return UITableViewCellEditingStyleDelete;
  144. }
  145. // 修改编辑按钮文字
  146. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  147. return Localized(@"JX_Delete");
  148. }
  149. //服务器返回数据
  150. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  151. if ([aDownload.action isEqualToString:act_AttentionDel]) {
  152. [_wait stop];
  153. JXUserObject *user = _array[_currentIndex];
  154. [_array removeObject:user];
  155. [_table deleteRow:(int)_currentIndex section:0];
  156. [user doSendMsg:XMPP_TYPE_DELALL content:nil];
  157. }
  158. }
  159. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  160. [_wait hide];
  161. return show_error;
  162. }
  163. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  164. [_wait hide];
  165. return show_error;
  166. }
  167. -(void) didServerConnectStart:(JXConnection*)aDownload{
  168. [_wait start];
  169. }
  170. @end