BogoNewsSystemViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. //
  2. // BogoNewsSystemViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/5/14.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoNewsSystemViewController.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 "BGSystemMsgModel.h"
  17. #import "MsgCellRight.h"
  18. #import "MsgTimeCell.h"
  19. @interface BogoNewsSystemViewController ()<UITableViewDelegate, UITableViewDataSource>
  20. @property(nonatomic, strong) UILabel *titleL;
  21. @property(nonatomic, strong) UIButton *backBtn;
  22. @end
  23. @implementation BogoNewsSystemViewController{
  24. // int _select; //1.交易 2.好友 3.未关注
  25. int _page; //页数
  26. }
  27. - (void)viewWillAppear:(BOOL)animated
  28. {
  29. [super viewWillAppear:animated];
  30. [self.navigationController setNavigationBarHidden:YES animated:NO];
  31. }
  32. - (void)dealloc
  33. {
  34. [[NSNotificationCenter defaultCenter] removeObserver:self];
  35. }
  36. - (void)viewDidLoad
  37. {
  38. // self.title = @"系统消息";
  39. _conversationArr = NSMutableArray.new;
  40. _page = 1;
  41. self.mTableView = [[UITableView alloc] initWithFrame:CGRectZero];
  42. self.mTableView.delegate = self;
  43. self.mTableView.dataSource = self;
  44. self.mTableView.backgroundColor = kBackGroundColor;
  45. [self.view addSubview:self.mTableView];
  46. self.mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  47. UINib *nib = [UINib nibWithNibName:@"MsgCellLeft" bundle:nil];
  48. [self.mTableView registerNib:nib forCellReuseIdentifier:@"leftcell"];
  49. nib = [UINib nibWithNibName:@"MsgCellRight" bundle:nil];
  50. // [self.mtableview registerNib:nib forCellReuseIdentifier:@"rightcell"];
  51. nib = [UINib nibWithNibName:@"MsgTimeCell" bundle:nil];
  52. [self.mTableView registerNib:nib forCellReuseIdentifier:@"timecell"];
  53. [BGMJRefreshManager refresh:self.mTableView target:self headerRereshAction:@selector(headerStartRefresh) footerRereshAction:nil];
  54. self.titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, kScreenW, kTopHeight - kStatusBarHeight)];
  55. self.titleL.text =ASLocalizedString( @"系统消息");
  56. self.titleL.textAlignment = NSTextAlignmentCenter;
  57. self.titleL.font = [UIFont systemFontOfSize:18];
  58. [self.view addSubview:self.titleL];
  59. self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  60. [self.backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  61. [self.backBtn addTarget:self action:@selector(clickBackBtn:) forControlEvents:UIControlEventTouchUpInside];
  62. [self.view addSubview:self.backBtn];
  63. self.titleL.centerX = kScreenW / 2;
  64. self.backBtn.frame = CGRectMake(kRealValue(10), kStatusBarHeight, kRealValue(40), kRealValue(40));
  65. [self requestPageWithIndex:_page];
  66. [self.view addSubview:self.mTableView];
  67. [self.mTableView setFrame:CGRectMake(0, kTopHeight, kScreenW, kScreenHeight - kTopHeight - MG_BOTTOM_MARGIN)];
  68. self.mTableView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  69. id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  70. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  71. [self.view addGestureRecognizer:pan];
  72. }
  73. -(void)clickBackBtn:(UIButton *)sender{
  74. [self.navigationController popViewControllerAnimated:YES];
  75. }
  76. -(void)requestPageWithIndex:(NSInteger)pageIndex{
  77. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  78. [parmDict setObject:@"index" forKey:@"ctl"];
  79. [parmDict setObject:@"msg_list" forKey:@"act"];
  80. [parmDict setObject:[NSString stringWithFormat:@"%ld",pageIndex] forKey:@"p"];
  81. FWWeakify(self)
  82. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  83. FWStrongify(self)
  84. if (_page == 1) {
  85. [_conversationArr removeAllObjects];
  86. }
  87. NSArray *arr = [NSArray modelArrayWithClass:[BGSystemMsgModel class] json:responseJson[@"list"]];
  88. for (int i = 0; i < arr.count ; i ++) {
  89. BGSystemMsgModel *timemodel = [BGSystemMsgModel new];
  90. BGSystemMsgModel *model = arr[i];
  91. model.mMsgType = 1;
  92. timemodel.mMsgType = 0;
  93. timemodel.addtime = model.addtime;
  94. [_conversationArr addObject:timemodel];
  95. [_conversationArr addObject:model];
  96. }
  97. // [_conversationArr addObjectsFromArray:arr];
  98. [BGMJRefreshManager endRefresh:self.mTableView];
  99. [_mTableView reloadData];
  100. } FailureBlock:^(NSError *error) {
  101. dispatch_async(dispatch_get_main_queue(), ^{
  102. [BGMJRefreshManager endRefresh:self.mTableView];
  103. });
  104. }];
  105. }
  106. - (void)updateTableViewFrame
  107. {
  108. CGFloat tableViewHeight;
  109. if (!self.isHaveLive)
  110. {
  111. tableViewHeight = kScreenH - 64;
  112. }
  113. else
  114. {
  115. tableViewHeight = kScreenH / 2 - 44;
  116. }
  117. [self.mTableView setFrame:CGRectMake(0, 0, kScreenW, tableViewHeight)];
  118. }
  119. #pragma mrak-- ------------------------消息通知-- ------------------------
  120. - (void)IMChatMsgNotficationInList:(NSNotification *)notfication
  121. {
  122. if (![NSThread isMainThread])
  123. {
  124. [self performSelectorOnMainThread:@selector(IMChatMsgNotficationInList:) withObject:notfication waitUntilDone:NO];
  125. return;
  126. }
  127. SFriendObj *bfindone = nil;
  128. SIMMsgObj *thatmsg = notfication.object;
  129. for (SFriendObj *one in _conversationArr)
  130. {
  131. if (one.mUser_id == thatmsg.mSenderId)
  132. {
  133. bfindone = one;
  134. break;
  135. }
  136. }
  137. if (bfindone)
  138. {
  139. [bfindone setLMsg:thatmsg.mCoreTMsg];
  140. [self.mTableView reloadData];
  141. }
  142. }
  143. - (void)headerStartRefresh
  144. {
  145. [self requestPageWithIndex:1];
  146. }
  147. #pragma mark----------------------tableView的协议方法------------------------
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  149. {
  150. // if (_conversationArr.count > 0) {
  151. return _conversationArr.count;
  152. // }
  153. // return 0;
  154. }
  155. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
  156. {
  157. return UITableViewAutomaticDimension;
  158. }
  159. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  160. {
  161. return UITableViewAutomaticDimension;
  162. }
  163. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  164. {
  165. BGSystemMsgModel *msgobj = nil;
  166. if (_conversationArr.count > 0) {
  167. msgobj = _conversationArr[indexPath.row];
  168. }
  169. MsgCellRight *retcell = [MsgCellRight new];
  170. if (msgobj.mMsgType == 1)
  171. { //文字消息
  172. retcell = [tableView dequeueReusableCellWithIdentifier:@"leftcell"];
  173. retcell.mheadimg.image = [UIImage imageNamed:@"bogo_news_top_system"];
  174. [retcell.mmsglabel dealFace:msgobj.content];
  175. CGSize ss = [retcell.mmsglabel sizeThatFits:CGSizeMake(tableView.bounds.size.width - 73 - 50, CGFLOAT_MAX)];
  176. retcell.mlabelconstH.constant = ss.height;
  177. retcell.mlabelconstW.constant = ss.width;
  178. retcell.backgroundColor = kClearColor;
  179. retcell.selectionStyle = UITableViewCellSelectionStyleNone;
  180. return retcell;
  181. }
  182. else
  183. { //其他什么鬼...其他所有消息都当真时间消息处理了....
  184. MsgTimeCell *timecell = [tableView dequeueReusableCellWithIdentifier:@"timecell"];
  185. timecell.mbgview.layer.borderWidth = 0.0f;
  186. timecell.mbgview.backgroundColor = kClearColor;
  187. timecell.mtimelabel.text = msgobj.addtime;
  188. timecell.mtimelabel.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  189. timecell.mtimelabel.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  190. // [msgobj getTimeStr];
  191. timecell.selectionStyle = UITableViewCellSelectionStyleNone;
  192. return timecell;
  193. }
  194. retcell.selectionStyle = UITableViewCellSelectionStyleNone;
  195. retcell.backgroundColor = [UIColor clearColor];
  196. return retcell;
  197. }
  198. #pragma mark 点击单元格的方法
  199. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  200. {
  201. }
  202. #pragma mark-----------------------删除单元格方法------------------------
  203. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  204. {
  205. return NO;
  206. }
  207. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  208. {
  209. return ASLocalizedString(@"删除");
  210. }
  211. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  212. {
  213. // if (editingStyle == UITableViewCellEditingStyleDelete)
  214. // {
  215. // SFriendObj *oneobj = nil;
  216. // oneobj = [_conversationArr objectAtIndex:indexPath.row];
  217. // [SVProgressHUD showWithStatus:ASLocalizedString(@"操作中...")];
  218. //
  219. // [oneobj delThis:^(SResBase *resb) {
  220. //
  221. // if (resb.msuccess)
  222. // {
  223. // [SVProgressHUD dismiss];
  224. // [_conversationArr removeObjectAtIndex:indexPath.row];
  225. //
  226. // [self.mTableView beginUpdates];
  227. // [self.mTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  228. // [self.mTableView endUpdates];
  229. // //获取角标
  230. // [self reloadItem:_select];
  231. //
  232. // }
  233. // else
  234. // {
  235. // [SVProgressHUD showErrorWithStatus:resb.mmsg];
  236. // }
  237. //
  238. // }];
  239. // if (_conversationArr.count == 0) {
  240. // [self showNoContentView];
  241. // if (_isHaveLive)
  242. // {
  243. // self.noContentView.center = CGPointMake(self.view.frame.size.width/2, 87.5+40);
  244. // }
  245. // }
  246. // }
  247. }
  248. - (void)reloadItem:(int)selectItem
  249. {
  250. // if ([self.delegate respondsToSelector:@selector(reloadChatBadge:)])
  251. // {
  252. // [self.delegate reloadChatBadge:selectItem];
  253. // }
  254. }
  255. - (void)updateItem:(int)unReadNum
  256. {
  257. // if ([self.delegate respondsToSelector:@selector(updateChatFriendBadge:)])
  258. // {
  259. // [self.delegate updateChatFriendBadge:unReadNum];
  260. // }
  261. }
  262. - (void)itemBtnClick:(SFriendObj *)obj
  263. {
  264. // if ([self.delegate respondsToSelector:@selector(clickFriendItem:)])
  265. // {
  266. // [self.delegate clickFriendItem:obj];
  267. // }
  268. }
  269. - (void)didReceiveMemoryWarning
  270. {
  271. [super didReceiveMemoryWarning];
  272. // Dispose of any resources that can be recreated.
  273. }
  274. /*
  275. #pragma mark - Navigation
  276. // In a storyboard-based application, you will often want to do a little preparation before navigation
  277. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  278. // Get the new view controller using [segue destinationViewController].
  279. // Pass the selected object to the new view controller.
  280. }
  281. */
  282. /*
  283. #pragma mark - Navigation
  284. // In a storyboard-based application, you will often want to do a little preparation before navigation
  285. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  286. // Get the new view controller using [segue destinationViewController].
  287. // Pass the selected object to the new view controller.
  288. }
  289. */
  290. @end