YOUPAILZLiveListVC.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //
  2. // YOUPAILZLiveListVC.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/19.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveListVC.h"
  9. #import "YOUPAILZLiveItemCell.h"
  10. //#import <AgoraRtcEngineKit/AgoraRtcEngineKit.h>
  11. #import "YOUPAILCBannerModel.h"
  12. #import "SDCycleScrollView.h"
  13. #import "YYAnimatedImageView.h"
  14. #import "YYImage.h"
  15. #import "YOUPAILZLiveModel.h"
  16. #import "YOUPAILZLiveAudienceVC.h"
  17. #import "YOUPAILZLiveAnchorVC.h"
  18. #import "UIViewController+TFPresent.h"
  19. #import "YOUPAILZEndLiveHintModel.h"
  20. #import "YOUPAILZEndLiveHintView.h"
  21. #import "YOUPAILZLiveManagerListUtils.h"
  22. @interface YOUPAILZLiveListVC () <UICollectionViewDataSource,UICollectionViewDelegate,AgoraRtcEngineDelegate,SDCycleScrollViewDelegate>
  23. //@property (nonatomic, strong) AgoraRtcEngineKit *youpaipagoraKit;
  24. //@property (nonatomic, strong) AgoraRtcVideoCanvas *youpaipremoteCanvas; // 远程画布
  25. //@property (nonatomic, strong) YOUPAILZLiveListItemModel *youpaipliveItemModel;
  26. @property (nonatomic, assign) NSInteger youpaipcurrentPage;
  27. @property (nonatomic, assign) NSInteger youpaiptotalPage;
  28. @property (nonatomic, strong) NSArray <YOUPAILCBannerModel *> *youpaipbannerArray;
  29. @property (nonatomic, strong) SDCycleScrollView *youpaipbannerView;
  30. @property (nonatomic, strong) NSArray <YOUPAILZLiveListItemModel*> *youpaipgetRandLives;
  31. @property (nonatomic, strong) YYImage *icLiveZhibozhong28;
  32. @property (nonatomic, strong) YYImage *icLiveZhibozhong38;
  33. @property (nonatomic, strong) YYImage *youpaipicLiveUserHeader;
  34. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  35. @end
  36. @implementation YOUPAILZLiveListVC
  37. //@synthesize consumer;
  38. //
  39. //- (void)dealloc{
  40. // [[NSNotificationCenter defaultCenter] removeObserver:self];
  41. //}
  42. //
  43. //- (void)viewWillAppear:(BOOL)animated{
  44. // [super viewWillAppear:animated];
  45. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(leave) name:UIApplicationWillResignActiveNotification object:nil];
  46. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifjoin) name:UIApplicationDidBecomeActiveNotification object:nil];
  47. //}
  48. //- (void)viewDidAppear:(BOOL)animated{
  49. // [super viewDidAppear:animated];
  50. // [self youpaifjoin];
  51. //}
  52. //- (void)viewWillDisappear:(BOOL)animated{
  53. // [super viewWillDisappear:animated];
  54. //
  55. // [self leave];
  56. // [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
  57. // [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
  58. //}
  59. - (void)viewDidLoad {
  60. [super viewDidLoad];
  61. // self.view.backgroundColor = LCBkgColor;
  62. [self youpaifsetupUI];
  63. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leave) name:@"CallVideo" object:nil];
  64. }
  65. -(void)youpaifsetupUI{
  66. [self.view addSubview:self.youpaipcollectionView];
  67. [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.top.bottom.right.offset(0.0f);
  69. }];
  70. [self.youpaipcollectionView.mj_header beginRefreshing];
  71. }
  72. ///// 初始化 AgoraRtcEngineKit 类。
  73. //- (void)youpaifinitializeAgoraEngine{
  74. // self.youpaipagoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:AgoraID delegate:self];
  75. // //设置频道场景
  76. // [self.youpaipagoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
  77. // //设置用户角色
  78. // [self.youpaipagoraKit setClientRole:AgoraClientRoleAudience];
  79. // //初始化并返回新分配的具有指定视频分辨率的AgoraVideoEncoderConfiguration对象
  80. // AgoraVideoEncoderConfiguration *configuration = [[AgoraVideoEncoderConfiguration alloc] initWithSize:AgoraVideoDimension1280x720 frameRate:AgoraVideoFrameRateFps24 bitrate:AgoraVideoBitrateCompatible orientationMode:AgoraVideoOutputOrientationModeAdaptative];
  81. // [self.youpaipagoraKit setVideoEncoderConfiguration:configuration];
  82. // //设置本地视频镜像模式
  83. // [self.youpaipagoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
  84. // //启用与Agora Web SDK的互操作性。
  85. // [self.youpaipagoraKit enableWebSdkInteroperability:YES];
  86. // //启用视频
  87. // [self.youpaipagoraKit enableVideo];
  88. // //设置视频源
  89. // [self.youpaipagoraKit setVideoSource:self];
  90. // [self.youpaipagoraKit youpaifmuteAllRemoteAudioStreams:YES];
  91. //}
  92. ///// 加入频道
  93. //- (void)youpaifjoinChannel{
  94. // WeakSelf;
  95. // [self.youpaipagoraKit joinChannelByToken:nil channelId:self.youpaipliveItemModel.room_id info:nil uid:[[LCSaveModel getUserModel].userinfo.user_id integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
  96. // //检查扬声器是否已启用
  97. // if([weakSelf.youpaipagoraKit isSpeakerphoneEnabled]){
  98. // //设置扬声器
  99. // [weakSelf.youpaipagoraKit setEnableSpeakerphone:YES];
  100. // }
  101. // // 设置不自动锁屏
  102. // [UIApplication sharedApplication].idleTimerDisabled = YES;
  103. // }];
  104. //}
  105. ///// 离开频道
  106. //- (void)youpaifleaveChannel{
  107. // [self.youpaipagoraKit youpaifmuteAllRemoteAudioStreams:NO];
  108. // [self.youpaipagoraKit setupLocalVideo:nil];
  109. // // 离开频道。
  110. // [self.youpaipagoraKit youpaifleaveChannel:nil];
  111. // self.youpaipagoraKit.delegate = nil;
  112. // self.youpaipagoraKit.videoSource = nil;
  113. // self.youpaipagoraKit = nil;
  114. //}
  115. //
  116. //- (void)youpaifjoin{
  117. // BOOL isLive = NO; /// 是否在直播
  118. // for (UIViewController *vc in self.navigationController.viewControllers) {
  119. // if ([vc isKindOfClass:[YOUPAILZLiveAnchorVC class]]) {
  120. // isLive = YES;
  121. // }
  122. // }
  123. // if (self.type == 1 && self.dataSource.count != 0 && ![LCSaveData getIsVideo] && !isLive && self.youpaipliveItemModel.is_virtual != 1) { // 只有推荐才初始化声网SDK
  124. // [self youpaifinitializeAgoraEngine];
  125. // [self youpaifjoinChannel];
  126. // }
  127. //}
  128. //
  129. //- (void)leave{
  130. // if (self.type == 1 && self.youpaipagoraKit != nil) {
  131. // [self youpaifleaveChannel];
  132. // }
  133. //}
  134. - (void)youpaifgetRandLiveClick:(UIButton *)sender{
  135. [self youpaifjoinLiveWithRoomId:self.youpaipgetRandLives[sender.tag].youpaiproom_id is_comein_room_hide:0];
  136. }
  137. //#pragma mark - AgoraRtcEngineDelegate
  138. //
  139. //
  140. //- (void)rtcEngine:(AgoraRtcEngineKit *)engine didJoinedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed{
  141. // if([self.youpaipliveItemModel.anchor_id isEqual:[NSString stringWithFormat:@"%@",@(uid)]]){
  142. // AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  143. // videoCanvas.uid = uid;
  144. // videoCanvas.view = self.bigItemCell.youpaipremoteVideo;
  145. // // 视图的渲染模式
  146. // videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  147. // // 设置远端视图。
  148. // [self.youpaipagoraKit setupRemoteVideo:videoCanvas];
  149. // self.youpaipremoteCanvas = videoCanvas;
  150. // }
  151. //}
  152. //
  153. //
  154. //#pragma mark - AgoraVideoSourceProtocol
  155. //// 初始化视频源
  156. //- (BOOL)shouldInitialize{
  157. // return YES;
  158. //}
  159. //
  160. //// 检索缓冲区类型
  161. //- (AgoraVideoBufferType)bufferType{
  162. // // 使用像素缓冲区传输视频数据
  163. // return AgoraVideoBufferTypePixelBuffer;
  164. //}
  165. #pragma mark - UICollectionViewDataSource
  166. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  167. return self.youpaipdataSource.count;
  168. }
  169. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  170. // if (indexPath.item == 0 && self.type == 1) {
  171. // [self.bigItemCell youpaifreloadWithModel:self.dataSource[indexPath.item]];
  172. // return self.bigItemCell;
  173. // }else{
  174. YOUPAILZLiveItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILZLiveItemCell" forIndexPath:indexPath];
  175. LZLiveItemCellStyle style;
  176. if (self.youpaiptype == 2) { /// 只有热门才显示排名
  177. style = LZLiveItemCellStyleWithRanking;
  178. }else{
  179. style = LZLiveItemCellStyleWithDefault;
  180. }
  181. cell.youpaipanimationImage = self.icLiveZhibozhong28;
  182. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item] style:style index:indexPath.item];
  183. UILongPressGestureRecognizer* longgs = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongpress:)];
  184. [cell addGestureRecognizer:longgs];//为cell添加手势
  185. longgs.minimumPressDuration = 0.25f;//定义长按识别时长
  186. longgs.view.tag = indexPath.item;//将手势和cell的序号绑定
  187. return cell;
  188. // }
  189. }
  190. - (void)youpaiflongpress:(UILongPressGestureRecognizer *)ges{
  191. if(ges.state == UIGestureRecognizerStateEnded){
  192. NSInteger row = ges.view.tag;
  193. YOUPAILZLiveListItemModel *model = self.youpaipdataSource[row];
  194. if(model.youpaipis_comein_room_hide == 1){
  195. @weakify(self);
  196. ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"悄悄进房" andblock:^{//举报
  197. @strongify(self);
  198. [self youpaifjoinLiveWithRoomId:model.youpaiproom_id is_comein_room_hide:model.youpaipis_comein_room_hide];
  199. }];
  200. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[action]];
  201. alertSheet.alertWindow.hidden = NO;
  202. [alertSheet show];
  203. }
  204. }
  205. }
  206. #pragma mark - UICollectionViewDelegate
  207. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  208. [self youpaifjoinLiveWithRoomId:self.youpaipdataSource[indexPath.item].youpaiproom_id is_comein_room_hide:0];
  209. }
  210. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  211. // if (indexPath.item == 0 && self.type == 1) {
  212. // CGFloat width = KScreenWidth - 10.0f;
  213. // return CGSizeMake(width, width * 0.8f);
  214. // }else{
  215. CGFloat width = (KScreenWidth/2) -1.0f;
  216. return CGSizeMake(width, width);
  217. // }
  218. }
  219. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  220. CGFloat height = 0.0f;
  221. if (self.youpaipbannerArray.count > 0) {
  222. height += KScreenWidth*(88/365.0);
  223. }
  224. if (self.youpaipgetRandLives.count > 0) {
  225. height += 129.0f;
  226. }
  227. return CGSizeMake(KScreenWidth, height);
  228. }
  229. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  230. {
  231. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:
  232. UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
  233. for (UIView* view in headerView.subviews) {
  234. [view removeFromSuperview];
  235. }
  236. // 如果当前想要的是头部视图
  237. if (self.youpaipbannerArray.count > 0) {
  238. NSMutableArray* imgUrlArray = [NSMutableArray array];
  239. for (YOUPAILCBannerModel* model in self.youpaipbannerArray) {
  240. [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
  241. }
  242. self.youpaipbannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(5,0, KScreenWidth - 10.0f,KScreenWidth*(88/375.0)) delegate:self placeholderImage:[UIImage imageNamed:@"banner_default"]];
  243. self.youpaipbannerView.autoScrollTimeInterval = 3.0;//3s轮播
  244. self.youpaipbannerView.layer.cornerRadius = 3.0;
  245. self.youpaipbannerView.layer.masksToBounds = YES;
  246. self.youpaipbannerView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
  247. self.youpaipbannerView.imageURLStringsGroup = imgUrlArray;
  248. [headerView addSubview:self.youpaipbannerView];
  249. }
  250. if (self.youpaipgetRandLives.count > 0) {
  251. CGFloat y = self.youpaipbannerArray.count > 0 ? KScreenWidth*(88/365.0) : 0.0f;
  252. UIView *randLiveBgV = [[UIView alloc] initWithFrame:CGRectMake(5.0f, y, KScreenWidth - 10.0f, 129.0f)];
  253. [headerView addSubview:randLiveBgV];
  254. UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 14.0f, randLiveBgV.mj_w, 16.5f)];
  255. titleL.textAlignment = NSTextAlignmentCenter;
  256. titleL.font = LCFont12;
  257. titleL.textColor = HexColorFromRGB(0xCCCCCC);
  258. [randLiveBgV addSubview:titleL];
  259. NSString *text = @"— 新秀推荐 —";
  260. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:text];
  261. NSRange range2 = [text rangeOfString:@"新秀推荐"];
  262. [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x333333) range:range2];
  263. titleL.attributedText = attrStr;
  264. NSInteger count = 5;
  265. CGFloat width = randLiveBgV.mj_w / count;
  266. for (NSInteger i = 0; i < count; i ++) {
  267. if (i >= self.youpaipgetRandLives.count) {
  268. break;
  269. }
  270. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  271. btn.frame = CGRectMake(i * width, CGRectGetMaxY(titleL.frame) + 9.0f, width, 90.0f);
  272. btn.tag = i;
  273. [btn addTarget:self action:@selector(youpaifgetRandLiveClick:) forControlEvents:UIControlEventTouchUpInside];
  274. [randLiveBgV addSubview:btn];
  275. YYAnimatedImageView *youpaipbgImgV = [[YYAnimatedImageView alloc] initWithFrame:CGRectMake((btn.mj_w - 59.0f) / 2.0f, 0.0f, 59.0f, 59.0f)];
  276. youpaipbgImgV.image = self.youpaipicLiveUserHeader;
  277. youpaipbgImgV.contentMode = UIViewContentModeScaleAspectFit;
  278. [btn addSubview:youpaipbgImgV];
  279. UIImageView *youpaipavatarImgV = [[UIImageView alloc] initWithFrame:CGRectMake((youpaipbgImgV.mj_w - 44.0f)/ 2.0f, (youpaipbgImgV.mj_h - 44.0f)/ 2.0f, 44.0f, 44.0f)];
  280. youpaipavatarImgV.layer.cornerRadius = youpaipavatarImgV.mj_w / 2.0f;
  281. youpaipavatarImgV.clipsToBounds = YES;
  282. youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  283. [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipgetRandLives[i].youpaipcover_img]];
  284. [youpaipbgImgV addSubview:youpaipavatarImgV];
  285. UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(5.0f, CGRectGetMaxY(youpaipbgImgV.frame) + 2.0f, btn.mj_w - 10.0f, 15.0f)];
  286. nameL.text = self.youpaipgetRandLives[i].youpaipanchor_name;
  287. nameL.textColor = HexColorFromRGB(0x333333);
  288. nameL.font = LCFont(11.0f);
  289. nameL.textAlignment = NSTextAlignmentCenter;
  290. [btn addSubview:nameL];
  291. }
  292. }
  293. return headerView;
  294. }
  295. #pragma mark - SDCycleScrollViewDelegate
  296. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
  297. {
  298. YOUPAILCBannerModel* model = self.youpaipbannerArray[index];
  299. if (model.youpaiplink_type==1) {
  300. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  301. baseWeb.contentUrl = model.youpaiplink_url;
  302. [self.navigationController pushViewController:baseWeb animated:YES];
  303. }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
  304. [self youpaifpageToStr:model.youpaiplink_url];
  305. }
  306. }
  307. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  308. // if (scrollView == self.collectionView && [self.scrollDelegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
  309. // [self.scrollDelegate scrollViewDidScroll:scrollView];
  310. // }
  311. //}
  312. - (UICollectionView *)youpaipcollectionView{
  313. if (!_youpaipcollectionView) {
  314. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  315. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  316. flowLayout.minimumLineSpacing = 1.0f;
  317. flowLayout.minimumInteritemSpacing = 1.0f;
  318. flowLayout.sectionInset = UIEdgeInsetsMake(1.0f, 0.0f, 1.0f, 0.0f);
  319. SEL sel = NSSelectorFromString(@"_setRowAlignmentsOptions:");
  320. if ([flowLayout respondsToSelector:sel]) {
  321. ((void(*)(id,SEL,NSDictionary*)) objc_msgSend)(flowLayout,sel, @{@"UIFlowLayoutCommonRowHorizontalAlignmentKey":@(NSTextAlignmentLeft),@"UIFlowLayoutLastRowHorizontalAlignmentKey" : @(NSTextAlignmentLeft),@"UIFlowLayoutRowVerticalAlignmentKey" : @(NSTextAlignmentCenter)});
  322. }
  323. _youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  324. _youpaipcollectionView.delegate = self;
  325. _youpaipcollectionView.dataSource = self;
  326. _youpaipcollectionView.backgroundColor = LCBkgColor;
  327. [_youpaipcollectionView registerClass:[YOUPAILZLiveItemCell class] forCellWithReuseIdentifier:@"YOUPAILZLiveItemCell"];
  328. [_youpaipcollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
  329. _youpaipcollectionView.showsHorizontalScrollIndicator = NO;
  330. _youpaipcollectionView.showsVerticalScrollIndicator = NO;
  331. _youpaipcollectionView.mj_header = [LCRefreshDotGiftHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  332. }
  333. return _youpaipcollectionView;
  334. }
  335. - (NSMutableArray<YOUPAILZLiveListItemModel *> *)youpaipdataSource{
  336. if (!_youpaipdataSource) {
  337. _youpaipdataSource = [NSMutableArray array];
  338. }
  339. return _youpaipdataSource;
  340. }
  341. #pragma mark - request data
  342. - (void)youpaifloadNewData{
  343. if(self.youpaiptype == 3 || self.youpaiptype == 4){ // 摘星站banner
  344. [self youpaifrequestBannerData];
  345. }
  346. if (self.youpaiptype == 4) { // 新秀banner 新秀顶部推荐
  347. [self youpaifrequestBannerData];
  348. [self youpaifrequestGetRandLive];
  349. }
  350. self.youpaipcollectionView.mj_footer.hidden = YES;
  351. [self.youpaipcollectionView.mj_footer endRefreshing];//先结束上拉,假如有的话
  352. [self.youpaipcollectionView.mj_footer endRefreshingWithNoMoreData];
  353. self.youpaipcollectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  354. self.youpaipcurrentPage = 1;
  355. WeakSelf;
  356. [LCHttpHelper requestWithURLString:GetLiveListByCate parameters:@{@"page":@(self.youpaipcurrentPage),@"cate_id":@(self.youpaiptype)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  357. NSDictionary* dict = (NSDictionary*)responseObject;
  358. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  359. if (code==0) {//成功
  360. [weakSelf.youpaipdataSource removeAllObjects];
  361. weakSelf.youpaipdataSource = [YOUPAILZLiveListItemModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"list"]];
  362. weakSelf.youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
  363. NSInteger currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"] integerValue];
  364. weakSelf.youpaipcurrentPage = currentPage;
  365. [weakSelf.youpaipcollectionView reloadData];
  366. // if (weakSelf.type == 1 && weakSelf.dataSource.count != 0) { // 只有推荐才初始化声网SDK
  367. // weakSelf.youpaipliveItemModel = weakSelf.dataSource[0];
  368. // [weakSelf youpaifjoin];
  369. // }
  370. [weakSelf.youpaipcollectionView lz_hideEmptyView];
  371. if (weakSelf.youpaipdataSource.count == 0) {
  372. NSString *des = [[[dict objectForKey:@"data"] objectForKey:@"des"] objectForKey:@"des"];
  373. NSURL *imgURL = [LCTools getImageUrlWithAddress:[[[dict objectForKey:@"data"] objectForKey:@"des"] objectForKey:@"img"]];
  374. [weakSelf.youpaipcollectionView lz_showEmptyViewWithUrl:imgURL content:des];
  375. }
  376. if (currentPage >= weakSelf.youpaiptotalPage) {
  377. [weakSelf.youpaipcollectionView.mj_footer endRefreshingWithNoMoreData];
  378. weakSelf.youpaipcollectionView.mj_footer.hidden = YES;
  379. }
  380. [weakSelf.youpaipcollectionView.mj_header endRefreshing];
  381. }else{
  382. [weakSelf.youpaipcollectionView.mj_header endRefreshing];
  383. }
  384. } failure:^(NSError *error) {
  385. [weakSelf.youpaipcollectionView.mj_header endRefreshing];
  386. }];
  387. }
  388. - (void)youpaifloadMoreData{
  389. //先结束下拉 假如有的话
  390. [self.youpaipcollectionView.mj_header endRefreshing];
  391. WeakSelf;
  392. [LCHttpHelper requestWithURLString:GetLiveListByCate parameters:@{@"page":@(self.youpaipcurrentPage+1),@"cate_id":@(self.youpaiptype)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  393. NSDictionary* dict = (NSDictionary*)responseObject;
  394. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  395. if (code==0) {//成功
  396. NSMutableArray* modelArray = [YOUPAILZLiveListItemModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
  397. [weakSelf.youpaipdataSource addObjectsFromArray:modelArray];
  398. weakSelf.youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
  399. NSInteger currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"] integerValue];
  400. weakSelf.youpaipcurrentPage = currentPage;
  401. [weakSelf.youpaipcollectionView reloadData];
  402. if (currentPage>=weakSelf.youpaiptotalPage) {
  403. [weakSelf.youpaipcollectionView.mj_footer endRefreshingWithNoMoreData];
  404. weakSelf.youpaipcollectionView.mj_footer.hidden = YES;
  405. }
  406. [weakSelf.youpaipcollectionView.mj_header endRefreshing];
  407. }
  408. [weakSelf.youpaipcollectionView.mj_footer endRefreshing];
  409. } failure:^(NSError *error) {
  410. [weakSelf.youpaipcollectionView.mj_footer endRefreshing];
  411. }];
  412. }
  413. //获取banner
  414. - (void)youpaifrequestBannerData{
  415. NSString *cate_id = @"2";
  416. if (self.youpaiptype == 3) {
  417. cate_id = @"3";
  418. }
  419. WeakSelf;
  420. [LCHttpHelper requestWithURLString:HomeBanner parameters:@{@"cate_id":cate_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  421. NSDictionary* dict = (NSDictionary*)responseObject;
  422. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  423. if (code==0) {//成功
  424. weakSelf.youpaipbannerArray = [YOUPAILCBannerModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"banner"]];
  425. [weakSelf.youpaipcollectionView reloadData];
  426. }
  427. } failure:^(NSError *error) {
  428. }];
  429. }
  430. //获取新秀推荐
  431. - (void)youpaifrequestGetRandLive{
  432. WeakSelf;
  433. [LCHttpHelper requestWithURLString:GetRandLive parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  434. NSDictionary* dict = (NSDictionary*)responseObject;
  435. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  436. if (code==0) {//成功
  437. weakSelf.youpaipgetRandLives = [YOUPAILZLiveListItemModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  438. [weakSelf.youpaipcollectionView reloadData];
  439. }
  440. } failure:^(NSError *error) {
  441. }];
  442. }
  443. // 观众加入直播间
  444. - (void)youpaifjoinLiveWithRoomId:(NSString *)roomId is_comein_room_hide:(NSInteger)is_comein_room_hide{
  445. [ZCHUDHelper showWithStatus:nil];
  446. WeakSelf;
  447. [LCHttpHelper requestWithURLString:JoinLive parameters:@{@"room_id":roomId,@"is_comein_room_hide":@(is_comein_room_hide)} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  448. NSDictionary* dict = (NSDictionary*)responseObject;
  449. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  450. if (code == 0) {
  451. [ZCHUDHelper dismiss];
  452. [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
  453. YOUPAILZLiveModel *youpaipliveModel = [YOUPAILZLiveModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  454. if(youpaipliveModel.youpaiptype == 0){
  455. YOUPAILZEndLiveHintModel *model1 = [YOUPAILZEndLiveHintModel mj_objectWithKeyValues:dict[@"data"][@"user_info"]];
  456. YOUPAILZEndLiveHintView *view = [[YOUPAILZEndLiveHintView alloc]initWithFrame:CGRectZero Model:model1];
  457. }else{
  458. [ZCHUDHelper dismiss];
  459. [LCSaveData saveLiveRankTopThere:youpaipliveModel.youpaiprank_top_three];
  460. YOUPAILZLiveAudienceVC *audienceVC = [[YOUPAILZLiveAudienceVC alloc] initWithModel:youpaipliveModel];
  461. [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:youpaipliveModel.youpaiplive_id];
  462. [weakSelf.navigationController pushViewController:audienceVC animated:NO];
  463. }
  464. }else{
  465. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  466. }
  467. } failure:^(NSError *error) {
  468. [ZCHUDHelper showTitle:error.localizedDescription];
  469. }];
  470. }
  471. //
  472. //- (void)viewWillLayoutSubviews{
  473. // [super viewWillLayoutSubviews];
  474. // [UIView animateWithDuration:0.25f animations:^{
  475. // self.collectionView.frame = self.view.bounds;
  476. // }];
  477. //}
  478. - (YYImage *)icLiveZhibozhong28{
  479. if (!_icLiveZhibozhong28) {
  480. NSString *path = [[NSBundle mainBundle] pathForResource:@"ic_live_zhibozhong_28" ofType:@"gif"];
  481. _icLiveZhibozhong28 = [YYImage imageWithData:[NSData dataWithContentsOfFile:path]];
  482. }
  483. return _icLiveZhibozhong28;
  484. }
  485. - (YYImage *)icLiveZhibozhong38{
  486. if (!_icLiveZhibozhong38) {
  487. NSString *path = [[NSBundle mainBundle] pathForResource:@"ic_live_zhibozhong_38" ofType:@"gif"];
  488. _icLiveZhibozhong38 = [YYImage imageWithData:[NSData dataWithContentsOfFile:path]];
  489. }
  490. return _icLiveZhibozhong38;
  491. }
  492. - (YYImage *)youpaipicLiveUserHeader{
  493. if (!_youpaipicLiveUserHeader) {
  494. NSString *path = [[NSBundle mainBundle] pathForResource:@"ic_live_header" ofType:@"gif"];
  495. _youpaipicLiveUserHeader = [YYImage imageWithData:[NSData dataWithContentsOfFile:path]];
  496. }
  497. return _youpaipicLiveUserHeader;
  498. }
  499. #pragma mark - JXPagingViewListViewDelegate
  500. - (UIView *)listView{
  501. return self.view;
  502. }
  503. - (UIScrollView *)listScrollView{
  504. return self.youpaipcollectionView;
  505. }
  506. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  507. self.scrollCallback = callback;
  508. }
  509. @end