BGConversationListController.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. //
  2. // BGConversationListController.m
  3. // BuguLive
  4. //
  5. // Created by 朱庆彬 on 2017/8/22.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. #import "BGConversationListController.h"
  8. #import "ChatFriendCell.h"
  9. #import "ChatTradeCell.h"
  10. #import "BGBaseChatController.h"
  11. #import "BGConversationServiceController.h"
  12. #import "IMModel.h"
  13. #import "JSBadgeView.h"
  14. #import "M80AttributedLabel.h"
  15. @interface BGConversationListController () <UITableViewDelegate, UITableViewDataSource>
  16. @end
  17. @implementation BGConversationListController
  18. {
  19. int _select; //1.交易 2.好友 3.未关注
  20. int _page; //页数
  21. }
  22. - (void)viewWillAppear:(BOOL)animated
  23. {
  24. [super viewWillAppear:animated];
  25. [self.navigationController setNavigationBarHidden:YES animated:NO];
  26. }
  27. - (void)dealloc
  28. {
  29. [[NSNotificationCenter defaultCenter] removeObserver:self];
  30. }
  31. - (void)viewDidLoad
  32. {
  33. _select = 2;
  34. _conversationArr = NSMutableArray.new;
  35. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IMChatMsgNotficationInList:) name:g_notif_chatmsg object:nil];
  36. self.mTableView = [[UITableView alloc] initWithFrame:CGRectZero];
  37. self.mTableView.delegate = self;
  38. self.mTableView.dataSource = self;
  39. self.mTableView.tag = 1107;
  40. self.mTableView.backgroundColor = kBackGroundColor;
  41. [self.view addSubview:self.mTableView];
  42. self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. [self.mTableView registerNib:[UINib nibWithNibName:@"ChatFriendCell" bundle:nil] forCellReuseIdentifier:@"ChatFriendCell"];
  44. [BGMJRefreshManager refresh:self.mTableView target:self headerRereshAction:@selector(headerStartRefresh) footerRereshAction:nil];
  45. }
  46. - (void)updateTableViewFrame
  47. {
  48. CGFloat tableViewHeight;
  49. if (!self.isHaveLive)
  50. {
  51. tableViewHeight = kScreenH - 64;
  52. }
  53. else
  54. {
  55. tableViewHeight = kScreenH / 2 - 44;
  56. }
  57. [self.mTableView setFrame:CGRectMake(0, 0, kScreenW, tableViewHeight)];
  58. }
  59. #pragma mrak-- ------------------------消息通知-- ------------------------
  60. - (void)IMChatMsgNotficationInList:(NSNotification *)notfication
  61. {
  62. if (![NSThread isMainThread])
  63. {
  64. [self performSelectorOnMainThread:@selector(IMChatMsgNotficationInList:) withObject:notfication waitUntilDone:NO];
  65. return;
  66. }
  67. SFriendObj *bfindone = nil;
  68. SIMMsgObj *thatmsg = notfication.object;
  69. for (SFriendObj *one in _conversationArr)
  70. {
  71. if (one.mUser_id == thatmsg.mSenderId)
  72. {
  73. bfindone = one;
  74. break;
  75. }
  76. }
  77. if (bfindone)
  78. {
  79. [bfindone setLMsg:thatmsg.mCoreTMsg];
  80. [self.mTableView reloadData];
  81. }
  82. }
  83. - (void)headerStartRefresh
  84. {
  85. [self.mTableView reloadData];
  86. SFriendObj *xxx = nil;
  87. [SFriendObj getMyFriendMsgList:_select
  88. lastObj:xxx
  89. block:^(SResBase *resb, NSArray *all, int unReadNum) {
  90. [self updateItem:unReadNum];
  91. [BGMJRefreshManager endRefresh:self.mTableView];
  92. [_conversationArr removeAllObjects];
  93. if (all.count)
  94. {
  95. [self hideNoContentView];
  96. [_conversationArr addObjectsFromArray:all];
  97. }
  98. else
  99. {
  100. [self showNoContentView];
  101. if (_isHaveLive)
  102. {
  103. self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  104. }
  105. }
  106. [self.mTableView reloadData];
  107. }];
  108. }
  109. #pragma mark----------------------tableView的协议方法------------------------
  110. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  111. {
  112. return _conversationArr.count;
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. return 60.0f;
  117. }
  118. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. SFriendObj *oneobj = nil;
  121. if (indexPath.row < _conversationArr.count)
  122. {
  123. oneobj = [_conversationArr objectAtIndex:indexPath.row];
  124. }
  125. ChatFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChatFriendCell"];
  126. [cell.mheadimg sd_setImageWithURL:[NSURL URLWithString:oneobj.mHead_image] placeholderImage:kDefaultPreloadHeadImg];
  127. [cell.viconImageView sd_setImageWithURL:[NSURL URLWithString:oneobj.mV_icon]];
  128. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  129. if (oneobj.mNick_name.length > 11)
  130. {
  131. cell.mname.text = [NSString stringWithFormat:@"%@...", [oneobj.mNick_name substringToIndex:11]];
  132. }
  133. else
  134. {
  135. cell.mname.text = oneobj.mNick_name;
  136. }
  137. [cell.mmsg dealFace:oneobj.mLastMsg];
  138. cell.mtime.text = [oneobj getTimeStr];
  139. if (oneobj.mSex == 0)
  140. {
  141. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  142. }
  143. else if (oneobj.mSex == 1)
  144. {
  145. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  146. }
  147. else
  148. {
  149. cell.msex.image = [UIImage imageNamed:@"com_female_selected"];
  150. }
  151. NSString *ss = [NSString stringWithFormat:@"level%d", oneobj.mUser_level];
  152. cell.mlevel.image = [UIImage imageNamed:ss];
  153. [cell setUnReadCount:[oneobj getUnReadCount]];
  154. return cell;
  155. }
  156. #pragma mark 点击单元格的方法
  157. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  158. {
  159. SFriendObj *oneobj = nil;
  160. if (indexPath.row < _conversationArr.count)
  161. {
  162. oneobj = [_conversationArr objectAtIndex:indexPath.row];
  163. }
  164. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  165. backItem.title = ASLocalizedString(@"返回");
  166. self.navigationController.topViewController.navigationItem.backBarButtonItem = backItem;
  167. IMAUser *user = [[IMAUser alloc] initWith:[NSString stringWithFormat:@"%d", oneobj.mUser_id]];
  168. user.icon = oneobj.mHead_image;
  169. user.nickName = oneobj.mNick_name;
  170. user.remark = @"";
  171. if (self.isHaveLive == NO)
  172. {
  173. BGConversationServiceController *chatvc = [BGConversationServiceController makeChatVCWith:oneobj isHalf:NO];
  174. chatvc.dic = @{
  175. @"mHead_image": oneobj.mHead_image,
  176. @"mUser_id": @(oneobj.mUser_id)
  177. };
  178. [[AppDelegate sharedAppDelegate] pushViewController:chatvc animated:YES];
  179. }
  180. if (self.isHaveLive == YES)
  181. {
  182. //跳转 2去下界面
  183. [self itemBtnClick:oneobj];
  184. }
  185. [oneobj ignoreThisUnReadCount];
  186. [self.mTableView reloadData];
  187. [self reloadItem:_select];
  188. }
  189. #pragma mark-----------------------删除单元格方法------------------------
  190. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  191. {
  192. return YES;
  193. }
  194. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  195. {
  196. return ASLocalizedString(@"删除");
  197. }
  198. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  199. {
  200. if (editingStyle == UITableViewCellEditingStyleDelete)
  201. {
  202. SFriendObj *oneobj = nil;
  203. oneobj = [_conversationArr objectAtIndex:indexPath.row];
  204. [SVProgressHUD showWithStatus:ASLocalizedString(@"操作中...")];
  205. [oneobj delThis:^(SResBase *resb) {
  206. if (resb.msuccess)
  207. {
  208. [SVProgressHUD dismiss];
  209. [_conversationArr removeObjectAtIndex:indexPath.row];
  210. [self.mTableView beginUpdates];
  211. [self.mTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  212. [self.mTableView endUpdates];
  213. //获取角标
  214. [self reloadItem:_select];
  215. }
  216. else
  217. {
  218. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  219. }
  220. }];
  221. if (_conversationArr.count == 0) {
  222. [self showNoContentView];
  223. if (_isHaveLive)
  224. {
  225. self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  226. }
  227. }
  228. }
  229. }
  230. - (void)reloadItem:(int)selectItem
  231. {
  232. if ([self.delegate respondsToSelector:@selector(reloadChatBadge:)])
  233. {
  234. [self.delegate reloadChatBadge:selectItem];
  235. }
  236. }
  237. - (void)updateItem:(int)unReadNum
  238. {
  239. if ([self.delegate respondsToSelector:@selector(updateChatFriendBadge:)])
  240. {
  241. [self.delegate updateChatFriendBadge:unReadNum];
  242. }
  243. }
  244. - (void)itemBtnClick:(SFriendObj *)obj
  245. {
  246. if ([self.delegate respondsToSelector:@selector(clickFriendItem:)])
  247. {
  248. [self.delegate clickFriendItem:obj];
  249. }
  250. }
  251. - (void)didReceiveMemoryWarning
  252. {
  253. [super didReceiveMemoryWarning];
  254. // Dispose of any resources that can be recreated.
  255. }
  256. /*
  257. #pragma mark - Navigation
  258. // In a storyboard-based application, you will often want to do a little preparation before navigation
  259. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  260. // Get the new view controller using [segue destinationViewController].
  261. // Pass the selected object to the new view controller.
  262. }
  263. */
  264. @end