VideoViewController.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //
  2. // VideoViewController.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/5/2.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "VideoViewController.h"
  9. #import "VideoCollectionViewCell.h"
  10. #import "HMHotModel.h"
  11. #import "NewestItemCell.h"
  12. @interface VideoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  13. @property (nonatomic, strong) NSMutableArray * dataArray;
  14. @property (nonatomic, strong) UICollectionView * collectionView;
  15. @property (nonatomic, assign) int page;
  16. @property (nonatomic, assign) int has_next;
  17. @property (nonatomic, assign) BOOL canClickItem;
  18. @property (nonatomic, strong) HMHotModel * videoModel;
  19. @end
  20. @implementation VideoViewController
  21. - (void)dealloc
  22. {
  23. [[NSNotificationCenter defaultCenter] removeObserver:self];
  24. }
  25. - (NSMutableArray *)dataArray
  26. {
  27. if (_dataArray == nil)
  28. {
  29. _dataArray = [NSMutableArray array];
  30. }
  31. return _dataArray;
  32. }
  33. - (void)viewDidLoad
  34. {
  35. [super viewDidLoad];
  36. [self createView];
  37. [self setNetworing:1];
  38. }
  39. - (void)createView
  40. {
  41. self.view.backgroundColor = kWhiteColor;
  42. UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc] init] ;
  43. // CGFloat itemW = (self.viewFrame.size.width-3)/2.0;
  44. // CGFloat itemH = (self.viewFrame.size.width-3)/2.0;
  45. // //设置cell的大小
  46. // flow.itemSize = CGSizeMake(itemW, itemH) ;
  47. // flow.minimumLineSpacing = 3;
  48. // flow.minimumInteritemSpacing = 3;
  49. // flow.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10) ;
  50. _collectionView = [[UICollectionView alloc] initWithFrame:self.viewFrame collectionViewLayout:flow];
  51. _collectionView.delegate = self;
  52. _collectionView.dataSource = self;
  53. _collectionView.backgroundColor = kClearColor;
  54. _collectionView.tag = 1107;
  55. [_collectionView registerNib:[UINib nibWithNibName:@"NewestItemCell" bundle:nil] forCellWithReuseIdentifier:@"NewestItemCell"];
  56. // [_collectionView registerClass:[NewestItemCell class] forCellWithReuseIdentifier:@"NewestItemCell"];
  57. [self.view addSubview:_collectionView];
  58. [BGMJRefreshManager refresh:_collectionView target:self headerRereshAction:@selector(headerReresh) shouldHeaderBeginRefresh:NO footerRereshAction:@selector(footerRereshing)];
  59. _canClickItem = YES;
  60. [self setNetworing:1];
  61. }
  62. #pragma mark -- 头部刷新
  63. - (void)headerReresh
  64. {
  65. [self setNetworing:1];
  66. }
  67. //尾部刷新
  68. - (void)footerRereshing
  69. {
  70. if (_has_next == 1)
  71. {
  72. _page ++;
  73. [self setNetworing:_page];
  74. }
  75. else
  76. {
  77. [BGMJRefreshManager endRefresh:_collectionView];
  78. }
  79. }
  80. - (void)setNetworing:(int)page
  81. {
  82. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  83. [parmDict setObject:@"index" forKey:@"ctl"];
  84. [parmDict setObject:@"classify" forKey:@"act"];
  85. [parmDict setObject:@(_classified_id) forKey:@"classified_id"];
  86. [parmDict setObject:@(page) forKey:@"p"];
  87. FWWeakify(self)
  88. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  89. FWStrongify(self)
  90. if ([responseJson toInt:@"status"] == 1)
  91. {
  92. self.has_next = [responseJson toInt:@"has_next"];
  93. self.page = [responseJson toInt:@"page"];
  94. if (self.page == 1)
  95. {
  96. [self.dataArray removeAllObjects];
  97. }
  98. self.videoModel = [HMHotModel mj_objectWithKeyValues:responseJson];
  99. [self.dataArray addObjectsFromArray:self.videoModel.list];
  100. [self.collectionView reloadData];
  101. }
  102. [BGMJRefreshManager endRefresh:self.collectionView];
  103. if (!self.dataArray.count)
  104. {
  105. [self showNoContentView];
  106. }
  107. else
  108. {
  109. [self hideNoContentView];
  110. }
  111. } FailureBlock:^(NSError *error) {
  112. FWStrongify(self)
  113. [BGMJRefreshManager endRefresh:self.collectionView];
  114. }];
  115. }
  116. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  117. {
  118. return self.dataArray.count;
  119. }
  120. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. // VideoCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCollectionViewCell" forIndexPath:indexPath] ;
  123. // cell.model = self.dataArray[indexPath.item];
  124. // return cell ;
  125. NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
  126. cell.backgroundColor = [UIColor whiteColor];
  127. LivingModel *LModel = _dataArray[indexPath.row];
  128. [cell setCellContent:LModel Type:1];
  129. return cell;
  130. }
  131. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. HMHotItemModel *model = self.dataArray[indexPath.item];
  134. if(model.password.length > 0)
  135. {
  136. }
  137. else
  138. {
  139. [self joinLivingRoom:self.dataArray[indexPath.item]];
  140. return;
  141. }
  142. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请输入房间密码")preferredStyle:UIAlertControllerStyleAlert];
  143. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  144. textField.placeholder = ASLocalizedString(@"请输入密码");
  145. textField.delegate = self;
  146. textField.keyboardType = UIKeyboardTypeNumberPad;
  147. }];
  148. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  149. }];
  150. [alertController addAction:actionCacel];
  151. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  152. NSString *password = alertController.textFields.firstObject.text;
  153. NSString *md5Str = [[NSString md5String:password] uppercaseString];
  154. //转化为大写
  155. NSLog(@"%@",md5Str);
  156. if ([md5Str isEqualToString:model.password]) {
  157. [self joinLivingRoom:self.dataArray[indexPath.item]];
  158. }else{
  159. [FanweMessage alertHUD:ASLocalizedString(@"密码不正确")];
  160. }
  161. }];
  162. [alertController addAction:actionConfirm];
  163. [self presentViewController:alertController animated:YES completion:nil];
  164. // [self joinLivingRoom:self.dataArray[indexPath.item]];
  165. }
  166. #pragma mark 加入直播间
  167. - (void)joinLivingRoom:(HMHotItemModel *)model
  168. {
  169. // 防止重复点击
  170. if (self.canClickItem)
  171. {
  172. self.canClickItem = NO;
  173. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  174. self.canClickItem = YES;
  175. });
  176. }
  177. else
  178. {
  179. return;
  180. }
  181. if (![BGUtils isNetConnected])
  182. {
  183. return;
  184. }
  185. if ([IMAPlatform sharedInstance].host)
  186. {
  187. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc]init];
  188. liveRoom.chatRoomId = model.group_id;
  189. liveRoom.avRoomId = model.room_id;
  190. liveRoom.title = [NSString stringWithFormat:@"%d",model.room_id];
  191. liveRoom.vagueImgUrl = model.head_image;
  192. TCShowUser *showUser = [[TCShowUser alloc]init];
  193. showUser.uid = model.user_id;
  194. showUser.avatar = model.head_image;
  195. showUser.username = model.nick_name;
  196. liveRoom.host = showUser;
  197. if (model.live_in == FW_LIVE_STATE_ING)
  198. {
  199. liveRoom.liveType = FW_LIVE_TYPE_AUDIENCE;
  200. }
  201. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  202. // {
  203. // liveRoom.liveType = FW_LIVE_TYPE_RELIVE;
  204. // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
  205. // }
  206. if ([LiveCenterManager sharedInstance].itemModel) {
  207. [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLiveRoomNotification" object:nil];
  208. }
  209. //2020-1-7 小直播变大
  210. [LiveCenterManager sharedInstance].itemModel=liveRoom;
  211. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  212. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:liveRoom modelArr:self.dataArray isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  213. }];
  214. }
  215. else
  216. {
  217. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  218. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  219. } completion:^{
  220. }];
  221. }
  222. // // model 转为 dic
  223. // NSDictionary *dic = model.mj_keyValues;
  224. //
  225. //
  226. //
  227. // // 直播管理中心开启观众直播
  228. // BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  229. // [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofPramaDic:dic.mutableCopy isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  230. // }];
  231. }
  232. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  233. {
  234. return CGSizeMake((kScreenW-30)/2.0f, (kScreenW-30) / 2.0f + kRealValue(32));
  235. // return CGSizeMake((kScreenW-30)/2.0f, (kScreenW-30)/2.0f);
  236. }
  237. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  238. return 10;
  239. }
  240. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  241. return 0;
  242. }
  243. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  244. {
  245. return UIEdgeInsetsMake(10, 10, 0, 10);
  246. }
  247. @end