TCShowLiveTopView.m 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. //
  2. // TCShowLiveTopView.m
  3. // TCShow
  4. //
  5. // Created by AlexiChen on 16/4/14.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "TCShowLiveTopView.h"
  9. #pragma mark - ----------------------- 内部类 TCShowLiveTimeView -----------------------
  10. @implementation TCShowLiveTimeView
  11. {
  12. }
  13. - (void)dealloc
  14. {
  15. NSLog(@"11");
  16. }
  17. #pragma mark 初始化房间信息等
  18. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem liveController:(id<FWLiveControllerAble>)liveController
  19. {
  20. if (self = [super initWithFrame:CGRectZero])
  21. {
  22. _liveItem = liveItem;
  23. _isHost = [liveItem isHost];
  24. [self addOwnViews];
  25. [self configOwnViews];
  26. self.backgroundColor = UIColor.clearColor;
  27. // self.layer.cornerRadius = kLogoContainerViewHeight/2;
  28. // self.layer.masksToBounds = YES;
  29. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onPKViewChange:) name:@"onPKViewChange" object:nil];
  30. }
  31. return self;
  32. }
  33. #pragma mark 请求完接口后,刷新直播间相关信息
  34. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  35. {
  36. _liveItem = liveItem;
  37. _isHost = [liveItem isHost];
  38. _roomId.text = [NSString stringWithFormat:@"ID:%@",liveInfo.room_id];
  39. [self setHostVIcon:liveInfo];
  40. }
  41. - (void)addOwnViews
  42. {
  43. UIImageView * bgImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 3, 181, 44)];
  44. bgImgV.image = [UIImage imageNamed:@"voiceroomtopbg"];
  45. bgImgV.contentMode = UIViewContentModeScaleToFill;
  46. [self addSubview:bgImgV];
  47. _hostHeadBtn = [[MenuButton alloc] init];
  48. _hostHeadBtn.layer.masksToBounds = YES;
  49. [self addSubview:_hostHeadBtn];
  50. _hostVImgView = [[UIImageView alloc]init];
  51. [self addSubview:_hostVImgView];
  52. _liveTitle = [[UILabel alloc] init];
  53. _liveTitle.userInteractionEnabled = YES;
  54. _liveTitle.font = kAppSmallerTextFont;
  55. _liveTitle.textAlignment = NSTextAlignmentCenter;
  56. _liveTitle.textColor = kWhiteColor;
  57. _liveTitle.text = ASLocalizedString(@"加载中...");
  58. [self addSubview:_liveTitle];
  59. _liveAudience = [[UILabel alloc] init];
  60. _liveAudience.userInteractionEnabled = YES;
  61. _liveAudience.font = kAppSmallerTextFont;
  62. _liveAudience.textAlignment = NSTextAlignmentCenter;
  63. _liveAudience.textColor = UIColor.whiteColor;
  64. _liveAudience.text = @"0";
  65. _liveAudience.hidden = YES;
  66. [self addSubview:_liveAudience];
  67. _roomId = [[UILabel alloc] init];
  68. _roomId.userInteractionEnabled = YES;
  69. _roomId.font = kAppSmallerTextFont;
  70. _roomId.textAlignment = NSTextAlignmentCenter;
  71. _roomId.textColor = kWhiteColor;
  72. _roomId.text = @"";
  73. [self addSubview:_roomId];
  74. _liveFollow = [[UIButton alloc] init];
  75. // _liveFollow.titleLabel.font = kAppSmallerTextFont;
  76. // _liveFollow.backgroundColor = RGB(118, 59, 243);
  77. // [_liveFollow setTitleColor:kWhiteColor forState:UIControlStateNormal];
  78. // [_liveFollow setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  79. [_liveFollow setImage:[UIImage imageNamed:@"bogo_live_topUser_concert"] forState:UIControlStateNormal];
  80. // _liveFollow.layer.masksToBounds = YES;
  81. [self addSubview:_liveFollow];
  82. }
  83. #pragma mark 设置主播认证图标
  84. - (void)setHostVIcon:(CurrentLiveInfo *)currentLiveInfo
  85. {
  86. if ([currentLiveInfo.podcast.user.is_authentication intValue] == 2)
  87. {
  88. NSString *vIcon = currentLiveInfo.podcast.user.v_icon;
  89. _hostVImgView.hidden = YES;
  90. // if (vIcon && ![vIcon isEqualToString:@""])
  91. // {
  92. // _hostVImgView.hidden = NO;
  93. // _hostVImgView.backgroundColor = kRedColor;
  94. // [_hostVImgView sd_setImageWithURL:[NSURL URLWithString:vIcon]];
  95. // }
  96. // else
  97. // {
  98. // _hostVImgView.hidden = YES;
  99. // }
  100. }
  101. }
  102. - (void)configOwnViews
  103. {
  104. NSString *url = [[_liveItem liveHost] imUserIconUrl];
  105. [_hostHeadBtn sd_setImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  106. }
  107. - (void)relayoutFrameOfSubViews
  108. {
  109. _hostHeadBtn.frame = CGRectMake(10, 7, kLogoContainerViewHeight, kLogoContainerViewHeight);
  110. _hostHeadBtn.layer.cornerRadius = _hostHeadBtn.frame.size.width/2;
  111. _hostVImgView.frame = CGRectMake(CGRectGetMaxX(_hostHeadBtn.frame)-kViconWidthOrHeight, CGRectGetMaxY(_hostHeadBtn.frame)-kViconWidthOrHeight, kViconWidthOrHeight, kViconWidthOrHeight);
  112. _liveTitle.frame = CGRectMake(kLogoContainerViewHeight + 10, 8, kLiveStatusViewWidth, kLogoContainerViewHeight/2);
  113. _liveAudience.frame = CGRectMake(CGRectGetMaxX(_hostHeadBtn.frame), self.frame.size.height-kLogoContainerViewHeight/2, kLiveStatusViewWidth, kLogoContainerViewHeight/2);
  114. _roomId.frame = CGRectMake(_liveTitle.left, _liveTitle.bottom + 7, kLiveStatusViewWidth, kLogoContainerViewHeight/2);
  115. _liveFollow.frame = CGRectMake(181 - 44, (self.frame.size.height-44)/2, 44, 44);
  116. // _liveFollow.layer.cornerRadius = 11;
  117. // _liveFollow.layer.cornerRadius = _liveFollow.frame.size.height/2;
  118. }
  119. - (void)onImUsersEnterLive
  120. {
  121. NSString *audience = _liveAudience.text;
  122. if (audience && ![audience isEqualToString:@""])
  123. {
  124. audience = StringFromInt([audience intValue]+1);
  125. }
  126. else
  127. {
  128. audience = @"1";
  129. }
  130. _liveAudience.text = audience;
  131. }
  132. - (void)onImUsersExitLive
  133. {
  134. NSString *audience = _liveAudience.text;
  135. if (audience && ![audience isEqualToString:@""] && [audience intValue])
  136. {
  137. audience = StringFromInt([audience intValue]-1);
  138. }
  139. else
  140. {
  141. audience = @"0";
  142. }
  143. _liveAudience.text = audience;
  144. }
  145. @end
  146. #pragma mark - ----------------------- 内部类 LiveUserViewCell -----------------------
  147. @interface LiveUserViewCell : UICollectionViewCell
  148. {
  149. MenuButton *_userIcon;
  150. UIImageView *_vImgView;
  151. }
  152. @property (nonatomic, readonly) MenuButton *userIcon;
  153. @property (nonatomic, readonly) UIImageView *vImgView;//守护图标
  154. @property(nonatomic, strong) UIImageView *nobleImgView;
  155. @property(nonatomic, strong) UILabel *titleL;
  156. @property(nonatomic, assign) NSInteger indexRow;
  157. @end
  158. @implementation LiveUserViewCell
  159. - (instancetype)initWithFrame:(CGRect)frame
  160. {
  161. if (self = [super initWithFrame:frame])
  162. {
  163. _userIcon = [[MenuButton alloc] init];
  164. _userIcon.clipsToBounds = YES;
  165. _userIcon.backgroundColor = [UIColor clearColor];
  166. _userIcon.layer.cornerRadius = kLogoContainerViewHeight/2;
  167. _userIcon.layer.masksToBounds = YES;
  168. _userIcon.userInteractionEnabled = YES;
  169. [self.contentView addSubview:_userIcon];
  170. _nobleImgView = [[UIImageView alloc]initWithFrame:CGRectMake(-5, -2.5, kLogoContainerViewHeight + 2.5, kLogoContainerViewHeight + 2.5)];
  171. // _nobleImgView.layer.cornerRadius = kViconWidthOrHeight/2;
  172. // _nobleImgView.layer.masksToBounds = YES;
  173. _nobleImgView.image = [UIImage imageNamed:@"bogo_noble_live_headIcon"];
  174. [self.contentView addSubview:_nobleImgView];
  175. _vImgView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-kViconWidthOrHeight, frame.size.height-kViconWidthOrHeight, kViconWidthOrHeight, kViconWidthOrHeight)];
  176. _vImgView.layer.cornerRadius = kViconWidthOrHeight/2;
  177. _vImgView.layer.masksToBounds = YES;
  178. _vImgView.image = [UIImage imageNamed:@""];
  179. [self.contentView addSubview:_vImgView];
  180. _titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kLogoContainerViewHeight, kRealValue(14))];
  181. _titleL.backgroundColor = [UIColor colorWithHexString:@"#C28CF8"];
  182. _titleL.textColor = kWhiteColor;
  183. _titleL.font = [UIFont systemFontOfSize:10];
  184. _titleL.textAlignment = NSTextAlignmentCenter;
  185. _titleL.layer.cornerRadius = kRealValue(14 / 2);
  186. _titleL.layer.masksToBounds = YES;
  187. _titleL.alpha = 0.8;
  188. [self.contentView addSubview:_titleL];
  189. }
  190. return self;
  191. }
  192. - (void)setIndexRow:(NSInteger)indexRow{
  193. _titleL.alpha = 0.8;
  194. if (indexRow == 0) {
  195. self.titleL.backgroundColor = [UIColor colorWithHexString:@"#C28CF8"];
  196. }else if (indexRow == 1){
  197. self.titleL.backgroundColor = [UIColor colorWithHexString:@"#8EC5FF"];
  198. }else if (indexRow == 2){
  199. self.titleL.backgroundColor = [UIColor colorWithHexString:@"#C39346"];
  200. }else{
  201. self.titleL.backgroundColor = [UIColor colorWithHexString:@"#000000"];
  202. _titleL.alpha = 0.4;
  203. }
  204. }
  205. - (void)layoutSubviews
  206. {
  207. [super layoutSubviews];
  208. CGRect rect = self.contentView.bounds;
  209. _userIcon.frame = CGRectMake(rect.origin.x + 2.5, rect.origin.y + 2.5, 30, 30);
  210. _nobleImgView.frame = CGRectMake(rect.origin.x, rect.origin.y, 34, 34);
  211. }
  212. @end
  213. #pragma mark - ----------------------- TCShowLiveTopView -----------------------
  214. @implementation TCShowLiveTopView
  215. {
  216. CAGradientLayer *gradientLayer;
  217. }
  218. #pragma mark - ----------------------- 直播生命周期 -----------------------
  219. - (void)releaseAll
  220. {
  221. [[NSNotificationCenter defaultCenter] removeObserver:self];
  222. if (_liveRateTimer)
  223. {
  224. [_liveRateTimer invalidate];
  225. _liveRateTimer = nil;
  226. }
  227. _liveItem = nil;
  228. _timeView.liveItem = nil;
  229. }
  230. - (void)dealloc
  231. {
  232. [self releaseAll];
  233. }
  234. #pragma mark 开始直播
  235. - (void)startLive
  236. {
  237. }
  238. #pragma mark 暂停直播
  239. - (void)pauseLive
  240. {
  241. if (_liveRateTimer)
  242. {
  243. [_liveRateTimer invalidate];
  244. _liveRateTimer = nil;
  245. }
  246. }
  247. #pragma mark 重新开始直播
  248. - (void)resumeLive
  249. {
  250. [self monitorRateKBPS];
  251. }
  252. #pragma mark 结束直播
  253. - (void)endLive
  254. {
  255. [self releaseAll];
  256. }
  257. #pragma mark 初始化房间信息等
  258. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem liveController:(id<FWLiveControllerAble>)liveController
  259. {
  260. if (self = [super initWithFrame:CGRectZero])
  261. {
  262. _liveItem = liveItem;
  263. _isHost = [liveItem isHost];
  264. _groupIdStr = StringFromInt([_liveItem liveAVRoomId]);
  265. _httpManager = [NetHttpsManager manager];
  266. _userArray = [NSMutableArray array];
  267. // self.layer.borderColor = UIColor.redColor.CGColor;
  268. // self.layer.borderWidth = 1;
  269. _timeView = [[TCShowLiveTimeView alloc] initWith:liveItem liveController:liveController];
  270. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onPKViewChange:) name:@"onPKViewChange" object:nil];
  271. [self addOwnViewsWith:_liveItem];
  272. [self monitorRateKBPS];
  273. [self requestWardData];
  274. }
  275. return self;
  276. }
  277. - (void)requestWardData{
  278. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  279. [dict setValue:@"guardians_old" forKey:@"ctl"];
  280. [dict setValue:@"index" forKey:@"act"];
  281. [dict setValue:_liveItem.liveHost.imUserId forKey:@"host_id"];
  282. [_httpManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  283. NSLog(@"104responseJson%@",responseJson);
  284. if ([responseJson toInt:@"status"] == 1) {
  285. //守护数量
  286. NSString *guardian_sum = responseJson[@"guardian_sum"];
  287. self.wardJson = responseJson;
  288. if (guardian_sum.integerValue == 0) {
  289. self.wardNumLabel.text = ASLocalizedString(@"守护 : 虚席以待");
  290. }else{
  291. self.wardNumLabel.text = [NSString stringWithFormat:ASLocalizedString(@"守护 : %@人"),guardian_sum];
  292. }
  293. // NSString *is_guartian = responseJson[@"is_guartian"];
  294. // [GlobalVariables sharedInstance].is_guartian = [NSString stringWithFormat:@"%@",is_guartian];
  295. [self relayoutOtherContainerViewFrame];
  296. }else{
  297. //接口请求失败
  298. NSLog(ASLocalizedString(@"守护列表请求数据失败responseJson:%@"),responseJson);
  299. }
  300. } FailureBlock:^(NSError *error) {
  301. NSLog(ASLocalizedString(@"守护列表请求数据失败error:%@"),error);
  302. }];
  303. }
  304. //该参数就是发送过来的通知,接到通知后执行的方法
  305. - (void)onPKViewChange:(NSNotification *)notify
  306. {
  307. int isFull = [[notify.userInfo valueForKey:@"isFull"] intValue];
  308. if(isFull == 1)
  309. {
  310. _otherContainerView.hidden = NO;
  311. _collectionView.hidden = NO;
  312. // _liveGuard.hidden = NO;
  313. }
  314. else
  315. {
  316. _otherContainerView.hidden = NO;
  317. _collectionView.hidden = NO;
  318. // _liveGuard.hidden = YES;
  319. }
  320. }
  321. #pragma mark 请求完接口后,刷新直播间相关信息
  322. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  323. {
  324. _liveItem = liveItem;
  325. _isHost = [liveItem isHost];
  326. _groupIdStr = [_liveItem liveIMChatRoomId];
  327. _is_private = liveInfo.is_private;
  328. _has_admin = (int)liveInfo.podcast.has_admin;
  329. [_timeView refreshLiveItem:_liveItem liveInfo:liveInfo];
  330. float ticket = liveInfo.podcast.user.ticket.floatValue;
  331. if (ticket > 1000) {
  332. _ticketNumLabel.text = [NSString stringWithFormat:@"%.1fK",floorf(ticket/1000)];
  333. }else{
  334. _ticketNumLabel.text = [NSString stringWithFormat:@"%.0f",ticket];
  335. }
  336. if (![BGUtils isBlankString:liveInfo.video_title])
  337. {
  338. _timeView.liveTitle.text = liveInfo.podcast.user.nick_name;
  339. }
  340. else
  341. {
  342. _timeView.liveTitle.text = ASLocalizedString(@"直播Live");
  343. }
  344. // // 当前直播间是否在竞拍
  345. // if (liveInfo.pai_id == 0)
  346. // {
  347. // self.accountLabel.hidden = NO;
  348. // }
  349. if ([liveInfo.luck_num intValue] > 1)
  350. {
  351. _accountLabel.text = [NSString stringWithFormat:@"%@:%@",[GlobalVariables sharedInstance].appModel.account_name,liveInfo.luck_num];
  352. }
  353. else
  354. {
  355. if (liveInfo.user_id.length > 1)
  356. {
  357. _accountLabel.text = [NSString stringWithFormat:@"%@:%@",[GlobalVariables sharedInstance].appModel.account_name,liveInfo.user_id];
  358. }
  359. }
  360. [_timeView.hostHeadBtn sd_setImageWithURL:[NSURL URLWithString:liveInfo.podcast.user.head_image] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  361. // _timeView.hostHeadBtn.backgroundColor = kBlueColor;
  362. if (!_isHost && liveInfo.podcast.has_focus == 0 && ![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  363. {
  364. _isShowFollowBtn = YES;
  365. }
  366. [self relayoutOtherContainerViewFrame];
  367. [self relayoutFrameOfSubViews];
  368. [self.collectionView reloadData];
  369. }
  370. #pragma mark - ----------------------- 观众进、退操作 -----------------------
  371. #pragma mark 首次获取观众列表
  372. - (void)refreshAudienceList:(NSDictionary *)responseJson
  373. {
  374. NSArray *array = [[responseJson objectForKey:@"viewer"] objectForKey:@"list"];
  375. if (array && [array isKindOfClass:[NSArray class]])
  376. {
  377. if ([array count])
  378. {
  379. // NSMutableArray* userArray = [NSMutableArray array];
  380. // for (NSDictionary *dict in array)
  381. // {
  382. // if (![[dict toString:@"user_id"] isEqualToString:[[_liveItem liveHost] imUserId]])
  383. // {
  384. // UserModel *audience = [UserModel mj_objectWithKeyValues:dict];
  385. // [userArray addObject:audience];
  386. // }
  387. // }
  388. // _userArray = userArray;
  389. }
  390. }
  391. CurrentLiveInfo *info = [CurrentLiveInfo mj_objectWithKeyValues:responseJson];
  392. _numRightTitleL.text = [NSString stringWithFormat:@" %@",info.total_num];
  393. FWWeakify(self)
  394. [UIView animateWithDuration:0 animations:^{
  395. FWStrongify(self)
  396. [self.collectionView reloadData];
  397. }];
  398. [self performSelector:@selector(setupLiveAudience:) withObject:[[responseJson objectForKey:@"viewer"] toString:@"watch_number"] afterDelay:0.3];
  399. }
  400. #pragma mark 初始化观众数量、列表
  401. - (void)setupLiveAudience:(NSString *)watch_number
  402. {
  403. if (![BGUtils isBlankString:watch_number])
  404. {
  405. if ([watch_number intValue] >= [_collectionView numberOfItemsInSection:0])
  406. {
  407. [_timeView.liveAudience setText:watch_number];
  408. [_numRightTitleL setText:watch_number];
  409. }
  410. else
  411. {
  412. int numCount;
  413. if (_is_private)
  414. {
  415. numCount = (int)([_collectionView numberOfItemsInSection:0]-2);
  416. }
  417. else
  418. {
  419. numCount = (int)[_collectionView numberOfItemsInSection:0];
  420. [_timeView.liveAudience setText:StringFromInt(numCount)];
  421. }
  422. }
  423. }
  424. else
  425. {
  426. if ([_collectionView numberOfItemsInSection:0])
  427. {
  428. int numCount;
  429. if (_is_private)
  430. {
  431. numCount = (int)([_collectionView numberOfItemsInSection:0]-2);
  432. }
  433. else
  434. {
  435. numCount = (int)[_collectionView numberOfItemsInSection:0];
  436. [_timeView.liveAudience setText:StringFromInt(numCount)];
  437. }
  438. }
  439. else
  440. {
  441. _timeView.liveAudience.text = @"0";
  442. }
  443. }
  444. }
  445. #pragma mark 刷新观众列表
  446. - (void)refreshLiveAudienceList:(CustomMessageModel *)customMessageModel
  447. {
  448. if (customMessageModel.data && [customMessageModel.data isKindOfClass:[NSDictionary class]])
  449. {
  450. // 当 data_type == 1,主播、所有连麦观众收到的定时连麦消息
  451. if (customMessageModel.data_type == 0)
  452. {
  453. if ([GlobalVariables sharedInstance].refreshAudienceListTime < [[customMessageModel.data objectForKey:@"time"] longValue])
  454. {
  455. [GlobalVariables sharedInstance].refreshAudienceListTime = [[customMessageModel.data objectForKey:@"time"] longValue];
  456. NSArray *keyArray = [customMessageModel.data objectForKey:@"list_fields"];
  457. NSArray *valueAllArray = [customMessageModel.data objectForKey:@"list_data"];
  458. if (keyArray && [keyArray isKindOfClass:[NSArray class]] && valueAllArray && [valueAllArray isKindOfClass:[NSArray class]])
  459. {
  460. // [_userArray removeAllObjects]; // 清空头像的数组
  461. // if ([keyArray count] && [valueAllArray count])
  462. // {
  463. // NSMutableArray* userArray = [NSMutableArray array];
  464. // for (NSArray *valueArray in valueAllArray)
  465. // {
  466. // NSString *user_id;
  467. // if ([keyArray containsObject:@"user_id"])
  468. // {
  469. // user_id = [valueArray objectAtIndex:[keyArray indexOfObject:@"user_id"]];
  470. // }
  471. //
  472. // if (user_id)
  473. // {
  474. // if (![user_id isEqualToString:[[_liveItem liveHost] imUserId]])
  475. // {
  476. // UserModel *userModel = [[UserModel alloc] init];
  477. // userModel.user_id = user_id;
  478. //
  479. // if ([keyArray containsObject:@"user_level"])
  480. // {
  481. // userModel.user_level = [valueArray objectAtIndex:[keyArray indexOfObject:@"user_level"]];
  482. // }
  483. //
  484. // if ([keyArray containsObject:@"head_image"])
  485. // {
  486. // NSString *headStr = [valueArray objectAtIndex:[keyArray indexOfObject:@"head_image"]];
  487. // if (![BGUtils isBlankString:headStr])
  488. // {
  489. // if ([headStr hasPrefix:@"http://"] || [headStr hasPrefix:@"https://"])
  490. // {
  491. // userModel.head_image = headStr;
  492. // }
  493. // else
  494. // {
  495. // userModel.head_image = [NSString stringWithFormat:@"%@%@",[customMessageModel.data objectForKey:@"short_url"],headStr];
  496. // }
  497. // }
  498. // }
  499. //
  500. // if ([keyArray containsObject:@"v_icon"])
  501. // {
  502. // NSString *iconStr = [valueArray objectAtIndex:[keyArray indexOfObject:@"v_icon"]];
  503. // if (![BGUtils isBlankString:iconStr])
  504. // {
  505. // if ([iconStr hasPrefix:@"http://"] || [iconStr hasPrefix:@"https://"])
  506. // {
  507. // userModel.v_icon = iconStr;
  508. // }
  509. // else
  510. // {
  511. // userModel.v_icon = [NSString stringWithFormat:@"%@%@",[customMessageModel.data objectForKey:@"short_url"],iconStr];
  512. // }
  513. // }
  514. // }
  515. //
  516. // if ([keyArray containsObject:@"is_authentication"])
  517. // {
  518. // userModel.is_authentication = [valueArray objectAtIndex:[keyArray indexOfObject:@"is_authentication"]];
  519. // }
  520. //
  521. // [userArray addObject:userModel];
  522. // }
  523. // }
  524. // }
  525. // _userArray = userArray;
  526. // }
  527. FWWeakify(self)
  528. [UIView animateWithDuration:0 animations:^{
  529. FWStrongify(self)
  530. [self.collectionView reloadData];
  531. }];
  532. [self performSelector:@selector(setupLiveAudience:) withObject:[customMessageModel.data toString:@"watch_number"] afterDelay:0.3];
  533. }
  534. }
  535. }
  536. }
  537. }
  538. - (UserModel *)getUserOf:(NSString *)sender
  539. {
  540. if (sender.length)
  541. {
  542. for(UserModel *user in _userArray)
  543. {
  544. if([user.user_id isEqualToString:sender])
  545. {
  546. return user;
  547. }
  548. }
  549. }
  550. return nil;
  551. }
  552. #pragma mark 观众进入直播间
  553. - (void)onImUsersEnterLive:(UserModel *)userModel
  554. {
  555. [_timeView onImUsersEnterLive];
  556. // if (userModel)
  557. // {
  558. // [self addUsers:userModel];
  559. // }
  560. _groupIdStr = [_liveItem liveIMChatRoomId];
  561. [self refreshAudienceWithRoomID:_groupIdStr];
  562. }
  563. #pragma mark 添加用户
  564. - (void)addUsers:(UserModel *)lu
  565. {
  566. if (lu)
  567. {
  568. // @synchronized(_userArray)
  569. // {
  570. UserModel *liu = [self getUserOf:lu.user_id];
  571. if (liu)
  572. {
  573. @try {
  574. NSInteger tmpIndex = [_userArray indexOfObject:liu];
  575. if (tmpIndex <= [_userArray count])
  576. {
  577. [_userArray replaceObjectAtIndex:tmpIndex withObject:lu];
  578. }
  579. } @catch (NSException *exception) {
  580. } @finally {
  581. }
  582. [UIView animateWithDuration:0 animations:^{
  583. [_collectionView reloadData];
  584. }];
  585. }
  586. else
  587. {
  588. if (_userArray)
  589. {
  590. NSInteger tmpIndex = 0;
  591. NSInteger user_level = 0;
  592. if ([lu.sort_num intValue])
  593. {
  594. user_level = [lu.sort_num intValue];
  595. }
  596. else
  597. {
  598. user_level = [lu.user_level intValue];
  599. }
  600. for (NSInteger i=0; i<[_userArray count]; i++) {
  601. UserModel *um = [_userArray objectAtIndex:i];
  602. if (user_level >= [um.user_level intValue])
  603. {
  604. tmpIndex = i;
  605. break;
  606. }
  607. else if (i == [_userArray count]-1)
  608. {
  609. tmpIndex = i;
  610. }
  611. }
  612. // @try {
  613. if (_userArray) {
  614. if (tmpIndex <= [_userArray count])
  615. {
  616. [_userArray insertObject:lu atIndex:tmpIndex];
  617. [UIView animateWithDuration:0 animations:^{
  618. [_collectionView reloadData];
  619. }];
  620. }
  621. }
  622. //
  623. // } @catch (NSException *exception) {
  624. //
  625. // } @finally {
  626. //
  627. // }
  628. }else{
  629. [_userArray addObject:lu];
  630. [UIView animateWithDuration:0 animations:^{
  631. [_collectionView reloadData];
  632. }];
  633. }
  634. }
  635. }
  636. // }
  637. }
  638. #pragma mark 观众退出直播间
  639. - (void)onImUsersExitLive:(UserModel *)userModel
  640. {
  641. [_timeView onImUsersExitLive];
  642. // if (userModel)
  643. // {
  644. // [self deleteUsers:userModel];
  645. // }
  646. _groupIdStr = [_liveItem liveIMChatRoomId];
  647. [self refreshAudienceWithRoomID:_groupIdStr];
  648. }
  649. #pragma mark 删除用户
  650. - (void)deleteUsers:(UserModel *)lu
  651. {
  652. if (lu)
  653. {
  654. @synchronized(_userArray)
  655. {
  656. UserModel *liu = [self getUserOf:lu.user_id];
  657. if (liu)
  658. {
  659. [_userArray removeObject:liu];
  660. [UIView animateWithDuration:0 animations:^{
  661. [_collectionView reloadData];
  662. }];
  663. }
  664. }
  665. }
  666. }
  667. -(void)refreshAudienceWithRoomID:(NSString *)roomID{
  668. roomID = StringFromInt([_liveItem liveAVRoomId]);
  669. NSMutableDictionary * parmDict = [NSMutableDictionary dictionary];
  670. [parmDict setObject:@"video" forKey:@"ctl"];
  671. [parmDict setObject:@"room_lists" forKey:@"act"];
  672. [parmDict setObject:SafeStr(roomID) forKey:@"room_id"];
  673. [parmDict setObject:@"1" forKey:@"page"];
  674. [[NetHttpsManager manager]POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  675. if ([[responseJson valueForKey:@"status"]integerValue] == 1) {
  676. [_userArray removeAllObjects];
  677. NSArray *listArr = [NSArray modelArrayWithClass:[UserModel class] json:[responseJson valueForKey:@"data"]];
  678. [_userArray addObjectsFromArray:listArr];
  679. [self.collectionView reloadData];
  680. }
  681. // UserModel *liu = [self getUserOf:lu.user_id];
  682. // if (liu)
  683. // {
  684. // [_userArray removeObject:liu];
  685. } FailureBlock:^(NSError *error) {
  686. }];
  687. }
  688. #pragma mark - ----------------------- 初始化界面 -----------------------
  689. - (void)addOwnViewsWith:(id<FWShowLiveRoomAble>)room
  690. {
  691. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  692. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  693. layout.itemSize = CGSizeMake(kLogoContainerViewHeight, kLogoContainerViewHeight + 5);
  694. layout.minimumLineSpacing = kDefaultMargin-2;
  695. _collectionView = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:layout];
  696. [_collectionView registerClass:[LiveUserViewCell class] forCellWithReuseIdentifier:@"LiveUserViewCell"];
  697. _collectionView.backgroundColor = [UIColor clearColor];
  698. _collectionView.dataSource =self;
  699. _collectionView.delegate = self;
  700. _collectionView.showsHorizontalScrollIndicator = NO;
  701. [self addSubview:_collectionView];
  702. _numRightImgView = [[UIImageView alloc]init];
  703. _numRightImgView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
  704. // _numRightImgView.image = [UIImage imageNamed:@"bogo_liveroom_TopNumBgImg"];
  705. _numRightImgView.contentMode = UIViewContentModeScaleToFill;
  706. [self addSubview:_numRightImgView];
  707. _numRightTitleL = [UILabel new];
  708. _numRightTitleL.font = [UIFont boldSystemFontOfSize:9];
  709. _numRightTitleL.text = @"";
  710. _numRightTitleL.textColor = kWhiteColor;
  711. _numRightSubTitleL = [UILabel new];
  712. _numRightSubTitleL.font = [UIFont boldSystemFontOfSize:11];
  713. _numRightSubTitleL.text = ASLocalizedString(@" 当前人气");
  714. _numRightSubTitleL.textColor = [UIColor colorWithWhite:1 alpha:0.8];
  715. [_numRightImgView addSubview:_numRightTitleL];
  716. [_numRightImgView addSubview:_numRightSubTitleL];
  717. @synchronized (_userArray)
  718. {
  719. [UIView animateWithDuration:0 animations:^{
  720. [_collectionView reloadData];
  721. }];
  722. }
  723. __weak TCShowLiveTopView *ws = self;
  724. [_timeView.hostHeadBtn setClickAction:^(id<MenuAbleItem> menu) {
  725. [ws clickLiveHost];
  726. }];
  727. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickLiveHost)];
  728. tap.numberOfTapsRequired = 1;
  729. tap.numberOfTouchesRequired = 1;
  730. [_timeView.liveTitle addGestureRecognizer:tap];
  731. UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickLiveHost)];
  732. tap2.numberOfTapsRequired = 1;
  733. tap2.numberOfTouchesRequired = 1;
  734. [_timeView.liveAudience addGestureRecognizer:tap2];
  735. if (![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[room liveHost] imUserId]]) {
  736. [_timeView.liveFollow addTarget:self action:@selector(followAction) forControlEvents:UIControlEventTouchUpInside];
  737. }
  738. [self addSubview:_timeView];
  739. [self addSubview:_collectionView];
  740. // 印票
  741. _otherContainerView = [[UIView alloc]init];
  742. //渐变B835A2到DD518B
  743. _otherContainerView.frame = CGRectMake(0, 0, 0, kTicketContrainerViewHeight);
  744. _otherContainerView.layer.cornerRadius = _otherContainerView.frame.size.height/2;
  745. _otherContainerView.backgroundColor = kGrayTransparentColor2;
  746. _otherContainerView.clipsToBounds = YES;
  747. [self addSubview:_otherContainerView];
  748. UITapGestureRecognizer *sigleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToContribution)];
  749. [_otherContainerView addGestureRecognizer:sigleTap];
  750. _ticketNameLabel = [[UILabel alloc]init];
  751. _ticketNameLabel.textColor = kWhiteColor;
  752. _ticketNameLabel.font = [UIFont systemFontOfSize:14.0];
  753. GlobalVariables *BuguLive = [GlobalVariables sharedInstance];
  754. _ticketNameLabel.text = [NSString stringWithFormat:@"%@ : ",BuguLive.appModel.ticket_name];
  755. [_otherContainerView addSubview:_ticketNameLabel];
  756. _ticketNumLabel = [[UILabel alloc]init];
  757. _ticketNumLabel.textColor = kWhiteColor;
  758. _ticketNumLabel.font = [UIFont systemFontOfSize:14.0];
  759. _ticketNumLabel.text = @"0";
  760. [_otherContainerView addSubview:_ticketNumLabel];
  761. _moreImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"lr_top_arrow_right"]];
  762. [_otherContainerView addSubview:_moreImgView];
  763. // 守护
  764. _wardContainerView = [[UIView alloc]init];
  765. _wardContainerView.frame = CGRectMake(0, 0, 0, kTicketContrainerViewHeight);
  766. _wardContainerView.layer.cornerRadius = _wardContainerView.frame.size.height/2;
  767. _wardContainerView.backgroundColor = kGrayTransparentColor2;
  768. _wardContainerView.clipsToBounds = YES;
  769. _wardContainerView.hidden = YES;
  770. _wardContainerView.userInteractionEnabled = YES;
  771. [self addSubview:_wardContainerView];
  772. UITapGestureRecognizer *wardSigleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToWardPopView)];
  773. [_wardContainerView addGestureRecognizer:wardSigleTap];
  774. _wardNumLabel = [[UILabel alloc]init];
  775. _wardNumLabel.textColor = kWhiteColor;
  776. _wardNumLabel.font = [UIFont systemFontOfSize:14.0];
  777. [self addSubview:_wardNumLabel];
  778. _wardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  779. [_wardBtn setBackgroundImage:[UIImage imageNamed:ASLocalizedString(@"bogo_live_ward")] forState:UIControlStateNormal];
  780. [_wardBtn addTarget:self action:@selector(goToWardPopView) forControlEvents:UIControlEventTouchUpInside];
  781. [self addSubview:_wardBtn];
  782. _vipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  783. [_vipBtn setBackgroundImage:[UIImage imageNamed:ASLocalizedString(@"bogo_live_Vip")] forState:UIControlStateNormal];
  784. [_vipBtn addTarget:self action:@selector(gotoVipPopView) forControlEvents:UIControlEventTouchUpInside];
  785. _vipBtn.hidden = [[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"0"];
  786. [self addSubview:_vipBtn];
  787. _moreWardImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"lr_top_arrow_right"]];
  788. [_wardContainerView addSubview:_moreWardImgView];
  789. // 最高价(竞拍模块)
  790. _priceView = [[UIView alloc]init];
  791. _priceView.frame = CGRectMake(0, 0, 0, kTicketContrainerViewHeight);
  792. _priceView.layer.cornerRadius = _priceView .bounds.size.height/2;
  793. _priceView.backgroundColor = kGrayTransparentColor2;
  794. _priceView.clipsToBounds = YES;
  795. _priceView.userInteractionEnabled = YES;
  796. [self addSubview:_priceView];
  797. _priceView.hidden = NO;
  798. UITapGestureRecognizer *otherTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToAuction)];
  799. [_priceView addGestureRecognizer:otherTap];
  800. _titleNameLabel= [[UILabel alloc]init];
  801. _titleNameLabel.textColor = kWhiteColor;
  802. _titleNameLabel.font = [UIFont systemFontOfSize:15.0];
  803. [_priceView addSubview:_titleNameLabel];
  804. _priceLabel = [[UILabel alloc]init];
  805. _priceLabel.textColor = kWhiteColor;
  806. _priceLabel.font = [UIFont systemFontOfSize:15.0];
  807. [_priceView addSubview:_priceLabel];
  808. _otherMoreView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"lr_top_arrow_right"]];
  809. [_priceView addSubview:_otherMoreView];
  810. _priceView.hidden = YES;
  811. // 账号
  812. _accountLabel = [[UILabel alloc]init];
  813. _accountLabel.textColor = RGBA(255, 255, 255, 0.52);
  814. _accountLabel.font = [UIFont systemFontOfSize:13.0];
  815. _accountLabel.textAlignment = NSTextAlignmentRight;
  816. _accountLabel.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  817. _accountLabel.hidden = YES;
  818. _accountLabel.shadowOffset = CGSizeMake(1, 1);
  819. [self addSubview:_accountLabel];
  820. // 推拉流码率
  821. _kbpsContainerView = [[UIView alloc]init];
  822. _kbpsContainerView.frame = CGRectMake(0, 0, 100, kTicketContrainerViewHeight+6);
  823. _kbpsContainerView.backgroundColor = kClearColor;
  824. _kbpsContainerView.clipsToBounds = YES;
  825. _kbpsContainerView.hidden = YES;
  826. [self addSubview:_kbpsContainerView];
  827. _kbpsSendLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_kbpsContainerView.frame), CGRectGetHeight(_kbpsContainerView.frame)/2)];
  828. _kbpsSendLabel.textColor = kWhiteColor;
  829. _kbpsSendLabel.font = [UIFont systemFontOfSize:9.0];
  830. _kbpsSendLabel.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  831. _kbpsSendLabel.shadowOffset = CGSizeMake(1, 1);
  832. [_kbpsContainerView addSubview:_kbpsSendLabel];
  833. _kbpsRecvLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_kbpsContainerView.frame), CGRectGetHeight(_kbpsContainerView.frame)/2)];
  834. _kbpsRecvLabel.textColor = kWhiteColor;
  835. _kbpsRecvLabel.font = [UIFont systemFontOfSize:9.0];
  836. _kbpsRecvLabel.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  837. _kbpsRecvLabel.shadowOffset = CGSizeMake(1, 1);
  838. [_kbpsContainerView addSubview:_kbpsRecvLabel];
  839. }
  840. - (void)relayoutFrameOfSubViews
  841. {
  842. CGFloat tmpWidth = 0;
  843. if (_isShowFollowBtn)
  844. {
  845. tmpWidth = kLogoContainerViewHeight+kLiveStatusViewWidth+kFollowBtnWidth+kDefaultMargin-2;
  846. _timeView.liveFollow.hidden = NO;
  847. }
  848. else
  849. {
  850. tmpWidth = kLogoContainerViewHeight+kLiveStatusViewWidth+kDefaultMargin-2;
  851. _timeView.liveFollow.hidden = YES;
  852. }
  853. _timeView.frame = CGRectMake(10, 3, self.width - 10, 44);
  854. [_timeView relayoutFrameOfSubViews];
  855. _numRightImgView.frame = CGRectMake(kScreenW - kLiveTopRightNumWidth, 0, kLiveTopRightNumWidth, kRealValue(34));
  856. _numRightImgView.centerY = _timeView.centerY;
  857. // _numRightImgView.qmui_borderPosition = QMUIViewBorderPositionTop | QMUIViewBorderPositionBottom | QMUIViewBorderPositionLeft;
  858. _collectionView.frame = CGRectMake(self.width - 100, 0, (self.frame.size.width-CGRectGetMaxX(_timeView.frame)-kDefaultMargin-kLiveTopRightNumWidth-kDefaultMargin*2),kLogoContainerViewHeight + kRealValue(17 / 2));
  859. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, kLiveTopRightNumWidth, kRealValue(34)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(kRealValue(34)/2, kRealValue(34)/2)];
  860. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  861. maskLayer.frame = CGRectMake(0, 0, kLiveTopRightNumWidth, kRealValue(34));
  862. maskLayer.path = maskPath.CGPath;
  863. _numRightImgView.layer.mask = maskLayer;
  864. // _numRightImgView.layer.cornerRadius = kRealValue(34)/2;
  865. // _numRightImgView.clipsToBounds = YES;
  866. [_numRightTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  867. make.centerX.mas_equalTo(_numRightImgView.mas_centerX);
  868. make.top.mas_equalTo(4);
  869. }];
  870. [_numRightSubTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  871. make.centerX.mas_equalTo(_numRightImgView.mas_centerX);
  872. make.top.mas_equalTo(_numRightTitleL.mas_bottom).offset(2);
  873. }];
  874. // _numRightTitleL.frame = CGRectMake(0, 0, _numRightImgView.width, _numRightImgView.height / 2);
  875. // _numRightSubTitleL.frame = CGRectMake(0, _numRightImgView.height / 2, _numRightImgView.width, _numRightImgView.height / 2);
  876. _accountLabel.frame = CGRectMake((self.frame.size.width-self.frame.size.width/2-kDefaultMargin), CGRectGetMaxY(_collectionView.frame)+kDefaultMargin, self.frame.size.width/2, _otherContainerView.frame.size.height);
  877. [self relayoutOtherContainerViewFrame];
  878. }
  879. - (void)relayoutOtherContainerViewFrame
  880. {
  881. CGSize ticketNameSize = [_ticketNameLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  882. CGSize ticketNumSize = [_ticketNumLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  883. _ticketNameLabel.frame = CGRectMake(kDefaultMargin, 0, ticketNameSize.width, CGRectGetHeight(_otherContainerView.frame));
  884. _ticketNumLabel.frame = CGRectMake(CGRectGetMaxX(_ticketNameLabel.frame)+2, 0, ticketNumSize.width+2, CGRectGetHeight(_otherContainerView.frame));
  885. _moreImgView.frame = CGRectMake(CGRectGetMaxX(_ticketNumLabel.frame)+4, (CGRectGetHeight(_otherContainerView.frame)-9)/2, 5, 9);
  886. _otherContainerView.frame = CGRectMake(kDefaultMargin, CGRectGetMaxY(_collectionView.frame)+kAppMargin2 * 2, CGRectGetMaxX(_moreImgView.frame)+kDefaultMargin, kTicketContrainerViewHeight);
  887. // gradientLayer.frame = _otherContainerView.bounds;
  888. // gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#B835A2"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#DD518B"].CGColor];
  889. // gradientLayer.startPoint = CGPointMake(0, 0);
  890. // gradientLayer.endPoint = CGPointMake(0, 1);
  891. gradientLayer = [CAGradientLayer layer];
  892. gradientLayer.frame = _otherContainerView.bounds; // 请将"yourView"替换为您想要添加渐变的视图
  893. gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#B835A2"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#DD518B"].CGColor];
  894. gradientLayer.startPoint = CGPointMake(0, 0);
  895. gradientLayer.endPoint = CGPointMake(1, 0);
  896. // 将渐变图层添加到视图的层次结构中
  897. [_otherContainerView.layer insertSublayer:gradientLayer atIndex:0];
  898. //守护相关
  899. CGSize wardNumSize = [_wardNumLabel.text textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:14]];
  900. // _wardNumLabel.frame = CGRectMake(kDefaultMargin, 0, wardNumSize.width+2, CGRectGetHeight(_wardContainerView.frame));
  901. _wardBtn.frame = CGRectMake(_otherContainerView.right + 10, _otherContainerView.top, 83, 23);
  902. _vipBtn.frame = CGRectMake(_wardBtn.right + 10, _wardBtn.top, 83, 23);
  903. if (_vipBtn.hidden) _vipBtn.height = 0;
  904. // CAGradientLayer *gradientLayer3 = [CAGradientLayer layer];
  905. // gradientLayer3.frame = _otherContainerView.bounds; // 请将"yourView"替换为您想要添加渐变的视图
  906. // gradientLayer3.colors = @[(__bridge id)[UIColor colorWithHexString:@"#EB3452"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#EFAF16"].CGColor];
  907. // gradientLayer3.startPoint = CGPointMake(0, 0);
  908. // gradientLayer3.endPoint = CGPointMake(1, 0);
  909. // [_vipBtn.layer insertSublayer:gradientLayer3 atIndex:0];
  910. CGSize titleNameSize = [_titleNameLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  911. CGSize priceSize = [_priceLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  912. _titleNameLabel.frame = CGRectMake(kDefaultMargin, 0, titleNameSize.width, _priceView.frame.size.height);
  913. _priceLabel.frame = CGRectMake(CGRectGetMaxX(_titleNameLabel.frame)+kDefaultMargin, 0, priceSize.width, CGRectGetHeight(_priceView.frame));
  914. _otherMoreView.frame = CGRectMake(CGRectGetMaxX(_priceLabel.frame)+4, (CGRectGetHeight(_priceView.frame)-9)/2, 5, 9);
  915. _priceView.frame = CGRectMake(kDefaultMargin, CGRectGetMaxY(_wardContainerView.frame)+kAppMargin2, CGRectGetMaxX(_otherMoreView.frame)+kDefaultMargin, kTicketContrainerViewHeight);
  916. CGRect newFrame = _kbpsContainerView.frame;
  917. newFrame.origin.x = CGRectGetMaxX(_wardContainerView.frame)+kDefaultMargin;
  918. newFrame.origin.y = CGRectGetMinY(_wardContainerView.frame) -3;
  919. _kbpsContainerView.frame = newFrame;
  920. }
  921. #pragma mark - ----------------------- UICollectionViewDataSource -----------------------
  922. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  923. {
  924. return 1;
  925. }
  926. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  927. {
  928. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(userlistRefresh)])
  929. {
  930. [_toServicedelegate userlistRefresh];
  931. }
  932. return _userArray.count;
  933. }
  934. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  935. {
  936. LiveUserViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LiveUserViewCell" forIndexPath:indexPath];
  937. [cell sizeToFit];
  938. UserModel *audience;
  939. if ([self.is_private isEqualToString:@"1"])//是否私密
  940. {
  941. if (![[[_liveItem liveHost] imUserId] isEqualToString:[IMAPlatform sharedInstance].host.imUserId] && self.has_admin == 0)//是否是私密直播的管理员
  942. {
  943. audience = _userArray[indexPath.row];
  944. [cell.userIcon sd_setImageWithURL:[NSURL URLWithString:audience.head_image] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  945. if ([audience.noble_stealth isEqualToString:@"1"]) {
  946. }
  947. }else
  948. {
  949. if (indexPath.row == 0){
  950. [cell.userIcon setImage:[UIImage imageNamed:@"ic_live_add_viewer"] forState:0];
  951. }else if (indexPath.row == 1)
  952. {
  953. [cell.userIcon setImage:[UIImage imageNamed:@"ic_live_minus_viewer"] forState:0];
  954. }else
  955. {
  956. audience = _userArray[indexPath.row-2];
  957. [cell.userIcon sd_setImageWithURL:[NSURL URLWithString:audience.head_image] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  958. }
  959. }
  960. }else
  961. {
  962. audience = _userArray[indexPath.row];
  963. [cell.userIcon sd_setImageWithURL:[NSURL URLWithString:audience.head_image] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  964. }
  965. if (audience.nobleid.intValue > 0)
  966. {
  967. cell.nobleImgView.hidden = NO;
  968. [cell.nobleImgView sd_setImageWithURL:[NSURL URLWithString:SafeStr(audience.noble_avatar)]];
  969. }
  970. else
  971. {
  972. cell.nobleImgView.hidden = YES;
  973. }
  974. if (audience.is_noble_mysterious.intValue == 1) {
  975. [cell.userIcon sd_setImageWithURL:nil forState:UIControlStateNormal placeholderImage:kDefaultNobleMysteriousHeadImg];
  976. }else{
  977. [cell.userIcon sd_setImageWithURL:[NSURL URLWithString:audience.head_image] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  978. }
  979. cell.indexRow = indexPath.row;
  980. cell.titleL.hidden = YES;
  981. if (audience.total_num.intValue > 0) {
  982. cell.titleL.text = audience.total_num;
  983. cell.titleL.hidden = NO;
  984. }
  985. cell.userInteractionEnabled = YES;
  986. cell.userIcon.tag = indexPath.row;
  987. __weak TCShowLiveTopView *ws = self;
  988. [cell.userIcon setClickAction:^(id<MenuAbleItem> menu) {
  989. [ws userIconAction:menu];
  990. }];
  991. return cell;
  992. }
  993. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  994. {
  995. return 2;
  996. }
  997. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  998. NSLog(@"%@",_userArray[indexPath.row]);
  999. UserModel *userModel = _userArray[indexPath.row];
  1000. // UserModel *userModel = [[UserModel alloc]init];
  1001. // userModel.user_id = [[_liveItem liveHost] imUserId];
  1002. // userModel.nick_name = [[_liveItem liveHost] imUserName];
  1003. // userModel.head_image = [[_liveItem liveHost] imUserIconUrl];
  1004. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:userModel:)])
  1005. {
  1006. [_toServicedelegate onTopView:self userModel:userModel];
  1007. }
  1008. }
  1009. - (void)userIconAction:(id)sender
  1010. {
  1011. MenuButton *userIcon = (MenuButton *)sender;
  1012. UserModel *userModel = [_userArray objectAtIndex:userIcon.tag];
  1013. if ([userModel.is_noble_mysterious isEqualToString:@"1"] && ![userModel.user_id isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  1014. [FanweMessage alertHUD:ASLocalizedString(@"不能查看神秘人的信息")];
  1015. return;
  1016. }
  1017. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(clickTopViewUserHeaderMustQuitAllHalfVC:)])
  1018. {
  1019. [_toServicedelegate clickTopViewUserHeaderMustQuitAllHalfVC:self];
  1020. }
  1021. if ([self.is_private isEqualToString:@"1"])//判断是否是私密
  1022. {
  1023. if (![[[_liveItem liveHost] imUserId] isEqualToString:[IMAPlatform sharedInstance].host.imUserId] && self.has_admin == 0)//是否是私密直播的管理员
  1024. {
  1025. if (userIcon.tag < [_userArray count])
  1026. {
  1027. UserModel *userModel = [_userArray objectAtIndex:userIcon.tag];
  1028. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:userModel:)])
  1029. {
  1030. [_toServicedelegate onTopView:self userModel:userModel];
  1031. }
  1032. }
  1033. }else
  1034. {
  1035. if (userIcon.tag == 0 || userIcon.tag == 1)//+ -
  1036. {
  1037. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:andCount:)])
  1038. {
  1039. [_toServicedelegate onTopView:self andCount:(int)userIcon.tag];
  1040. }
  1041. }
  1042. else
  1043. {
  1044. if (userIcon.tag < [_userArray count]+2)
  1045. {
  1046. UserModel *userModel = [_userArray objectAtIndex:userIcon.tag-2];
  1047. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:userModel:)])
  1048. {
  1049. [_toServicedelegate onTopView:self userModel:userModel];
  1050. }
  1051. }
  1052. }
  1053. }
  1054. }
  1055. else
  1056. {
  1057. if (userIcon.tag < [_userArray count])
  1058. {
  1059. UserModel *userModel = [_userArray objectAtIndex:userIcon.tag];
  1060. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:userModel:)])
  1061. {
  1062. [_toServicedelegate onTopView:self userModel:userModel];
  1063. }
  1064. }
  1065. }
  1066. }
  1067. #pragma mark -点击LiveVC 的主播个人 图像
  1068. /*!
  1069. * @author Yue
  1070. *
  1071. * @brief 直播左上角第一个btn,点击弹出个人信息,同时控制半VC 退出
  1072. */
  1073. - (void)clickLiveHost
  1074. {
  1075. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(clickTopViewUserHeaderMustQuitAllHalfVC:)])
  1076. {
  1077. [_toServicedelegate clickTopViewUserHeaderMustQuitAllHalfVC:self];
  1078. }
  1079. UserModel *userModel = [[UserModel alloc]init];
  1080. userModel.user_id = [[_liveItem liveHost] imUserId];
  1081. userModel.nick_name = [[_liveItem liveHost] imUserName];
  1082. userModel.head_image = [[_liveItem liveHost] imUserIconUrl];
  1083. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(onTopView:userModel:)])
  1084. {
  1085. [_toServicedelegate onTopView:self userModel:userModel];
  1086. }
  1087. }
  1088. #pragma mark - ----------------------- 其他 -----------------------
  1089. #pragma mark 刷新印票数量
  1090. - (void)refreshTicketCount:(NSString *)ticketCount
  1091. {
  1092. float ticket = ticketCount.floatValue;
  1093. if (ticket > 1000) {
  1094. _ticketNumLabel.text = [NSString stringWithFormat:@"%.1f%@",floorf(ticket/1000),ASLocalizedString(@"K")];
  1095. }else{
  1096. _ticketNumLabel.text = [NSString stringWithFormat:@"%.0f",ticket];
  1097. }
  1098. [self relayoutOtherContainerViewFrame];
  1099. if (_userArray.count < 1) {
  1100. [self refreshAudienceWithRoomID:_groupIdStr];
  1101. }
  1102. [self refreshAudienceWithRoomID:_groupIdStr];
  1103. }
  1104. -(void)refreshHostNumCount:(NSString *)numCount{
  1105. _numRightTitleL.text = numCount;
  1106. }
  1107. #pragma mark 监听推拉流请求的码率
  1108. - (void)monitorRateKBPS
  1109. {
  1110. _liveRateTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(getRateKBPS) userInfo:nil repeats:YES];
  1111. }
  1112. - (void)getRateKBPS
  1113. {
  1114. if (_toSDKDelegate && [_toSDKDelegate respondsToSelector:@selector(refreshKBPS:)])
  1115. {
  1116. [_toSDKDelegate refreshKBPS:self];
  1117. }
  1118. }
  1119. - (void)goToContribution
  1120. {
  1121. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(goToContributionList:)])
  1122. {
  1123. [_toServicedelegate goToContributionList:self];
  1124. }
  1125. }
  1126. - (void)goToWardPopView{
  1127. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(goToWardPopView:)]) {
  1128. [_toServicedelegate goToWardPopView:self];
  1129. }
  1130. }
  1131. -(void)gotoVipPopView{
  1132. if (self.clickVipBlock) {
  1133. self.clickVipBlock(YES);
  1134. }
  1135. // if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(goToVipPopView:)]) {
  1136. // [_toServicedelegate goToVipPopView:self];
  1137. // }
  1138. }
  1139. - (void)followAction
  1140. {
  1141. if (_toServicedelegate && [_toServicedelegate respondsToSelector:@selector(followAchor:)])
  1142. {
  1143. [_toServicedelegate followAchor:self];
  1144. }
  1145. }
  1146. @end