BogoNewsViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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, SCREEN_HEIGHT)];
  66. topImgView.image = [UIImage imageNamed:@"mainBg"];
  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. UIImageView * titleBottomLineImgV = [[UIImageView alloc] init];
  84. titleBottomLineImgV.image = [UIImage imageNamed:@"home_title_lineBg"];
  85. [self.view addSubview:titleBottomLineImgV];
  86. self.titleL = [[UILabel alloc]init];//WithFrame:CGRectMake(15, kStatusBarHeight, kScreenW, kTopHeight - kStatusBarHeight)];
  87. self.titleL.text = ASLocalizedString(@"消息");
  88. // self.titleL.textAlignment = NSTextAlignmentCenter;
  89. self.titleL.font = [UIFont boldSystemFontOfSize:21];
  90. self.titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  91. [self.view addSubview:self.titleL];
  92. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.mas_equalTo(15);
  94. make.top.mas_equalTo(kStatusBarHeight + 8);
  95. }];
  96. [titleBottomLineImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(self.titleL);
  98. make.top.mas_equalTo(self.titleL.mas_bottom).mas_offset(-10);
  99. make.width.mas_equalTo(self.titleL);
  100. make.height.mas_equalTo(10);
  101. }];
  102. self.headView.top = kStatusBarHeight + (kTopHeight - kStatusBarHeight);
  103. [self.view addSubview:self.headView];
  104. self.mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.headView.bottom, kScreenW, kScreenH - self.headView.bottom - kTabBarHeight)];
  105. self.mTableView.delegate = self;
  106. self.mTableView.dataSource = self;
  107. self.mTableView.backgroundColor = kClearColor;
  108. // self.mTableView.tableHeaderView = self.headView;
  109. [self.view addSubview:self.mTableView];
  110. self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  111. [self.mTableView registerNib:[UINib nibWithNibName:@"ChatFriendCell" bundle:nil] forCellReuseIdentifier:@"ChatFriendCell"];
  112. [BGMJRefreshManager refresh:self.mTableView target:self headerRereshAction:@selector(headerStartRefresh) footerRereshAction:nil];
  113. [self.view addSubview:self.mTableView];
  114. }
  115. - (void)updateTableViewFrame
  116. {
  117. CGFloat tableViewHeight;
  118. if (!self.isHaveLive)
  119. {
  120. tableViewHeight = kScreenH - 64;
  121. }
  122. else
  123. {
  124. tableViewHeight = kScreenH / 2 - 44;
  125. }
  126. [self.mTableView setFrame:CGRectMake(0, 0, kScreenW, tableViewHeight)];
  127. }
  128. #pragma mrak-- ------------------------消息通知-- ------------------------
  129. - (void)IMChatMsgNotficationInList:(NSNotification *)notfication
  130. {
  131. if (![NSThread isMainThread])
  132. {
  133. [self performSelectorOnMainThread:@selector(IMChatMsgNotficationInList:) withObject:notfication waitUntilDone:NO];
  134. return;
  135. }
  136. SFriendObj *bfindone = nil;
  137. SIMMsgObj *thatmsg = notfication.object;
  138. for (SFriendObj *one in _conversationArr)
  139. {
  140. if (one.mUser_id == thatmsg.mSenderId)
  141. {
  142. bfindone = one;
  143. break;
  144. }
  145. }
  146. if (bfindone)
  147. {
  148. [bfindone setLMsg:thatmsg.mCoreTMsg];
  149. // [self.mTableView reloadData];
  150. }
  151. // SFriendObj *xxx = nil;
  152. // [SFriendObj getMyFriendMsgList:_select
  153. // lastObj:xxx
  154. // block:^(SResBase *resb, NSArray *all, int unReadNum) {
  155. //
  156. // if (all.count)
  157. // {
  158. // // [self hideNoContentView];
  159. // [self->_conversationArr removeAllObjects];
  160. // [self->_conversationArr addObjectsFromArray:all];
  161. //// [self.mTableView reloadData];
  162. //
  163. // }
  164. //
  165. //
  166. // }];
  167. //拉去官方消息
  168. [self reloadMsg];
  169. [[AppDelegate sharedAppDelegate] showNesBarRedNum];
  170. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  171. // 这里写延迟执行的代码
  172. [self headerStartRefresh];
  173. });
  174. }
  175. - (void)headerStartRefresh
  176. {
  177. // [self.mTableView reloadData];
  178. SFriendObj *xxx = nil;
  179. [SFriendObj getMyFriendMsgList:_select
  180. lastObj:xxx
  181. block:^(SResBase *resb, NSArray *all, int unReadNum) {
  182. NSLog(@"-=-=-=-=-=-=-==-=");
  183. // if (_unReadModel) {
  184. // NSInteger count = _unReadModel.bzone_reply + _unReadModel.bzone_like + _unReadModel.msg.count + unReadNum;
  185. // if (count == 0) {
  186. // self.tabBarItem.badgeValue = nil;
  187. // }else{
  188. // self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",count];
  189. // }
  190. // }
  191. // [self updateItem:_unReadModel.bzone_reply + _unReadModel.bzone_like + _unReadModel.msg.count + unReadNum];
  192. [BGMJRefreshManager endRefresh:self.mTableView];
  193. [self.conversationArr removeAllObjects];
  194. if (all.count){
  195. // self hideNoContentView];
  196. [self.conversationArr addObjectsFromArray:all];
  197. }else {
  198. // [self showNoContentView];
  199. // if (_isHaveLive)
  200. // {
  201. // self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  202. // }
  203. }
  204. [self.mTableView reloadData];
  205. }];
  206. }
  207. #pragma mark----------------------tableView的协议方法------------------------
  208. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  209. {
  210. return self.conversationArr.count + 1;
  211. }
  212. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  213. {
  214. return 85;
  215. }
  216. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  217. {
  218. SFriendObj *oneobj = nil;
  219. ChatFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChatFriendCell"];
  220. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  221. if (indexPath.row == 0) {
  222. [cell.mheadimg setImage:[UIImage imageNamed:@"bogo_news_top_system"]];
  223. cell.mname.text = ASLocalizedString(@"官方消息");
  224. if (_unReadModel.msg.content.length) {
  225. cell.mmsg.text = _unReadModel.msg.content;
  226. cell.mtime.text = [NSDate fd_getTimeSimpleFromTimestamp:_unReadModel.msg.addtime.doubleValue];
  227. }else{
  228. cell.mmsg.text = ASLocalizedString(@"Hi~ o(* ̄▽ ̄*)ブ欢迎你的到来!");
  229. }
  230. cell.msex.hidden = YES;
  231. [cell setUnReadCount:_unReadModel.msg.count];
  232. }else{
  233. if ((indexPath.row - 1) < _conversationArr.count)
  234. {
  235. oneobj = [_conversationArr objectAtIndex:indexPath.row - 1];
  236. }
  237. [cell.mheadimg sd_setImageWithURL:[NSURL URLWithString:oneobj.mHead_image] placeholderImage:kDefaultPreloadHeadImg];
  238. cell.viconImageView.hidden = YES;
  239. if (oneobj.mNick_name.length > 11)
  240. {
  241. cell.mname.text = [NSString stringWithFormat:@"%@...", [oneobj.mNick_name substringToIndex:11]];
  242. }
  243. else
  244. {
  245. cell.mname.text = oneobj.mNick_name;
  246. }
  247. [cell.mmsg dealFace:oneobj.mLastMsg];
  248. cell.mtime.text = [oneobj getTimeStr];
  249. if (oneobj.mSex == 0)
  250. {
  251. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  252. }
  253. else if (oneobj.mSex == 1)
  254. {
  255. cell.msex.image = [UIImage imageNamed:@"com_male_selected"];
  256. }
  257. else
  258. {
  259. cell.msex.image = [UIImage imageNamed:@"com_female_selected"];
  260. }
  261. NSString *ss = [NSString stringWithFormat:@"level%d", oneobj.mUser_level];
  262. cell.mlevel.image = [UIImage imageNamed:ss];
  263. NSLog(@"未读数量-----%@",oneobj.unread_count);
  264. [cell setUnReadCount:oneobj.unread_count.intValue];
  265. }
  266. cell.backgroundColor = kClearColor;
  267. return cell;
  268. }
  269. #pragma mark 点击单元格的方法
  270. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  271. {
  272. if (indexPath.row == 0) {
  273. BogoNewsSystemViewController *vc = [BogoNewsSystemViewController new];
  274. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  275. return;
  276. }
  277. SFriendObj *oneobj = nil;
  278. if (indexPath.row < _conversationArr.count + 1)
  279. {
  280. oneobj = [_conversationArr objectAtIndex:indexPath.row - 1];
  281. }
  282. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  283. backItem.title = ASLocalizedString(@"返回");
  284. self.navigationController.topViewController.navigationItem.backBarButtonItem = backItem;
  285. IMAUser *user = [[IMAUser alloc] initWith:[NSString stringWithFormat:@"%d", oneobj.mUser_id]];
  286. user.icon = oneobj.mHead_image;
  287. user.nickName = oneobj.mNick_name;
  288. user.remark = @"";
  289. if (self.isHaveLive == NO)
  290. {
  291. BGConversationServiceController *chatvc = [BGConversationServiceController makeChatVCWith:oneobj isHalf:NO];
  292. chatvc.dic = @{
  293. @"mHead_image": oneobj.mHead_image,
  294. @"mUser_id": @(oneobj.mUser_id)
  295. };
  296. [[AppDelegate sharedAppDelegate] pushViewController:chatvc animated:YES];
  297. }
  298. if (self.isHaveLive == YES)
  299. {
  300. //跳转 2去下界面
  301. [self itemBtnClick:oneobj];
  302. }
  303. [oneobj ignoreThisUnReadCount];
  304. [self.mTableView reloadData];
  305. [self reloadItem:_select];
  306. }
  307. #pragma mark-----------------------删除单元格方法------------------------
  308. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  309. {
  310. if (indexPath.row == 0){
  311. return false;
  312. }
  313. return YES;
  314. }
  315. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  316. {
  317. return ASLocalizedString(@"删除");
  318. }
  319. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  320. {
  321. if (editingStyle == UITableViewCellEditingStyleDelete)
  322. {
  323. SFriendObj *oneobj = nil;
  324. oneobj = [_conversationArr objectAtIndex:indexPath.row-1];
  325. [SVProgressHUD showWithStatus:ASLocalizedString(@"操作中...")];
  326. [oneobj delThis:^(SResBase *resb) {
  327. if (resb.msuccess)
  328. {
  329. [SVProgressHUD dismiss];
  330. [_conversationArr removeObjectAtIndex:indexPath.row-1];
  331. [self.mTableView beginUpdates];
  332. [self.mTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  333. [self.mTableView endUpdates];
  334. //获取角标
  335. [self reloadItem:_select];
  336. }
  337. else
  338. {
  339. [SVProgressHUD showErrorWithStatus:resb.mmsg];
  340. }
  341. }];
  342. if (_conversationArr.count == 0) {
  343. // [self showNoContentView];
  344. // if (_isHaveLive)
  345. // {
  346. // self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  347. // }
  348. }
  349. }
  350. }
  351. - (void)reloadItem:(int)selectItem
  352. {
  353. if ([self.delegate respondsToSelector:@selector(reloadChatBadge:)])
  354. {
  355. [self.delegate reloadChatBadge:selectItem];
  356. }
  357. }
  358. - (void)updateItem:(int)unReadNum
  359. {
  360. if ([self.delegate respondsToSelector:@selector(updateChatFriendBadge:)])
  361. {
  362. [self.delegate updateChatFriendBadge:unReadNum];
  363. }
  364. }
  365. - (void)itemBtnClick:(SFriendObj *)obj
  366. {
  367. if ([self.delegate respondsToSelector:@selector(clickFriendItem:)])
  368. {
  369. [self.delegate clickFriendItem:obj];
  370. }
  371. }
  372. -(void)clickHeadControl:(NSInteger)index{
  373. if (index == 0) {
  374. BogoNewsLikesViewController *vc = [[BogoNewsLikesViewController alloc]initWithNewsType:BOGONEWS_TYPE_LIKES];
  375. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  376. }else if(index == 1){
  377. BogoNewsLikesViewController *vc = [[BogoNewsLikesViewController alloc]initWithNewsType:BOGONEWS_TYPE_COMMENT];
  378. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  379. }else if (index == 2){
  380. FollowerViewController *FollowVC = [[FollowerViewController alloc]init];
  381. FollowVC.user_id = [GlobalVariables sharedInstance].userModel.user_id;
  382. FollowVC.type = [NSString stringWithFormat:@"%d",2];
  383. [[AppDelegate sharedAppDelegate] pushViewController:FollowVC animated:YES];
  384. }else if(index == 3){
  385. FollowerViewController *FollowVC = [[FollowerViewController alloc]init];
  386. FollowVC.user_id = [GlobalVariables sharedInstance].userModel.user_id;
  387. FollowVC.type = [NSString stringWithFormat:@"%d",1];
  388. [[AppDelegate sharedAppDelegate] pushViewController:FollowVC animated:YES];
  389. }
  390. }
  391. -(BogoNewsHeadView *)headView{
  392. if (!_headView) {
  393. _headView = [[BogoNewsHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(100))];
  394. _headView.delegate = self;
  395. }
  396. return _headView;
  397. }
  398. - (void)didReceiveMemoryWarning
  399. {
  400. [super didReceiveMemoryWarning];
  401. // Dispose of any resources that can be recreated.
  402. }
  403. @end