MOSquareBaseCollectionView.m 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. //
  2. // MOSquareBaseCollectionView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/7/31.
  6. //
  7. #define SetBtnWidthAndHeight 26.0
  8. //一页的size
  9. #define kPageSize 30
  10. #define kCollectionViewLeftAndRight 12.0
  11. #define kInsertBannerIndex 8
  12. #define kShowEnterRoomGuideViewKey @"kShowEnterRoomGuideViewKey"
  13. #import "MOSquareBaseCollectionView.h"
  14. #import "MOScrollMenuView.h"
  15. #import "MONoMoreDataView.h"
  16. #import "MOFollowInfoView.h"
  17. #import "MOFollowNoDataView.h"
  18. #import "MOSquareBannerReusableView.h"
  19. #import "MOLiveCell.h"
  20. #import "MOShowLivePagesVC.h"
  21. #import "MOLiveBase.h"
  22. #import "MOLiveList.h"
  23. #import "MOCountryBaseData.h"
  24. #import "MOCountryList.h"
  25. #import "MOMoreCountryView.h"
  26. #import "MOThemeManager.h"
  27. #import "MOMinimizeManager.h"
  28. #import "MOGuideMaskView.h"
  29. #import "UIScrollView+Scrollable.h"
  30. #import "MOLeftAlignedFlowLayout.h"
  31. @interface MOSquareBaseCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  32. @property (nonatomic, strong) UIView *bgView;
  33. /** 国家*/
  34. @property (nonatomic, strong) MOScrollMenuView *countryView;
  35. /** 展示所有国家的按钮 */
  36. @property (nonatomic, strong) BigBtn *allCountryBtn;
  37. /** 主界面 */
  38. @property (nonatomic, strong) UICollectionView *collectionView;
  39. /** 数据源(服务端返回的原数据) */
  40. @property (nonatomic, strong) NSMutableArray<MOLiveList *> *dataArr;
  41. /** 数据源(用来显示页面的数据源数组,index == kInsertBannerIndex 的位置插入bannerTag==YES的model) */
  42. @property (nonatomic, strong) NSMutableArray<MOLiveList *> *showDataArr;
  43. /** 没有更多的数据视图 */
  44. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  45. /** 关注界面 - 视频/音频切换view */
  46. @property (nonatomic, strong) MOScrollMenuView *followTypeView;
  47. /** follow数据展示View */
  48. @property (nonatomic, strong) MOFollowInfoView *followInfoView;
  49. /** 无数据view */
  50. @property (nonatomic, strong) MOFollowNoDataView *followNoData;
  51. /** 关注页面数据 */
  52. @property (nonatomic, strong) MOLiveBase *followInfoData;
  53. @property (nonatomic, strong) MOSquareBannerReusableView *headView;
  54. @property (nonatomic, strong) NSArray *bannerArr;
  55. @property (nonatomic, assign) BOOL isFirstShow;
  56. /** 国家列表 */
  57. @property (nonatomic, strong) NSMutableArray *countryDataArr;
  58. @property (nonatomic, assign) BOOL isProcessingSelection;
  59. //是否下拉刷新
  60. @property (nonatomic, assign) BOOL pullRefresh;
  61. @end
  62. @implementation MOSquareBaseCollectionView
  63. - (instancetype)init{
  64. self = [super init];
  65. if (self)
  66. {
  67. [self setupUI];
  68. }
  69. return self;
  70. }
  71. - (instancetype)initWithFrame:(CGRect)frame
  72. {
  73. self = [super initWithFrame:frame];
  74. if (self)
  75. {
  76. [self setupUI];
  77. }
  78. return self;
  79. }
  80. - (instancetype)initWithFrame:(CGRect)frame AndIsFollow:(BOOL)follow{
  81. self = [super initWithFrame:frame];
  82. if (self)
  83. {
  84. self.isFollow = follow;
  85. [self setupUI];
  86. }
  87. return self;
  88. }
  89. - (void)setupUI{
  90. //默认视频直播
  91. self.searchType = 2;
  92. self.next = @"";
  93. self.countryString = @"";
  94. self.roomType = 1;
  95. self.sortType = 1;
  96. self.isNeedWillRefresh = NO;
  97. self.isFirstShow = NO;
  98. [self addSubview:self.bgView];
  99. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.edges.equalTo(self);
  101. }];
  102. if(self.isFollow){
  103. // [self.bgView addSubview:self.followTypeView];
  104. // [self.followTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
  105. // make.top.equalTo(self.bgView);
  106. // make.left.equalTo(self.bgView).offset(15.0);
  107. // make.height.equalTo(@24.0);
  108. // make.right.equalTo(self.bgView).offset(-15.0);
  109. // }];
  110. [self.bgView addSubview:self.followInfoView];
  111. [self.followInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.top.equalTo(self.bgView).offset(12.0);
  113. make.left.right.equalTo(self.bgView);
  114. make.height.equalTo(@26.0);
  115. }];
  116. // [self.bgView addSubview:self.followNoData];
  117. // [self.followNoData mas_makeConstraints:^(MASConstraintMaker *make) {
  118. // make.top.equalTo(self.bgView).offset(12.0);
  119. // make.left.right.equalTo(self.bgView);
  120. // make.height.equalTo(@180.0);
  121. // }];
  122. [self.bgView addSubview:self.collectionView];
  123. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.top.equalTo(self.followInfoView.mas_bottom).offset(15.0);
  125. make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
  126. make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
  127. make.bottom.equalTo(self.bgView);
  128. }];
  129. [self setFollowTypeChooseBlock];
  130. }
  131. else{
  132. [self.bgView addSubview:self.countryView];
  133. [self.countryView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.top.equalTo(self.bgView).offset(0.0);
  135. make.left.equalTo(self.bgView).offset(15.0);
  136. // make.height.equalTo(@24.0);
  137. make.right.equalTo(self.bgView).offset(-15.0 - 30);
  138. make.height.mas_equalTo(0);
  139. }];
  140. [self.bgView addSubview:self.allCountryBtn];
  141. [self.allCountryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.right.equalTo(self.bgView).offset(-13.0);
  143. // make.width.height.equalTo(@24.0);
  144. make.width.height.mas_equalTo(0);
  145. make.centerY.equalTo(self.countryView.mas_centerY);
  146. }];
  147. [self.bgView addSubview:self.collectionView];
  148. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  149. // make.top.equalTo(self.countryView.mas_bottom).offset(15.0);
  150. make.top.mas_equalTo(0);
  151. make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
  152. make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
  153. make.bottom.equalTo(self.bgView);
  154. }];
  155. self.collectionView.backgroundView = self.noMoreDataView;
  156. }
  157. }
  158. - (void)updateFollowViewUI{
  159. if(self.followInfoData.recommend){
  160. //推荐数据
  161. self.followInfoView.hidden = YES;
  162. [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  163. make.top.mas_equalTo(0);
  164. make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
  165. make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
  166. make.bottom.equalTo(self.bgView);
  167. }];
  168. [UIView animateWithDuration:0.3 animations:^{
  169. [self layoutIfNeeded];
  170. }];
  171. }
  172. else{
  173. self.followInfoView.hidden = NO;
  174. [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  175. make.top.equalTo(self.followInfoView.mas_bottom).offset(15.0);
  176. make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
  177. make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
  178. make.bottom.equalTo(self.bgView);
  179. }];
  180. [UIView animateWithDuration:0.3 animations:^{
  181. [self layoutIfNeeded];
  182. }];
  183. self.followInfoView.contentLab.text = [NSString stringWithFormat:@"%.f %@",self.followInfoData.liveCount,NSLocalString(@"mimo_square_following_people_num")];
  184. }
  185. }
  186. #pragma mark - Block
  187. - (void)setFollowTypeChooseBlock{
  188. WEAKSELF
  189. self.followTypeView.clickBtnBlock = ^(NSInteger index) {
  190. __strong typeof(weakSelf) self = weakSelf;
  191. if(index == 0){
  192. self.roomType = 1;
  193. }
  194. else{
  195. self.roomType = 2;
  196. }
  197. //第一次位空字符串
  198. self.next = @"";
  199. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  200. NSDictionary *baseDict = @{@"roomType":@(self.roomType),
  201. @"sortType":@(self.sortType),
  202. @"page":basePage};
  203. [self toGetHttpFollowDataWithDict:baseDict];
  204. };
  205. }
  206. - (void)setCountryChooseBlock{
  207. self.countryView.titleArray = [self.countryDataArr copy];
  208. self.countryView.currentButtonIndex = 0;
  209. WEAKSELF
  210. self.countryView.clickBtnBlock = ^(NSInteger index) {
  211. __strong typeof(weakSelf) self = weakSelf;
  212. MOCountryList *countryModel = self.countryDataArr[index];
  213. if(index == 0){
  214. //推荐
  215. self.countryString = @"";
  216. }
  217. else{
  218. self.countryString = countryModel.id;
  219. }
  220. //第一次位空字符串
  221. self.next = @"";
  222. //视频直播
  223. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  224. NSDictionary *baseDict = @{@"searchType":@(self.searchType),
  225. @"category":self.countryString ?: @"",
  226. @"page":basePage};
  227. [self getHttpDataWithDict:baseDict];
  228. };
  229. }
  230. #pragma mark - JXCategoryListContentViewDelegate
  231. - (void)listWillAppear{
  232. if(self.dataArr.count == 0){
  233. if(self.isFollow){
  234. //关注列表数据
  235. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  236. NSDictionary *baseDict = @{@"roomType":@(self.roomType),
  237. @"sortType":@(self.sortType),
  238. @"page":basePage};
  239. [self toGetHttpFollowDataWithDict:baseDict];
  240. }
  241. else{
  242. if(self.dataArr.count == 0){
  243. //第一次位空字符串 (代表第一页)
  244. self.next = @"";
  245. //视频直播
  246. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  247. NSDictionary *baseDict = @{@"searchType":@(self.searchType),
  248. @"category":self.countryString ?: @"",
  249. @"page":basePage};
  250. [self getHttpDataWithDict:baseDict];
  251. }
  252. if(self.bannerArr.count == 0){
  253. if(self.searchType == 2){
  254. //视频直播
  255. [self getSquareBannerListDataWith:1];
  256. }
  257. else if (self.searchType == 3){
  258. //音频直播
  259. [self getSquareBannerListDataWith:6];
  260. }
  261. else if (self.searchType == 4){
  262. //新人
  263. [self getSquareBannerListDataWith:3];
  264. }
  265. }
  266. }
  267. }
  268. //获取国家列表
  269. if(!self.isFollow){
  270. if(self.countryDataArr.count == 0){
  271. [self getHttpDataAboutCategroy];
  272. }
  273. //国家列表数据缓存
  274. if([MOSvgaSourceManage shareManager].countryArr.count == 0){
  275. [self getHttpDataAboutCountry];
  276. }
  277. }
  278. }
  279. - (UIView *)listView{
  280. return self;
  281. }
  282. #pragma mark - Mothed
  283. - (void)toBeginRefresh{
  284. [self.collectionView.mj_header beginRefreshing];
  285. }
  286. - (void)showEnterRoomGuideView {
  287. if (self.dataArr.count == 0) {
  288. return;
  289. }
  290. NSIndexPath *firstIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
  291. UICollectionViewCell *firstCell = [self.collectionView cellForItemAtIndexPath:firstIndexPath];
  292. if (firstCell) {
  293. CGRect cellFrameInWindow = [firstCell convertRect:firstCell.bounds toView:[UIApplication sharedApplication].keyWindow];
  294. // 扩大四边各 5pt
  295. CGRect holeRect = CGRectInset(cellFrameInWindow, -5, -5);
  296. [self showGuideMaskWithHoleInRect:holeRect];
  297. }
  298. }
  299. - (void)showGuideMaskWithHoleInRect:(CGRect)holeRect {
  300. if (!self.window) {//view没显示不弹出气泡
  301. return;
  302. }
  303. NSString *showKey = (NSString *)[[MODataCache sharedYYCache] objectForKey:kShowEnterRoomGuideViewKey];
  304. if (showKey.length > 0) {//已经显示过了,不再显示
  305. return;
  306. }
  307. MOGuideMaskView *guideView = [[MOGuideMaskView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  308. [guideView addHoleWithRect:holeRect cornerRadius:16];
  309. [guideView show];
  310. [[MODataCache sharedYYCache] setObject:kShowEnterRoomGuideViewKey forKey:kShowEnterRoomGuideViewKey];
  311. CGFloat holeCenterX = CGRectGetMidX(holeRect);
  312. CGFloat bottomY = CGRectGetMaxY(holeRect);
  313. UIView *textView = [[UIView alloc] init];
  314. textView.backgroundColor = [MOTools colorWithHexString:@"#FF4DA6"];
  315. textView.layer.masksToBounds = YES;
  316. textView.layer.cornerRadius = 6;
  317. [guideView addSubview:textView];
  318. NSString *showText = NSLocalString(@"mimo_2_guide_select_host");
  319. UIFont *showFont = [MOTextTools poppinsMediumFont:12];
  320. CGFloat textWidth = [MOTools getWidthWithString:showText font:showFont];
  321. CGFloat viewWidth = textWidth + 12;
  322. [textView mas_makeConstraints:^(MASConstraintMaker *make) {
  323. make.top.mas_equalTo(bottomY + 59);
  324. make.centerX.equalTo(guideView.mas_left).offset(holeCenterX);
  325. make.size.mas_equalTo(CGSizeMake(viewWidth, 24));
  326. }];
  327. UIView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_left"]];
  328. [guideView addSubview:leftView];
  329. [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
  330. make.centerX.equalTo(textView.mas_left);
  331. make.centerY.equalTo(textView.mas_top);
  332. make.size.mas_equalTo(CGSizeMake(24, 19));
  333. }];
  334. UIView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_right"]];
  335. [guideView addSubview:rightView];
  336. [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
  337. make.right.equalTo(textView);
  338. make.bottom.equalTo(textView.mas_top);
  339. make.size.mas_equalTo(CGSizeMake(10, 10));
  340. }];
  341. UILabel *textLabel = [[UILabel alloc] init];
  342. textLabel.font = showFont;
  343. textLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  344. textLabel.text = showText;
  345. [textView addSubview:textLabel];
  346. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  347. make.center.mas_equalTo(0);
  348. }];
  349. UIImageView *lineView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_line_up"]];
  350. [guideView addSubview:lineView];
  351. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  352. make.top.mas_equalTo(bottomY + 2);
  353. make.centerX.equalTo(guideView.mas_left).offset(holeCenterX);
  354. make.size.mas_equalTo(CGSizeMake(10, 58));
  355. }];
  356. UIView *arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_arrow_up"]];
  357. [guideView addSubview:arrowView];
  358. [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
  359. make.bottom.equalTo(textView.mas_top).offset(1);
  360. make.centerX.equalTo(lineView);
  361. make.size.mas_equalTo(CGSizeMake(11, 6));
  362. }];
  363. }
  364. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  365. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  366. {
  367. return 1;
  368. }
  369. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  370. {
  371. return self.showDataArr.count;
  372. }
  373. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  374. {
  375. WEAKSELF
  376. MOLiveList *model;
  377. //因为牵扯Follow逻辑, 容易出现数组越界崩溃, 先这样处理
  378. if(indexPath.row < self.showDataArr.count){
  379. model = self.showDataArr[indexPath.row];
  380. if (model.bannerTag) {
  381. MOSquareBannerReusableView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOSquareBannerReusableView_ID forIndexPath:indexPath];
  382. cell.imageArr = self.bannerArr;
  383. return cell;
  384. } else {
  385. MOLiveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOLiveCell_ID forIndexPath:indexPath];
  386. cell.model = model;
  387. //更多按钮点击事件
  388. cell.moreBtnBlock = ^(MOLiveList * _Nonnull model) {
  389. for (MOLiveList *object in weakSelf.dataArr) {
  390. if([object.id isEqualToString:model.id]){
  391. object.isViewSelect = YES;
  392. }
  393. }
  394. };
  395. cell.cancelBtnBlock = ^(MOLiveList * _Nonnull model) {
  396. for (MOLiveList *object in weakSelf.dataArr) {
  397. if([object.id isEqualToString:model.id]){
  398. object.isViewSelect = NO;
  399. }
  400. }
  401. };
  402. __weak __typeof__(cell) weakCell = cell;
  403. cell.noLikeBlock = ^(MOLiveList * _Nonnull model) {
  404. NSIndexPath *newIndexPath = [weakSelf.collectionView indexPathForCell:weakCell];
  405. if(weakSelf.showDataArr.count > newIndexPath.row){
  406. MOLiveList *liveModel = [weakSelf.showDataArr objectAtIndex:newIndexPath.row];
  407. [weakSelf.showDataArr removeObject:liveModel];
  408. [weakSelf.collectionView performBatchUpdates:^{
  409. [weakSelf.collectionView deleteItemsAtIndexPaths:@[newIndexPath]];
  410. } completion:^(BOOL finished) {
  411. [weakSelf.dataArr removeObject:liveModel];
  412. [weakSelf handleDataAndReloadCollectionViewData];
  413. }];
  414. }
  415. };
  416. return cell;
  417. }
  418. }
  419. return [collectionView dequeueReusableCellWithReuseIdentifier:MOLiveCell_ID forIndexPath:indexPath];
  420. }
  421. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  422. {
  423. if (self.isProcessingSelection) {
  424. return;
  425. }
  426. self.isProcessingSelection = YES;
  427. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  428. if(!self.homeVC){
  429. return;
  430. }
  431. [MOShowAgoraKitManager shareManager].isFirstShow = YES;
  432. [MOShowAgoraKitManager shareManager].beginIndex = indexPath.row;
  433. [MOShowAgoraKitManager shareManager].isCreatLive = NO;
  434. MOLiveList *model = self.showDataArr[indexPath.row];
  435. //TODO: 进入直播房
  436. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  437. vc.userType = MOShowLiveAudienceType;
  438. vc.roomList = [self.dataArr mutableCopy];
  439. vc.searchType = self.searchType;
  440. vc.next = self.next;
  441. vc.countryString = self.countryString;
  442. vc.roomType = self.roomType;
  443. vc.sortType = self.sortType;
  444. NSInteger index = 0;
  445. int x = 0;
  446. for (MOLiveList *listModel in self.dataArr) {
  447. if([listModel.id isEqualToString:model.id]){
  448. index = x;
  449. }
  450. x ++;
  451. }
  452. vc.focusIndex = index;
  453. WEAKSELF
  454. vc.deleteCloseRoomBlock = ^(NSString * _Nonnull roomId) {
  455. if(roomId.length == 0){
  456. return;
  457. }
  458. BOOL isHave = NO;
  459. NSInteger theRow = 0;
  460. for (MOLiveList *listModel in weakSelf.dataArr) {
  461. if([roomId isEqualToString:listModel.id]){
  462. isHave = YES;
  463. break;
  464. }
  465. theRow ++;
  466. }
  467. if(isHave == YES){
  468. NSIndexPath *theIndexPath = [NSIndexPath indexPathForRow:theRow inSection:0];
  469. [weakSelf.showDataArr removeObjectAtIndex:theRow];
  470. [weakSelf handleDataAndReloadCollectionViewData];
  471. }
  472. };
  473. //关闭直播间的回调
  474. vc.closeRoomBlock = ^{
  475. NSArray *checkArr = [MOShowAgoraKitManager getSurroundingElementsWith:weakSelf.dataArr Range:10];
  476. [[MOShowAgoraKitManager shareManager] toCheckTheLiveRoomWithRoomListArr:checkArr andBlock:^(NSArray * _Nonnull closeArr) {
  477. NSMutableArray *deleteIndexArr = [NSMutableArray array];
  478. // 创建一个可变的NSIndexSet,用于添加不连续的索引
  479. NSMutableIndexSet *indexesToRemove = [NSMutableIndexSet indexSet];
  480. for (int x = 0; x < weakSelf.dataArr.count; x ++) {
  481. MOLiveList *liveModel = weakSelf.dataArr[x];
  482. NSString *roomIdStr = liveModel.id;
  483. if([closeArr containsObject:roomIdStr]){
  484. [indexesToRemove addIndex:x];
  485. }
  486. }
  487. [weakSelf.dataArr removeObjectsAtIndexes:indexesToRemove];
  488. [weakSelf handleDataAndReloadCollectionViewData];
  489. }];
  490. };
  491. vc.dataChangeBlock = ^(NSString * _Nonnull nextStr, NSMutableArray * _Nonnull roomList) {
  492. if(nextStr.length == 0){
  493. //最后一页
  494. [weakSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
  495. }
  496. if(roomList.count > weakSelf.dataArr.count){
  497. weakSelf.dataArr = [roomList mutableCopy];
  498. [weakSelf handleDataAndReloadCollectionViewData];
  499. weakSelf.collectionView.mj_footer.hidden = (weakSelf.dataArr.count > 0) ? NO : YES;
  500. }
  501. };
  502. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  503. // nav.modalPresentationStyle = UIModalPresentationFullScreen;
  504. // [self.homeVC presentViewController:nav animated:YES completion:nil];
  505. vc.hidesBottomBarWhenPushed = YES;
  506. [self.homeVC.navigationController pushViewController:vc animated:YES];
  507. self.isNeedWillRefresh = YES;
  508. //重置状态
  509. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  510. self.isProcessingSelection = NO;
  511. });
  512. }
  513. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
  514. viewForSupplementaryElementOfKind:(NSString *)kind
  515. atIndexPath:(NSIndexPath *)indexPath {
  516. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  517. if (self.isFollow && self.followInfoData.recommend) {
  518. MOFollowNoDataView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  519. withReuseIdentifier:@"MOFollowNoDataView"
  520. forIndexPath:indexPath];
  521. headView.backgroundColor = [UIColor clearColor];
  522. return headView;
  523. } else {
  524. // 返回一个空 header 防止崩溃
  525. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"sectionHeader" forIndexPath:indexPath];
  526. return view;
  527. }
  528. } else {
  529. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot" forIndexPath:indexPath];
  530. return view;
  531. }
  532. }
  533. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  534. if(self.isFollow && self.followInfoData.recommend){
  535. return CGSizeMake(SCREENWIDTH, 180);
  536. }
  537. return CGSizeMake(SCREENWIDTH, 0.01);
  538. }
  539. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  540. MOLiveList* model = self.showDataArr[indexPath.row];
  541. if (model.bannerTag) {
  542. CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2;
  543. return CGSizeMake(collectionWidth, 82);
  544. } else {
  545. CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2 - 7.0;
  546. return CGSizeMake(collectionWidth / 2.0 , 229);
  547. }
  548. }
  549. // 开始拖动时隐藏 tabBar
  550. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  551. if (![scrollView isContentVerticallyScrollable]) {
  552. return;
  553. }
  554. [[MOMainTabController sharedSingleton] hideTabbarWithAnimation:YES];
  555. if (self.beginScrollBlock) {
  556. self.beginScrollBlock();
  557. }
  558. }
  559. // 停止滚动时显示 tabBar(包括减速完成)
  560. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  561. if (![scrollView isContentVerticallyScrollable]) {
  562. return;
  563. }
  564. [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
  565. }
  566. // 如果没有减速(立即停止),也要显示 tabBar
  567. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  568. if (!decelerate) {
  569. [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
  570. }
  571. }
  572. #pragma mark - Http
  573. //获取界面数据
  574. - (void)getHttpDataWithDict:(NSDictionary *)dict{
  575. WEAKSELF
  576. [kHttpManager getLiveRoomListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  577. __strong typeof(weakSelf) self = weakSelf;
  578. [self.collectionView.mj_header endRefreshing];
  579. [self.collectionView.mj_footer endRefreshing];
  580. weakSelf.isNeedWillRefresh = NO;
  581. if(kCode_Success){
  582. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  583. MOLiveBase *baseModel = [MOLiveBase modelObjectWithDictionary:data[@"data"]];
  584. if(baseModel.next == nil || baseModel.next.length == 0){
  585. if(self.next == nil || self.next.length == 0){
  586. //第一页
  587. [self.dataArr removeAllObjects];
  588. [self toAddNewListDataWith:baseModel.liveList];
  589. }
  590. else{
  591. //最后一页
  592. [self toAddNewListDataWith:baseModel.liveList];
  593. }
  594. self.next = @"";
  595. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  596. }
  597. else{
  598. if(self.next == nil || self.next.length == 0){
  599. //第一页
  600. [self.dataArr removeAllObjects];
  601. [self toAddNewListDataWith:baseModel.liveList];
  602. }
  603. else{
  604. //最后一页
  605. [self toAddNewListDataWith:baseModel.liveList];
  606. }
  607. self.next = baseModel.next;
  608. }
  609. // [self.collectionView reloadData];
  610. [self handleDataAndReloadCollectionViewData];
  611. self.collectionView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  612. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  613. if (self.dataArr.count > 0) {
  614. [MOMinimizeManager shareManager].roomList = self.dataArr;
  615. }
  616. }
  617. else{
  618. kShowNetError(data)
  619. }
  620. }];
  621. }
  622. - (void)toAddNewListDataWith:(NSArray *)liveListArr{
  623. NSMutableArray *elementsToAdd = [NSMutableArray array];
  624. BOOL isOpen = [MOTools toJudgeShowWame];
  625. for (MOLiveList *listModel in liveListArr) {
  626. BOOL isElementFound = NO;
  627. // 检查数组A中是否存在相同元素
  628. for (NSInteger i = 0; i < self.dataArr.count; i++) {
  629. MOLiveList *elementA = self.dataArr[i];
  630. if([elementA.anchorUser.id isEqualToString:listModel.anchorUser.id]){
  631. [self.dataArr replaceObjectAtIndex:i withObject:listModel];
  632. isElementFound = YES;
  633. break;
  634. }
  635. }
  636. if(!isOpen){
  637. if(listModel.roomType == 2 || listModel.roomType == 3){
  638. continue;
  639. }
  640. }
  641. // 未找到则记录待添加
  642. if (!isElementFound) {
  643. [elementsToAdd addObject:listModel];
  644. }
  645. }
  646. // 将B中独有的元素添加到A
  647. [self.dataArr addObjectsFromArray:elementsToAdd];
  648. }
  649. - (void)toGetHttpFollowDataWithDict:(NSDictionary *)dict{
  650. WEAKSELF
  651. [kHttpManager getLiveRoomFollowListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  652. __strong typeof(weakSelf) self = weakSelf;
  653. [self.collectionView.mj_header endRefreshing];
  654. [self.collectionView.mj_footer endRefreshing];
  655. self.isNeedWillRefresh = NO;
  656. if(kCode_Success){
  657. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  658. self.followInfoData = [MOLiveBase modelObjectWithDictionary:data[@"data"]];
  659. if(self.followInfoData.next == nil || self.followInfoData.next.length == 0){
  660. if(self.next == nil || self.next.length == 0){
  661. //第一页
  662. [self.dataArr removeAllObjects];
  663. [self toAddNewListDataWith:self.followInfoData.liveList];
  664. }
  665. else{
  666. //最后一页
  667. [self toAddNewListDataWith:self.followInfoData.liveList];
  668. }
  669. self.next = @"";
  670. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  671. }
  672. else{
  673. if(self.next == nil || self.next.length == 0){
  674. [self.dataArr removeAllObjects];
  675. [self toAddNewListDataWith:self.followInfoData.liveList];
  676. }
  677. else{
  678. [self toAddNewListDataWith:self.followInfoData.liveList];
  679. }
  680. self.next = self.followInfoData.next;
  681. }
  682. [self handleDataAndReloadCollectionViewData];
  683. // [self.collectionView reloadData];
  684. [self updateFollowViewUI];
  685. self.collectionView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  686. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  687. if (self.dataArr.count > 0) {
  688. [MOMinimizeManager shareManager].roomList = self.dataArr;
  689. }
  690. }
  691. else{
  692. kShowNetError(data)
  693. }
  694. }];
  695. }
  696. - (void)getSquareBannerListDataWith:(NSInteger)type{
  697. WEAKSELF
  698. //banner分类(1=首页图片,2=直播间图片,3=New页图片,4=启动页图片,5=开播页图片,6=语音列表图片)
  699. NSDictionary *dict = @{@"category":@(type)};
  700. [kHttpManager getBaseBannerListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  701. if(kCode_Success){
  702. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  703. MOBannerData *baseModel = [MOBannerData modelObjectWithDictionary:data[@"data"]];
  704. weakSelf.headView.imageArr = [baseModel.JumpList copy];
  705. weakSelf.bannerArr = [baseModel.JumpList copy];
  706. if(!weakSelf.isFirstShow){
  707. weakSelf.isFirstShow = YES;
  708. [weakSelf.collectionView reloadData];
  709. }
  710. }
  711. else{
  712. // kShowNetError(data)
  713. }
  714. }];
  715. }
  716. //获取国家列表
  717. - (void)getHttpDataAboutCountry{
  718. WEAKSELF
  719. [[MOSvgaSourceManage shareManager].countryArr removeAllObjects];
  720. [kHttpManager getCountryAndRegionListWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  721. __strong typeof(weakSelf) self = weakSelf;
  722. if(kCode_Success){
  723. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  724. MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
  725. for (MOCountryList *object in countryBase.countryList) {
  726. if(object.code.length != 0){
  727. [[MODataCache sharedYYCache] setObject:object forKey:[NSString stringWithFormat:@"%@_%@",kCountryArrInfo,object.code]];
  728. }
  729. }
  730. [MOSvgaSourceManage shareManager].countryArr = [countryBase.countryList mutableCopy];
  731. // self.countryDataArr = [countryBase.countryList mutableCopy];
  732. //
  733. //第一个数据位推荐数据
  734. MOCountryList *firstModel = [[MOCountryList alloc] init];
  735. firstModel.name = NSLocalString(@"mimo_hot_recommend");
  736. firstModel.icon = @"";
  737. [[MOSvgaSourceManage shareManager].countryArr insertObject:firstModel atIndex:0];
  738. //
  739. // [self setCountryChooseBlock];
  740. [self.collectionView reloadData];
  741. }
  742. else
  743. {
  744. kShowNetError(data)
  745. }
  746. }];
  747. }
  748. - (void)getHttpDataAboutCategroy{
  749. WEAKSELF
  750. [kHttpManager toGetTheLiveRoomCategoryDataWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  751. __strong typeof(weakSelf) self = weakSelf;
  752. if(kCode_Success){
  753. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  754. MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
  755. self.countryDataArr = [countryBase.countryList mutableCopy];
  756. //第一个数据位推荐数据
  757. MOCountryList *firstModel = [[MOCountryList alloc] init];
  758. firstModel.name = NSLocalString(@"mimo_hot_recommend");
  759. firstModel.icon = @"";
  760. [self.countryDataArr insertObject:firstModel atIndex:0];
  761. [self setCountryChooseBlock];
  762. // [self.collectionView reloadData];
  763. }
  764. else
  765. {
  766. kShowNetError(data)
  767. }
  768. }];
  769. }
  770. - (void)handleDataAndReloadCollectionViewData {
  771. self.showDataArr = self.dataArr.mutableCopy;
  772. if (!self.isFollow) {
  773. MOLiveList *bannerModel = [[MOLiveList alloc] init];
  774. bannerModel.bannerTag = YES;
  775. if (self.showDataArr.count <= kInsertBannerIndex) {
  776. [self.showDataArr addObject:bannerModel];
  777. } else {
  778. [self.showDataArr insertObject:bannerModel atIndex:kInsertBannerIndex];
  779. }
  780. }
  781. [self.collectionView reloadData];
  782. if (self.pullRefresh) {//下拉刷新需要显示tabbar
  783. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  784. [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
  785. self.pullRefresh = NO;
  786. });
  787. }
  788. }
  789. #pragma mark - Lazy
  790. - (UICollectionView *)collectionView
  791. {
  792. if (!_collectionView)
  793. {
  794. CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2 - 7.0;
  795. MOLeftAlignedFlowLayout *layout = [[MOLeftAlignedFlowLayout alloc] init];
  796. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  797. layout.minimumLineSpacing = 7.0;
  798. layout.minimumInteritemSpacing = 7.0;
  799. layout.itemSize = CGSizeMake(collectionWidth / 2.0 , 229);
  800. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, collectionWidth, collectionWidth / 2) collectionViewLayout:layout];
  801. [_collectionView registerClass:[MOLiveCell class] forCellWithReuseIdentifier:MOLiveCell_ID];
  802. [_collectionView registerClass:[MOSquareBannerReusableView class] forCellWithReuseIdentifier:MOSquareBannerReusableView_ID];
  803. [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(MOFollowNoDataView.class) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass(MOFollowNoDataView.class)];
  804. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"sectionHeader"];
  805. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"];
  806. _collectionView.dataSource = self;
  807. _collectionView.delegate = self;
  808. _collectionView.showsVerticalScrollIndicator = NO;
  809. _collectionView.backgroundColor = [UIColor clearColor];
  810. WEAKSELF
  811. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  812. __strong typeof(weakSelf) self = weakSelf;
  813. self.pullRefresh = YES;
  814. //获取banner数据
  815. self.next = @"";
  816. if(self.isFollow){
  817. //关注列表数据
  818. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  819. NSDictionary *baseDict = @{@"roomType":@(self.roomType),
  820. @"sortType":@(self.sortType),
  821. @"page":basePage};
  822. [weakSelf toGetHttpFollowDataWithDict:baseDict];
  823. return;
  824. }
  825. else{
  826. if(self.searchType == 2){
  827. //视频直播
  828. [self getSquareBannerListDataWith:1];
  829. }
  830. else if (self.searchType == 3){
  831. //音频直播
  832. [self getSquareBannerListDataWith:6];
  833. }
  834. else if (self.searchType == 4){
  835. //新人
  836. [self getSquareBannerListDataWith:3];
  837. }
  838. if(self.countryDataArr.count == 0 && !self.isFollow){
  839. [self getHttpDataAboutCategroy];
  840. }
  841. //国家列表数据缓存
  842. if([MOSvgaSourceManage shareManager].countryArr.count == 0){
  843. [self getHttpDataAboutCountry];
  844. }
  845. //视频直播
  846. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next ?: @""};
  847. NSDictionary *baseDict = @{@"searchType":@(self.searchType),
  848. @"category":self.countryString ?: @"",
  849. @"page":basePage};
  850. [self getHttpDataWithDict:baseDict];
  851. }
  852. }];
  853. header.lastUpdatedTimeLabel.hidden = YES;
  854. header.stateLabel.hidden = YES;
  855. _collectionView.mj_header = header;
  856. _collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  857. if(weakSelf.next.length == 0){
  858. return;
  859. }
  860. if(weakSelf.isFollow){
  861. //关注列表数据
  862. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  863. NSDictionary *baseDict = @{@"roomType":@(weakSelf.roomType),
  864. @"sortType":@(weakSelf.sortType),
  865. @"page":basePage};
  866. [weakSelf toGetHttpFollowDataWithDict:baseDict];
  867. return;
  868. }
  869. else{
  870. //视频直播
  871. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  872. NSDictionary *baseDict = @{@"searchType":@(weakSelf.searchType),
  873. @"category":weakSelf.countryString ?: @"",
  874. @"page":basePage};
  875. [weakSelf getHttpDataWithDict:baseDict];
  876. }
  877. }];
  878. _collectionView.mj_footer.hidden = YES;
  879. }
  880. return _collectionView;
  881. }
  882. - (NSMutableArray<MOLiveList *> *)dataArr {
  883. if(!_dataArr){
  884. _dataArr = [NSMutableArray array];
  885. }
  886. return _dataArr;
  887. }
  888. - (NSMutableArray<MOLiveList *> *)showDataArr {
  889. if (!_showDataArr) {
  890. _showDataArr = [NSMutableArray array];
  891. }
  892. return _showDataArr;
  893. }
  894. - (NSMutableArray *)countryDataArr{
  895. if(!_countryDataArr){
  896. _countryDataArr = [NSMutableArray array];
  897. }
  898. return _countryDataArr;
  899. }
  900. - (MOScrollMenuView *)followTypeView{
  901. if(!_followTypeView){
  902. CGFloat width = SCREENWIDTH - 15.0 * 2.0;
  903. _followTypeView = [[MOScrollMenuView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 24.0)];
  904. MOCountryList *firstModel = [[MOCountryList alloc] init];
  905. firstModel.name = NSLocalString(@"mimo_Anchor_Live");
  906. firstModel.icon = @"";
  907. // MOCountryList *secondModel = [[MOCountryList alloc] init];
  908. // secondModel.name = NSLocalString(@"mimo_Anchor_Party");
  909. // secondModel.icon = @"";
  910. // _followTypeView.titleArray = @[firstModel,secondModel];
  911. _followTypeView.titleArray = @[firstModel];
  912. }
  913. return _followTypeView;
  914. }
  915. - (MOFollowInfoView *)followInfoView{
  916. if(!_followInfoView){
  917. _followInfoView = [MOFollowInfoView moFollowInfoView];
  918. }
  919. return _followInfoView;
  920. }
  921. - (MOFollowNoDataView *)followNoData{
  922. if(!_followNoData){
  923. _followNoData = [MOFollowNoDataView moFollowNoDataView];
  924. _followNoData.backgroundColor = [UIColor clearColor];
  925. }
  926. return _followNoData;
  927. }
  928. - (MONoMoreDataView *)noMoreDataView{
  929. if(!_noMoreDataView){
  930. _noMoreDataView = [MONoMoreDataView new];
  931. }
  932. return _noMoreDataView;
  933. }
  934. - (UIView *)bgView{
  935. if(!_bgView){
  936. _bgView = [[UIView alloc] init];
  937. _bgView.backgroundColor = [UIColor clearColor];
  938. }
  939. return _bgView;
  940. }
  941. - (MOScrollMenuView *)countryView{
  942. if(!_countryView){
  943. CGFloat width = SCREENWIDTH - 15.0 * 2.0;
  944. _countryView = [[MOScrollMenuView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 24.0)];
  945. MOCountryList *firstModel = [[MOCountryList alloc] init];
  946. firstModel.name = NSLocalString(@"mimo_hot_recommend");
  947. firstModel.icon = @"";
  948. _countryView.titleArray = @[firstModel];
  949. }
  950. return _countryView;
  951. }
  952. - (BigBtn *)allCountryBtn{
  953. if (!_allCountryBtn)
  954. {
  955. _allCountryBtn = [BigBtn buttonWithType:UIButtonTypeCustom];
  956. _allCountryBtn.backgroundColor = [UIColor clearColor];
  957. _allCountryBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
  958. _allCountryBtn.imageView.layer.masksToBounds = YES;
  959. [_allCountryBtn setImage:[UIImage imageNamed:@"icon_square_more_back"] forState:UIControlStateNormal];
  960. [_allCountryBtn addTarget:self action:@selector(allCountryBtnClick) forControlEvents:UIControlEventTouchUpInside];
  961. }
  962. return _allCountryBtn;
  963. }
  964. - (void)allCountryBtnClick{
  965. [self showCountryMoreView];
  966. }
  967. - (void)showCountryMoreView{
  968. if(self.countryDataArr.count == 0){
  969. return;
  970. }
  971. WEAKSELF
  972. MOMoreCountryView *view = [MOMoreCountryView moMoreCountryView];
  973. NSArray *tempArr = [self.countryDataArr mutableCopy];
  974. for (MOCountryList *model in tempArr) {
  975. model.isChoose = NO;
  976. }
  977. MOCountryList *chooseModel = tempArr[self.countryView.currentButtonIndex];
  978. chooseModel.isChoose = YES;
  979. view.dataArr = tempArr;
  980. UIWindow *keyWindow = kKeyWindow;
  981. [keyWindow addSubview:view];
  982. [view showMoreCountryView];
  983. view.clickBlock = ^(MOCountryList * _Nonnull listModel, NSIndexPath * _Nonnull indexPath) {
  984. weakSelf.countryView.currentButtonIndex = indexPath.row;
  985. __strong typeof(weakSelf) self = weakSelf;
  986. if(indexPath.row == 0){
  987. //推荐
  988. self.countryString = @"";
  989. }
  990. else{
  991. self.countryString = listModel.id;
  992. }
  993. //第一次位空字符串
  994. self.next = @"";
  995. //视频直播
  996. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  997. NSDictionary *baseDict = @{@"searchType":@(self.searchType),
  998. @"country":self.countryString,
  999. @"page":basePage};
  1000. [self getHttpDataWithDict:baseDict];
  1001. };
  1002. }
  1003. @end