SHomeLiveV.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //
  2. // SHomeLiveV.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/26.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SHomeLiveV.h"
  9. #import "MainLiveTableViewCell.h"
  10. @implementation SHomeLiveV
  11. - (instancetype)initWithFrame:(CGRect)frame andUserId:(NSString *)userId
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self)
  15. {
  16. self.backgroundColor = kBackGroundColor;
  17. self.user_id = userId;
  18. [self creatMainView];
  19. [self loadNewNetDataWithPage:1];
  20. [self loadHotNetDataWithPage:1];
  21. }
  22. return self;
  23. }
  24. - (void)creatMainView
  25. {
  26. self.liveTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, kScreenW, self.height)];
  27. self.liveTableView.backgroundColor = kBackGroundColor;
  28. self.liveTableView.dataSource = self;
  29. self.liveTableView.delegate = self;
  30. self.liveTableView.tableHeaderView = self.newestOrHotView;
  31. self.liveTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  32. [self addSubview:self.liveTableView];
  33. [self.liveTableView registerNib:[UINib nibWithNibName:@"MainLiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"MainLiveTableViewCell"];
  34. [BGMJRefreshManager refresh:_liveTableView target:self headerRereshAction:nil footerRereshAction:@selector(footerRereshing)];
  35. }
  36. #pragma mark 尾部刷新
  37. - (void)footerRereshing
  38. {
  39. if (_has_next == 1)
  40. {
  41. self.currentPage ++;
  42. if (self.newOrHotType == 0)
  43. {
  44. [self loadNewNetDataWithPage:self.currentPage];
  45. }else
  46. {
  47. [self loadHotNetDataWithPage:self.currentPage];
  48. }
  49. }else
  50. {
  51. [BGMJRefreshManager endRefresh:self.liveTableView];
  52. return;
  53. }
  54. }
  55. #pragma mark 最新
  56. - (void)loadNewNetDataWithPage:(int)page
  57. {
  58. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  59. [parmDict setObject:@"user" forKey:@"ctl"];
  60. if (self.user_id)
  61. {
  62. [parmDict setObject:self.user_id forKey:@"to_user_id"];
  63. }
  64. [parmDict setObject:@"user_review" forKey:@"act"];
  65. [parmDict setObject:@"0" forKey:@"sort"];
  66. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  67. FWWeakify(self)
  68. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  69. FWStrongify(self)
  70. if ([responseJson toInt:@"status"] == 1)
  71. {
  72. self.currentPage = [responseJson toInt:@"page"];
  73. self.has_next = [responseJson toInt:@"has_next"];
  74. self.newHotLabel.text = [NSString stringWithFormat:ASLocalizedString(@"共%d个精彩回放"),[responseJson toInt:@"count"]];
  75. if ([responseJson toInt:@"page"] <= 1)
  76. {
  77. [self.newestArray removeAllObjects];
  78. }
  79. NSArray *array = [responseJson objectForKey:@"list"];
  80. if (array)
  81. {
  82. if (array.count > 0)
  83. {
  84. for (NSDictionary *dict in array)
  85. {
  86. SenderModel *model = [SenderModel mj_objectWithKeyValues:dict];
  87. [self.newestArray addObject:model];
  88. }
  89. }
  90. }
  91. if (!self.newestArray.count)
  92. {
  93. [self showNoContentViewOnView:self.liveTableView];
  94. }else
  95. {
  96. [self hideNoContentViewOnView:self.liveTableView];
  97. }
  98. [self.liveTableView reloadData];
  99. }
  100. [BGMJRefreshManager endRefresh:self.liveTableView];
  101. } FailureBlock:^(NSError *error) {
  102. FWStrongify(self)
  103. [BGMJRefreshManager endRefresh:self.liveTableView];
  104. }];
  105. }
  106. #pragma mark 最热
  107. - (void)loadHotNetDataWithPage:(int)page
  108. {
  109. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  110. [parmDict setObject:@"user" forKey:@"ctl"];
  111. if (self.user_id)
  112. {
  113. [parmDict setObject:self.user_id forKey:@"to_user_id"];
  114. }
  115. [parmDict setObject:@"user_review" forKey:@"act"];
  116. [parmDict setObject:@"1" forKey:@"sort"];
  117. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  118. FWWeakify(self)
  119. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  120. {
  121. FWStrongify(self)
  122. if ([responseJson toInt:@"status"] == 1)
  123. {
  124. self.currentPage = [responseJson toInt:@"page"];
  125. self.has_next = [responseJson toInt:@"has_next"];
  126. self.newHotLabel.text = [NSString stringWithFormat:ASLocalizedString(@"共%d个精彩回放"),[responseJson toInt:@"count"]];
  127. if ([responseJson toInt:@"page"] <= 1)
  128. {
  129. [self.hotArray removeAllObjects];
  130. }
  131. NSArray *array = [responseJson objectForKey:@"list"];
  132. if (array)
  133. {
  134. if (array.count > 0)
  135. {
  136. for (NSDictionary *dict in array)
  137. {
  138. SenderModel *model = [SenderModel mj_objectWithKeyValues:dict];
  139. [self.hotArray addObject:model];
  140. }
  141. }
  142. }
  143. if (self.isCouldLiveData)
  144. {
  145. [self.liveTableView reloadData];
  146. if (self.hotArray.count > 0)
  147. {
  148. [self hideNoContentViewOnView:self.liveTableView];
  149. }else
  150. {
  151. [self showNoContentViewOnView:self.liveTableView];
  152. }
  153. }
  154. }
  155. [BGMJRefreshManager endRefresh:self.liveTableView];
  156. } FailureBlock:^(NSError *error)
  157. {
  158. [BGMJRefreshManager endRefresh:self.liveTableView];
  159. NSLog(@"error==%@",error);
  160. }];
  161. }
  162. #pragma mark -UITableViewDelegate&UITableViewDataSource
  163. //返回段数
  164. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  165. {
  166. return 1;
  167. }
  168. //返回行数
  169. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  170. {
  171. if (self.newOrHotType == 0)//最新
  172. {
  173. return self.newestArray.count;
  174. }else //最热
  175. {
  176. return self.hotArray.count;
  177. }
  178. }
  179. //返回cell高度
  180. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  181. {
  182. return 55*kAppRowHScale;
  183. }
  184. //返回单元格
  185. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  186. {
  187. int newRow = (int)indexPath.row;
  188. MainLiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainLiveTableViewCell" forIndexPath:indexPath];
  189. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  190. if (self.newOrHotType == 0)
  191. {
  192. if (indexPath.row < self.newestArray.count)
  193. {
  194. SenderModel *model = self.newestArray[newRow];
  195. [cell creatCellWithModel:model];
  196. }
  197. }else
  198. {
  199. if (indexPath.row < self.hotArray.count)
  200. {
  201. SenderModel *model = self.hotArray[newRow];
  202. [cell creatCellWithModel:model];
  203. }
  204. }
  205. return cell;
  206. }
  207. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  208. {
  209. if ([self.BuguLive.liveState.roomId intValue]>0)
  210. {
  211. [FanweMessage alert:ASLocalizedString(@"当前有视频正在播放")];
  212. }
  213. else
  214. {
  215. UserModel *liveModel;
  216. if (self.newOrHotType == 0)
  217. {
  218. if (indexPath.row < self.newestArray.count)
  219. {
  220. liveModel = self.newestArray[indexPath.row];
  221. }
  222. }else if (self.newOrHotType == 1)
  223. {
  224. if (indexPath.row < self.hotArray.count)
  225. {
  226. liveModel = self.hotArray[indexPath.row];
  227. }
  228. }
  229. if (self.LDelegate)
  230. {
  231. [self.LDelegate goToLiveRoomWithModel:liveModel andView:self];
  232. }
  233. }
  234. }
  235. #pragma mark 最新和最热的点击事件
  236. - (void)NHBtnClick:(UIButton *)btn
  237. {
  238. for (UIButton *newBtn in self.newestOrHotView.subviews)
  239. {
  240. if ([newBtn isKindOfClass:[UIButton class]])
  241. {
  242. if (newBtn.tag ==btn.tag)
  243. {
  244. [newBtn setTitleColor:kAppGrayColor1 forState:0];
  245. }else
  246. {
  247. [newBtn setTitleColor:kAppGrayColor3 forState:0];
  248. }
  249. }
  250. }
  251. self.isCouldLiveData = YES;
  252. self.newOrHotType = (int)btn.tag;
  253. [self.liveTableView reloadData];
  254. if (self.newOrHotType == 0)
  255. {
  256. [self loadNewNetDataWithPage:1];
  257. }else
  258. {
  259. [self loadHotNetDataWithPage:1];
  260. }
  261. }
  262. #pragma mark 最新和最热的界面
  263. - (UIView *)newestOrHotView
  264. {
  265. if (!_newestOrHotView)
  266. {
  267. _newestOrHotView = [[UIView alloc]initWithFrame:CGRectMake(0,0,kScreenW,50)];
  268. _newestOrHotView.backgroundColor = kBackGroundColor;
  269. [_newestOrHotView addSubview:self.newHotLabel];
  270. NSArray *array2 = [[NSArray alloc]initWithObjects:ASLocalizedString(@"最新"),ASLocalizedString(@"最热"), nil];
  271. for (int i= 0; i < 2; i ++)
  272. {
  273. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];;
  274. button.frame = CGRectMake(kScreenW*3/4+kScreenW*i/8, 0, kScreenW/8, 50);
  275. [button setTitle:array2[i] forState:0];
  276. button.titleLabel.font = [UIFont systemFontOfSize:12];
  277. button.tag = i;
  278. [button addTarget:self action:@selector(NHBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  279. [_newestOrHotView addSubview:button];
  280. if (i == self.newOrHotType)
  281. {
  282. [button setTitleColor:[UIColor colorWithHexString:@"#887BFF"] forState:0];
  283. }else
  284. {
  285. [button setTitleColor:kAppGrayColor3 forState:0];
  286. }
  287. }
  288. }
  289. return _newestOrHotView;
  290. }
  291. - (UILabel *)newHotLabel
  292. {
  293. if (!_newHotLabel)
  294. {
  295. _newHotLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenW/3, 49)];
  296. _newHotLabel.font = [UIFont systemFontOfSize:12];
  297. _newHotLabel.textColor = kAppGrayColor1;
  298. }
  299. return _newHotLabel;
  300. }
  301. - (NSMutableArray *)hotArray
  302. {
  303. if (!_hotArray)
  304. {
  305. _hotArray = [[NSMutableArray alloc]init];
  306. }
  307. return _hotArray;
  308. }
  309. - (NSMutableArray *)newestArray
  310. {
  311. if (!_newestArray)
  312. {
  313. _newestArray = [[NSMutableArray alloc]init];
  314. }
  315. return _newestArray;
  316. }
  317. @end