VoiceListViewController.m 13 KB

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