OnLiveViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // OnLiveViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/6/22.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "OnLiveViewController.h"
  9. #import "MBProgressHUD.h"
  10. #import "SenderModel.h"
  11. #import "MainLiveTableViewCell.h"
  12. @interface OnLiveViewController ()<UITableViewDelegate,UITableViewDataSource,MBProgressHUDDelegate>
  13. {
  14. UITableView *_myTableView;
  15. NSMutableArray *_dataArray;
  16. int _has_next;
  17. int _currentPage;
  18. int _state;
  19. UIView *_view2;
  20. UILabel *_liveLabel;
  21. UIButton *_lastButton2;
  22. int _sortState;
  23. int _page;
  24. int _status;
  25. int _count;
  26. }
  27. @end
  28. @implementation OnLiveViewController
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32. self.automaticallyAdjustsScrollViewInsets = NO;
  33. self.navigationItem.title = ASLocalizedString(@"我的回播");
  34. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  35. _dataArray = [[NSMutableArray alloc]init];
  36. _currentPage= 1;
  37. _sortState = 0;
  38. [self creatView];
  39. }
  40. - (void)creatView{
  41. //最新和最热的界面
  42. _view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 50)];
  43. _view2.backgroundColor = [UIColor whiteColor];
  44. UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 49, kScreenW, 1)];
  45. view2.backgroundColor = myTextColorLine5;
  46. [_view2 addSubview:view2];
  47. _liveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenW/3, 50)];
  48. _liveLabel.font = [UIFont systemFontOfSize:14];
  49. _liveLabel.textColor = kAppGrayColor1;
  50. [_view2 addSubview:_liveLabel];
  51. NSArray *array2 = [[NSArray alloc]initWithObjects:ASLocalizedString(@"最新"),ASLocalizedString(@"最热"), nil];
  52. for (int i= 0; i < 2; i ++)
  53. {
  54. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  55. button.frame = CGRectMake(kScreenW*3/4+kScreenW*i/8, 0, kScreenW/8, 50);
  56. [button setTitle:array2[i] forState:0];
  57. button.titleLabel.font = [UIFont systemFontOfSize:14];
  58. if (i == 0)
  59. {
  60. [button setTitleColor:kAppGrayColor1 forState:0];
  61. }else
  62. {
  63. [button setTitleColor:kAppGrayColor3 forState:0];
  64. }
  65. button.tag = 100+i;
  66. [button addTarget:self action:@selector(buttonClick2:) forControlEvents:UIControlEventTouchUpInside];
  67. [_view2 addSubview:button];
  68. }
  69. _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight)];
  70. _myTableView.backgroundColor = kBackGroundColor;
  71. _myTableView.dataSource = self;
  72. _myTableView.delegate = self;
  73. _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  74. [_myTableView registerNib:[UINib nibWithNibName:@"MainLiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"MainLiveTableViewCell"];
  75. [self.view addSubview:_myTableView];
  76. [BGMJRefreshManager refresh:_myTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  77. }
  78. - (void)viewWillAppear:(BOOL)animated
  79. {
  80. [super viewWillAppear:animated];
  81. }
  82. - (void)viewWillDisappear:(BOOL)animated
  83. {
  84. [super viewWillDisappear:animated];
  85. }
  86. - (void)backClick
  87. {
  88. [[AppDelegate sharedAppDelegate]popViewController];
  89. }
  90. //最新和最热的点击事件
  91. - (void)buttonClick2:(UIButton *)button
  92. {
  93. for (UIButton *btn in _view2.subviews)
  94. {
  95. if ([btn isKindOfClass:[UIButton class]])
  96. {
  97. if (btn.tag == button.tag)
  98. {
  99. [btn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  100. }else
  101. {
  102. [btn setTitleColor:kAppGrayColor3 forState:UIControlStateNormal];
  103. }
  104. }
  105. }
  106. _sortState = (int)button.tag -100;
  107. [self loadNetDataWithPage:1];
  108. }
  109. - (void)headerReresh
  110. {
  111. [self loadNetDataWithPage:1];
  112. }
  113. - (void)footerReresh
  114. {
  115. if (_has_next == 1)
  116. {
  117. _page ++;
  118. [self loadNetDataWithPage:_page];
  119. }
  120. else
  121. {
  122. [BGMJRefreshManager endRefresh:_myTableView];
  123. }
  124. }
  125. //数据加载
  126. - (void)loadNetDataWithPage:(int)page
  127. {
  128. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  129. [parmDict setObject:@"user" forKey:@"ctl"];
  130. if (self.user_id)
  131. {
  132. [parmDict setObject:self.user_id forKey:@"to_user_id"];
  133. }
  134. [parmDict setObject:@"user_review" forKey:@"act"];
  135. [parmDict setObject:[NSString stringWithFormat:@"%d",_sortState] forKey:@"sort"];
  136. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  137. FWWeakify(self)
  138. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  139. FWStrongify(self)
  140. if ([responseJson toInt:@"status"] == 1)
  141. {
  142. _page = [responseJson toInt:@"page"];
  143. if (_page == 1 || _page == 0)
  144. {
  145. _count = [responseJson toInt:@"count"];
  146. }
  147. _status = [responseJson toInt:@"status"];
  148. if (_page == 1)
  149. {
  150. [_dataArray removeAllObjects];
  151. }
  152. _has_next = [responseJson toInt:@"has_next"];
  153. _liveLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%d个精彩回放"),_count];
  154. NSArray *array = [responseJson objectForKey:@"list"];
  155. if (array)
  156. {
  157. if (array.count > 0)
  158. {
  159. for (NSDictionary *dict in array)
  160. {
  161. //5-7 回播点击问题
  162. NSMutableDictionary *dic;
  163. if([dict objectForKey:@"live_image"]){
  164. dic=[NSMutableDictionary dictionaryWithDictionary:dict];
  165. }else{
  166. dic=[NSMutableDictionary dictionaryWithDictionary:dict];
  167. [dic setObject:@"" forKey:@"live_image"];
  168. }
  169. //UserModel *model = [UserModel mj_objectWithKeyValues:dict];SenderModel
  170. SenderModel *model = [SenderModel mj_objectWithKeyValues:dic];
  171. }
  172. }
  173. }
  174. if (_dataArray.count > 0)
  175. {
  176. [self hideNoContentView];
  177. }
  178. else
  179. {
  180. [self showNoContentView];
  181. }
  182. [self.myTableView reloadData];
  183. }else
  184. {
  185. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  186. }
  187. [BGMJRefreshManager endRefresh:_myTableView];
  188. } FailureBlock:^(NSError *error)
  189. {
  190. [BGMJRefreshManager endRefresh:_myTableView];
  191. }];
  192. }
  193. #pragma mark -UITableViewDelegate&UITableViewDataSource
  194. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  195. {
  196. if (_dataArray.count > 0)
  197. {
  198. return _dataArray.count;
  199. }else
  200. {
  201. return 0;
  202. }
  203. }
  204. //返回段数
  205. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  206. {
  207. return 1;
  208. }
  209. //返回单元格
  210. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  211. {
  212. //通过复用id(reusedID)来寻找,只有同种类型的cell才能算找到
  213. if (_dataArray.count > 0 && indexPath.row < _dataArray.count)
  214. {
  215. MainLiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainLiveTableViewCell"];
  216. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  217. UserModel *model = _dataArray[indexPath.row];
  218. [cell creatCellWithModel:model];
  219. return cell;
  220. }else
  221. {
  222. return nil;
  223. }
  224. }
  225. //返回cell高度
  226. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  227. {
  228. return 60;
  229. }
  230. //段头
  231. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  232. {
  233. return 50;
  234. }
  235. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  236. {
  237. return _view2;
  238. }
  239. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  240. {
  241. if (_dataArray.count > 0 && _dataArray.count > indexPath.row)
  242. {
  243. if ([self checkUser:[IMAPlatform sharedInstance].host])
  244. {
  245. SenderModel *model = _dataArray[indexPath.row];
  246. TCShowUser *user = [[TCShowUser alloc] init];
  247. user.avatar = model.head_image;
  248. user.uid = model.user_id;
  249. user.username = model.nick_name;
  250. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  251. liveRoom.liveType = 1;
  252. liveRoom.host = user;
  253. liveRoom.avRoomId = [model.id intValue];
  254. liveRoom.title = model.id;
  255. liveRoom.vagueImgUrl = model.head_image;
  256. //2020-1-7 小直播变大
  257. [LiveCenterManager sharedInstance].itemModel=liveRoom;
  258. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:liveRoom modelArr:_dataArray isSusWindow:NO isSmallScreen:NO block:^(BOOL isFinished) {
  259. }];
  260. }else
  261. {
  262. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  263. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  264. } completion:^{
  265. }];
  266. }
  267. }
  268. }
  269. //删除操作,需要两个代理方法配合使用
  270. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  271. {
  272. //indexPath 就是删除的位置,通过代理方法,给我们了
  273. if (editingStyle == UITableViewCellEditingStyleDelete)
  274. {
  275. //1.数据源删除
  276. SenderModel *model = _dataArray[indexPath.row];
  277. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  278. [dictM setObject:@"video" forKey:@"ctl"];
  279. [dictM setObject:@"del_video_history" forKey:@"act"];
  280. [dictM setObject:[NSString stringWithFormat:@"%@",model.id] forKey:@"room_id"];
  281. [self.httpsManager POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  282. {
  283. [self loadNetDataWithPage:1];
  284. if ([responseJson toInt:@"status"] == 1)
  285. {
  286. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"删除回播视频成功")];
  287. }
  288. } FailureBlock:^(NSError *error)
  289. {
  290. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"删除回播视频失败,请重新操作")];
  291. }];
  292. }
  293. }
  294. //返回编辑类型.是增加还是删除
  295. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  296. {
  297. return UITableViewCellEditingStyleDelete;
  298. }
  299. - (BOOL)checkUser:(id<IMHostAble>)user
  300. {
  301. if (![user conformsToProtocol:@protocol(AVUserAble)])
  302. {
  303. return NO;
  304. }
  305. return YES;
  306. }
  307. @end