BogoNewsViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. //
  2. // BogoNewsViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/12.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoNewsViewController.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. #import "BogoNewsHeadView.h"
  17. #import "BogoNewsLikesViewController.h"
  18. #import "FollowerViewController.h"
  19. #import "BogoNewsTabNumModel.h"
  20. #import "BGSystemMsgVC.h"
  21. #import "BogoNewsSystemViewController.h"
  22. @interface BogoNewsViewController ()<UITableViewDelegate, UITableViewDataSource,BogoNewsHeadViewDelegate>
  23. @property(nonatomic, strong) BogoNewsHeadView *headView;
  24. @property(nonatomic, strong) UILabel *titleL;
  25. @property(nonatomic, strong) BogoNewsTabNumModel *unReadModel;
  26. @end
  27. @implementation BogoNewsViewController
  28. {
  29. int _select; //1.交易 2.好友 3.未关注
  30. int _page; //页数
  31. }
  32. - (void)viewWillAppear:(BOOL)animated
  33. {
  34. [super viewWillAppear:animated];
  35. [self.navigationController setNavigationBarHidden:YES animated:NO];
  36. [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kBlackColor,
  37. NSFontAttributeName:[UIFont systemFontOfSize:15]
  38. } forState:UIControlStateNormal];
  39. [self reloadMsg];
  40. [self headerStartRefresh];
  41. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  42. }
  43. -(void)reloadMsg{
  44. //
  45. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  46. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  47. [parmDict setObject:@"unread_messages" forKey:@"act"];
  48. //
  49. [[NetHttpsManager manager]POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  50. if ([[responseJson valueForKey:@"status"]integerValue] == 1) {
  51. BogoNewsTabNumModel *model = [BogoNewsTabNumModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  52. // [responseJson objectForKey:[responseJson valueForKey:@"data"]];
  53. self.unReadModel = model;
  54. self.headView.model = model;
  55. }
  56. } FailureBlock:^(NSError *error) {
  57. }];
  58. }
  59. - (void)dealloc
  60. {
  61. [[NSNotificationCenter defaultCenter] removeObserver:self];
  62. }
  63. - (void)viewDidLoad
  64. {
  65. UIImageView *topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenW)];
  66. topImgView.image = [UIImage imageNamed:@"bg_top"];
  67. [self.view addSubview:topImgView];
  68. // CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  69. // gradientLayer.frame = CGRectMake(0, 0, kScreenW, 250);
  70. // gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#FBE2FF"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#FFFFFF"].CGColor];
  71. // gradientLayer.startPoint = CGPointMake(0, 0);
  72. // gradientLayer.endPoint = CGPointMake(0, 1);
  73. // //把gradientLayer加到_collectionView最底部
  74. //
  75. //// UIView *gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 250)];
  76. // UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
  77. //// view.backgroundColor = kYellowColor;
  78. // [view.layer insertSublayer:gradientLayer atIndex:0];
  79. // [self.view addSubview:view];
  80. _select = 0;
  81. _conversationArr = NSMutableArray.new;
  82. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IMChatMsgNotficationInList:) name:g_notif_chatmsg object:nil];
  83. self.titleL = [[UILabel alloc]init];//WithFrame:CGRectMake(15, kStatusBarHeight, kScreenW, kTopHeight - kStatusBarHeight)];
  84. self.titleL.text = ASLocalizedString(@"消息");
  85. // self.titleL.textAlignment = NSTextAlignmentCenter;
  86. self.titleL.font = [UIFont boldSystemFontOfSize:21];
  87. self.titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  88. [self.view addSubview:self.titleL];
  89. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(15);
  91. make.top.mas_equalTo(kStatusBarHeight);
  92. make.height.mas_equalTo(44);
  93. }];
  94. self.headView.top = kStatusBarHeight + (kTopHeight - kStatusBarHeight);
  95. [self.view addSubview:self.headView];
  96. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.right.mas_offset(0);
  98. make.top.mas_offset(StatusBarHeight+44);
  99. make.height.mas_equalTo(self.headView.height);
  100. }];
  101. self.mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.headView.bottom, kScreenW, kScreenH - self.headView.bottom - kTabBarHeight)];
  102. self.mTableView.delegate = self;
  103. self.mTableView.dataSource = self;
  104. self.mTableView.backgroundColor = UIColor.whiteColor;
  105. self.mTableView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  106. self.mTableView.layer.cornerRadius = 16;
  107. [self.view addSubview:self.mTableView];
  108. self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  109. [self.mTableView registerNib:[UINib nibWithNibName:@"ChatFriendCell" bundle:nil] forCellReuseIdentifier:@"ChatFriendCell"];
  110. [BGMJRefreshManager refresh:self.mTableView target:self headerRereshAction:@selector(headerStartRefresh) footerRereshAction:nil];
  111. [self.view addSubview:self.mTableView];
  112. [self.mTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.right.mas_offset(0);
  114. make.top.equalTo(self.headView.mas_bottom).mas_offset(0);
  115. make.bottom.mas_offset(-TABBAR_HEIGHT);
  116. }];
  117. }
  118. - (void)updateTableViewFrame
  119. {
  120. // CGFloat tableViewHeight;
  121. // if (!self.isHaveLive)
  122. // {
  123. // tableViewHeight = kScreenH - 64;
  124. // }
  125. // else
  126. // {
  127. // tableViewHeight = kScreenH / 2 - 44;
  128. // }
  129. // [self.mTableView setFrame:CGRectMake(0, 0, kScreenW, tableViewHeight)];
  130. }
  131. #pragma mrak-- ------------------------消息通知-- ------------------------
  132. - (void)IMChatMsgNotficationInList:(NSNotification *)notfication
  133. {
  134. if (![NSThread isMainThread])
  135. {
  136. [self performSelectorOnMainThread:@selector(IMChatMsgNotficationInList:) withObject:notfication waitUntilDone:NO];
  137. return;
  138. }
  139. SFriendObj *bfindone = nil;
  140. SIMMsgObj *thatmsg = notfication.object;
  141. for (SFriendObj *one in _conversationArr)
  142. {
  143. if (one.mUser_id == thatmsg.mSenderId)
  144. {
  145. bfindone = one;
  146. break;
  147. }
  148. }
  149. if (bfindone)
  150. {
  151. [bfindone setLMsg:thatmsg.mCoreTMsg];
  152. // [self.mTableView reloadData];
  153. }
  154. // SFriendObj *xxx = nil;
  155. // [SFriendObj getMyFriendMsgList:_select
  156. // lastObj:xxx
  157. // block:^(SResBase *resb, NSArray *all, int unReadNum) {
  158. //
  159. // if (all.count)
  160. // {
  161. // // [self hideNoContentView];
  162. // [self->_conversationArr removeAllObjects];
  163. // [self->_conversationArr addObjectsFromArray:all];
  164. //// [self.mTableView reloadData];
  165. //
  166. // }
  167. //
  168. //
  169. // }];
  170. //拉去官方消息
  171. [self reloadMsg];
  172. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  173. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  174. // 这里写延迟执行的代码
  175. [self headerStartRefresh];
  176. });
  177. }
  178. - (void)headerStartRefresh
  179. {
  180. // [self.mTableView reloadData];
  181. SFriendObj *xxx = nil;
  182. [SFriendObj getMyFriendMsgList:_select
  183. lastObj:xxx
  184. block:^(SResBase *resb, NSArray *all, int unReadNum) {
  185. NSLog(@"-=-=-=-=-=-=-==-=");
  186. // if (_unReadModel) {
  187. // NSInteger count = _unReadModel.bzone_reply + _unReadModel.bzone_like + _unReadModel.msg.count + unReadNum;
  188. // if (count == 0) {
  189. // self.tabBarItem.badgeValue = nil;
  190. // }else{
  191. // self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",count];
  192. // }
  193. // }
  194. // [self updateItem:_unReadModel.bzone_reply + _unReadModel.bzone_like + _unReadModel.msg.count + unReadNum];
  195. [BGMJRefreshManager endRefresh:self.mTableView];
  196. [self.conversationArr removeAllObjects];
  197. if (all.count){
  198. // self hideNoContentView];
  199. [self.conversationArr addObjectsFromArray:all];
  200. }else {
  201. // [self showNoContentView];
  202. // if (_isHaveLive)
  203. // {
  204. // self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  205. // }
  206. }
  207. [self.mTableView reloadData];
  208. }];
  209. }
  210. #pragma mark----------------------tableView的协议方法------------------------
  211. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  212. {
  213. return self.conversationArr.count + 1;
  214. }
  215. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  216. {
  217. return 74;
  218. }
  219. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  220. {
  221. SFriendObj *oneobj = nil;
  222. ChatFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChatFriendCell"];
  223. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  224. if (indexPath.row == 0) {
  225. [cell.mheadimg setImage:[UIImage imageNamed:@"bogo_news_top_system"]];
  226. cell.mname.text = ASLocalizedString(@"官方消息");
  227. if (_unReadModel.msg.content.length) {
  228. cell.mmsg.text = _unReadModel.msg.content;
  229. cell.mtime.text = [NSDate fd_getTimeSimpleFromTimestamp:_unReadModel.msg.addtime.doubleValue];
  230. }else{
  231. cell.mmsg.text = ASLocalizedString(@"Hi~ o(* ̄▽ ̄*)ブ欢迎你的到来!");
  232. }
  233. cell.msex.hidden = YES;
  234. [cell setUnReadCount:_unReadModel.msg.count];
  235. }else{
  236. if ((indexPath.row - 1) < _conversationArr.count)
  237. {
  238. oneobj = [_conversationArr objectAtIndex:indexPath.row - 1];
  239. }
  240. [cell.mheadimg sd_setImageWithURL:[NSURL URLWithString:oneobj.mHead_image] placeholderImage:kDefaultPreloadHeadImg];
  241. cell.viconImageView.hidden = YES;
  242. if (oneobj.mNick_name.length > 11)
  243. {
  244. cell.mname.text = [NSString stringWithFormat:@"%@...", [oneobj.mNick_name substringToIndex:11]];
  245. }
  246. else
  247. {
  248. cell.mname.text = oneobj.mNick_name;
  249. }
  250. [cell.mmsg dealFace:oneobj.mLastMsg];
  251. cell.mtime.text = [oneobj getTimeStr];
  252. if (oneobj.mSex == 0)
  253. {
  254. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  255. }
  256. else if (oneobj.mSex == 1)
  257. {
  258. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  259. }
  260. else
  261. {
  262. cell.msex.image = [UIImage imageNamed:@"com_female_selected"];
  263. }
  264. NSString *ss = [NSString stringWithFormat:@"level%d", oneobj.mUser_level];
  265. cell.mlevel.image = [UIImage imageNamed:ss];
  266. NSLog(@"未读数量-----%@",oneobj.unread_count);
  267. [cell setUnReadCount:oneobj.unread_count.intValue];
  268. }
  269. cell.backgroundColor = kClearColor;
  270. return cell;
  271. }
  272. #pragma mark 点击单元格的方法
  273. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  274. {
  275. if (indexPath.row == 0) {
  276. BogoNewsSystemViewController *vc = [BogoNewsSystemViewController new];
  277. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  278. return;
  279. }
  280. SFriendObj *oneobj = nil;
  281. if (indexPath.row < _conversationArr.count + 1)
  282. {
  283. oneobj = [_conversationArr objectAtIndex:indexPath.row - 1];
  284. }
  285. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  286. backItem.title = ASLocalizedString(@"返回");
  287. self.navigationController.topViewController.navigationItem.backBarButtonItem = backItem;
  288. IMAUser *user = [[IMAUser alloc] initWith:[NSString stringWithFormat:@"%d", oneobj.mUser_id]];
  289. user.icon = oneobj.mHead_image;
  290. user.nickName = oneobj.mNick_name;
  291. user.remark = @"";
  292. if (self.isHaveLive == NO)
  293. {
  294. BGConversationServiceController *chatvc = [BGConversationServiceController makeChatVCWith:oneobj isHalf:NO];
  295. chatvc.dic = @{
  296. @"mHead_image": oneobj.mHead_image,
  297. @"mUser_id": @(oneobj.mUser_id)
  298. };
  299. [[AppDelegate sharedAppDelegate] pushViewController:chatvc animated:YES];
  300. }
  301. if (self.isHaveLive == YES)
  302. {
  303. //跳转 2去下界面
  304. [self itemBtnClick:oneobj];
  305. }
  306. [oneobj ignoreThisUnReadCount];
  307. [self.mTableView reloadData];
  308. [self reloadItem:_select];
  309. }
  310. #pragma mark-----------------------删除单元格方法------------------------
  311. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  312. {
  313. if (indexPath.row == 0){
  314. return false;
  315. }
  316. return YES;
  317. }
  318. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  319. {
  320. return ASLocalizedString(@"删除");
  321. }
  322. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  323. {
  324. if (editingStyle == UITableViewCellEditingStyleDelete)
  325. {
  326. SFriendObj *oneobj = nil;
  327. oneobj = [_conversationArr objectAtIndex:indexPath.row-1];
  328. [SVProgressHUD showWithStatus:ASLocalizedString(@"操作中...")];
  329. [oneobj delThis:^(SResBase *resb) {
  330. if (resb.msuccess)
  331. {
  332. [SVProgressHUD dismiss];
  333. [_conversationArr removeObjectAtIndex:indexPath.row-1];
  334. [self.mTableView beginUpdates];
  335. [self.mTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  336. [self.mTableView endUpdates];
  337. //获取角标
  338. [self reloadItem:_select];
  339. }
  340. else
  341. {
  342. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  343. }
  344. }];
  345. if (_conversationArr.count == 0) {
  346. // [self showNoContentView];
  347. // if (_isHaveLive)
  348. // {
  349. // self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  350. // }
  351. }
  352. }
  353. }
  354. - (void)reloadItem:(int)selectItem
  355. {
  356. if ([self.delegate respondsToSelector:@selector(reloadChatBadge:)])
  357. {
  358. [self.delegate reloadChatBadge:selectItem];
  359. }
  360. }
  361. - (void)updateItem:(int)unReadNum
  362. {
  363. if ([self.delegate respondsToSelector:@selector(updateChatFriendBadge:)])
  364. {
  365. [self.delegate updateChatFriendBadge:unReadNum];
  366. }
  367. }
  368. - (void)itemBtnClick:(SFriendObj *)obj
  369. {
  370. if ([self.delegate respondsToSelector:@selector(clickFriendItem:)])
  371. {
  372. [self.delegate clickFriendItem:obj];
  373. }
  374. }
  375. -(void)clickHeadControl:(NSInteger)index{
  376. if (index == 0) {
  377. BogoNewsLikesViewController *vc = [[BogoNewsLikesViewController alloc]initWithNewsType:BOGONEWS_TYPE_LIKES];
  378. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  379. }else if(index == 1){
  380. BogoNewsLikesViewController *vc = [[BogoNewsLikesViewController alloc]initWithNewsType:BOGONEWS_TYPE_COMMENT];
  381. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  382. }else if (index == 2){
  383. FollowerViewController *FollowVC = [[FollowerViewController alloc]init];
  384. FollowVC.user_id = [GlobalVariables sharedInstance].userModel.user_id;
  385. FollowVC.type = [NSString stringWithFormat:@"%d",2];
  386. [[AppDelegate sharedAppDelegate] pushViewController:FollowVC animated:YES];
  387. }else if(index == 3){
  388. FollowerViewController *FollowVC = [[FollowerViewController alloc]init];
  389. FollowVC.user_id = [GlobalVariables sharedInstance].userModel.user_id;
  390. FollowVC.type = [NSString stringWithFormat:@"%d",1];
  391. [[AppDelegate sharedAppDelegate] pushViewController:FollowVC animated:YES];
  392. }
  393. }
  394. -(BogoNewsHeadView *)headView{
  395. if (!_headView) {
  396. _headView = [[BogoNewsHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(103))];
  397. _headView.delegate = self;
  398. }
  399. return _headView;
  400. }
  401. - (void)didReceiveMemoryWarning
  402. {
  403. [super didReceiveMemoryWarning];
  404. // Dispose of any resources that can be recreated.
  405. }
  406. @end