BGConversationStrangerController.m 9.8 KB

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