| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204 |
- //
- // MOSquareBaseCollectionView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/7/31.
- //
- #define SetBtnWidthAndHeight 26.0
- //一页的size
- #define kPageSize 30
- #define kCollectionViewLeftAndRight 12.0
- #define kInsertBannerIndex 8
- #define kShowEnterRoomGuideViewKey @"kShowEnterRoomGuideViewKey"
- #import "MOSquareBaseCollectionView.h"
- #import "MOScrollMenuView.h"
- #import "MONoMoreDataView.h"
- #import "MOFollowInfoView.h"
- #import "MOFollowNoDataView.h"
- #import "MOSquareBannerReusableView.h"
- #import "MOLiveCell.h"
- #import "MOShowLivePagesVC.h"
- #import "MOLiveBase.h"
- #import "MOLiveList.h"
- #import "MOCountryBaseData.h"
- #import "MOCountryList.h"
- #import "MOMoreCountryView.h"
- #import "MOThemeManager.h"
- #import "MOMinimizeManager.h"
- #import "MOGuideMaskView.h"
- #import "UIScrollView+Scrollable.h"
- #import "MOLeftAlignedFlowLayout.h"
- @interface MOSquareBaseCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- @property (nonatomic, strong) UIView *bgView;
- /** 国家*/
- @property (nonatomic, strong) MOScrollMenuView *countryView;
- /** 展示所有国家的按钮 */
- @property (nonatomic, strong) BigBtn *allCountryBtn;
- /** 主界面 */
- @property (nonatomic, strong) UICollectionView *collectionView;
- /** 数据源(服务端返回的原数据) */
- @property (nonatomic, strong) NSMutableArray<MOLiveList *> *dataArr;
- /** 数据源(用来显示页面的数据源数组,index == kInsertBannerIndex 的位置插入bannerTag==YES的model) */
- @property (nonatomic, strong) NSMutableArray<MOLiveList *> *showDataArr;
- /** 没有更多的数据视图 */
- @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
- /** 关注界面 - 视频/音频切换view */
- @property (nonatomic, strong) MOScrollMenuView *followTypeView;
- /** follow数据展示View */
- @property (nonatomic, strong) MOFollowInfoView *followInfoView;
- /** 无数据view */
- @property (nonatomic, strong) MOFollowNoDataView *followNoData;
- /** 关注页面数据 */
- @property (nonatomic, strong) MOLiveBase *followInfoData;
- @property (nonatomic, strong) MOSquareBannerReusableView *headView;
- @property (nonatomic, strong) NSArray *bannerArr;
- @property (nonatomic, assign) BOOL isFirstShow;
- /** 国家列表 */
- @property (nonatomic, strong) NSMutableArray *countryDataArr;
- @property (nonatomic, assign) BOOL isProcessingSelection;
- //是否下拉刷新
- @property (nonatomic, assign) BOOL pullRefresh;
- @end
- @implementation MOSquareBaseCollectionView
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame AndIsFollow:(BOOL)follow{
- self = [super initWithFrame:frame];
- if (self)
- {
- self.isFollow = follow;
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
-
- //默认视频直播
- self.searchType = 2;
- self.next = @"";
- self.countryString = @"";
- self.roomType = 1;
- self.sortType = 1;
- self.isNeedWillRefresh = NO;
- self.isFirstShow = NO;
-
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- if(self.isFollow){
- // [self.bgView addSubview:self.followTypeView];
- // [self.followTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.bgView);
- // make.left.equalTo(self.bgView).offset(15.0);
- // make.height.equalTo(@24.0);
- // make.right.equalTo(self.bgView).offset(-15.0);
- // }];
-
- [self.bgView addSubview:self.followInfoView];
- [self.followInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(12.0);
- make.left.right.equalTo(self.bgView);
- make.height.equalTo(@26.0);
- }];
-
- // [self.bgView addSubview:self.followNoData];
- // [self.followNoData mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.bgView).offset(12.0);
- // make.left.right.equalTo(self.bgView);
- // make.height.equalTo(@180.0);
- // }];
-
- [self.bgView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.followInfoView.mas_bottom).offset(15.0);
- make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
- make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
- make.bottom.equalTo(self.bgView);
- }];
-
- [self setFollowTypeChooseBlock];
- }
- else{
- [self.bgView addSubview:self.countryView];
- [self.countryView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgView).offset(0.0);
- make.left.equalTo(self.bgView).offset(15.0);
- // make.height.equalTo(@24.0);
- make.right.equalTo(self.bgView).offset(-15.0 - 30);
- make.height.mas_equalTo(0);
- }];
-
- [self.bgView addSubview:self.allCountryBtn];
- [self.allCountryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.bgView).offset(-13.0);
- // make.width.height.equalTo(@24.0);
- make.width.height.mas_equalTo(0);
- make.centerY.equalTo(self.countryView.mas_centerY);
- }];
-
- [self.bgView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.countryView.mas_bottom).offset(15.0);
- make.top.mas_equalTo(0);
- make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
- make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
- make.bottom.equalTo(self.bgView);
- }];
- self.collectionView.backgroundView = self.noMoreDataView;
- }
- }
- - (void)updateFollowViewUI{
- if(self.followInfoData.recommend){
- //推荐数据
- self.followInfoView.hidden = YES;
- [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
- make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
- make.bottom.equalTo(self.bgView);
- }];
-
- [UIView animateWithDuration:0.3 animations:^{
- [self layoutIfNeeded];
- }];
- }
- else{
- self.followInfoView.hidden = NO;
- [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.followInfoView.mas_bottom).offset(15.0);
- make.left.equalTo(self.bgView).offset(kCollectionViewLeftAndRight);
- make.right.equalTo(self.bgView).offset(-kCollectionViewLeftAndRight);
- make.bottom.equalTo(self.bgView);
- }];
-
- [UIView animateWithDuration:0.3 animations:^{
- [self layoutIfNeeded];
- }];
- self.followInfoView.contentLab.text = [NSString stringWithFormat:@"%.f %@",self.followInfoData.liveCount,NSLocalString(@"mimo_square_following_people_num")];
-
- }
- }
- #pragma mark - Block
- - (void)setFollowTypeChooseBlock{
- WEAKSELF
- self.followTypeView.clickBtnBlock = ^(NSInteger index) {
- __strong typeof(weakSelf) self = weakSelf;
-
- if(index == 0){
- self.roomType = 1;
- }
- else{
- self.roomType = 2;
- }
-
- //第一次位空字符串
- self.next = @"";
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"roomType":@(self.roomType),
- @"sortType":@(self.sortType),
- @"page":basePage};
- [self toGetHttpFollowDataWithDict:baseDict];
- };
- }
- - (void)setCountryChooseBlock{
-
- self.countryView.titleArray = [self.countryDataArr copy];
- self.countryView.currentButtonIndex = 0;
-
- WEAKSELF
- self.countryView.clickBtnBlock = ^(NSInteger index) {
-
- __strong typeof(weakSelf) self = weakSelf;
-
- MOCountryList *countryModel = self.countryDataArr[index];
- if(index == 0){
- //推荐
- self.countryString = @"";
- }
- else{
- self.countryString = countryModel.id;
- }
-
- //第一次位空字符串
- self.next = @"";
- //视频直播
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"searchType":@(self.searchType),
- @"category":self.countryString ?: @"",
- @"page":basePage};
- [self getHttpDataWithDict:baseDict];
- };
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (void)listWillAppear{
-
- if(self.dataArr.count == 0){
- if(self.isFollow){
- //关注列表数据
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"roomType":@(self.roomType),
- @"sortType":@(self.sortType),
- @"page":basePage};
- [self toGetHttpFollowDataWithDict:baseDict];
- }
- else{
-
- if(self.dataArr.count == 0){
- //第一次位空字符串 (代表第一页)
- self.next = @"";
-
- //视频直播
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"searchType":@(self.searchType),
- @"category":self.countryString ?: @"",
- @"page":basePage};
- [self getHttpDataWithDict:baseDict];
- }
-
- if(self.bannerArr.count == 0){
- if(self.searchType == 2){
- //视频直播
- [self getSquareBannerListDataWith:1];
- }
- else if (self.searchType == 3){
- //音频直播
- [self getSquareBannerListDataWith:6];
- }
- else if (self.searchType == 4){
- //新人
- [self getSquareBannerListDataWith:3];
- }
- }
- }
- }
-
- //获取国家列表
- if(!self.isFollow){
- if(self.countryDataArr.count == 0){
- [self getHttpDataAboutCategroy];
- }
-
- //国家列表数据缓存
- if([MOSvgaSourceManage shareManager].countryArr.count == 0){
- [self getHttpDataAboutCountry];
- }
- }
-
- }
- - (UIView *)listView{
- return self;
- }
- #pragma mark - Mothed
- - (void)toBeginRefresh{
- [self.collectionView.mj_header beginRefreshing];
- }
- - (void)showEnterRoomGuideView {
- if (self.dataArr.count == 0) {
- return;
- }
-
- NSIndexPath *firstIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
- UICollectionViewCell *firstCell = [self.collectionView cellForItemAtIndexPath:firstIndexPath];
- if (firstCell) {
- CGRect cellFrameInWindow = [firstCell convertRect:firstCell.bounds toView:[UIApplication sharedApplication].keyWindow];
- // 扩大四边各 5pt
- CGRect holeRect = CGRectInset(cellFrameInWindow, -5, -5);
- [self showGuideMaskWithHoleInRect:holeRect];
- }
- }
- - (void)showGuideMaskWithHoleInRect:(CGRect)holeRect {
- if (!self.window) {//view没显示不弹出气泡
- return;
- }
-
- NSString *showKey = (NSString *)[[MODataCache sharedYYCache] objectForKey:kShowEnterRoomGuideViewKey];
- if (showKey.length > 0) {//已经显示过了,不再显示
- return;
- }
-
- MOGuideMaskView *guideView = [[MOGuideMaskView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- [guideView addHoleWithRect:holeRect cornerRadius:16];
- [guideView show];
- [[MODataCache sharedYYCache] setObject:kShowEnterRoomGuideViewKey forKey:kShowEnterRoomGuideViewKey];
-
- CGFloat holeCenterX = CGRectGetMidX(holeRect);
- CGFloat bottomY = CGRectGetMaxY(holeRect);
-
- UIView *textView = [[UIView alloc] init];
- textView.backgroundColor = [MOTools colorWithHexString:@"#FF4DA6"];
- textView.layer.masksToBounds = YES;
- textView.layer.cornerRadius = 6;
- [guideView addSubview:textView];
-
- NSString *showText = NSLocalString(@"mimo_2_guide_select_host");
- UIFont *showFont = [MOTextTools poppinsMediumFont:12];
-
- CGFloat textWidth = [MOTools getWidthWithString:showText font:showFont];
- CGFloat viewWidth = textWidth + 12;
- [textView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(bottomY + 59);
- make.centerX.equalTo(guideView.mas_left).offset(holeCenterX);
- make.size.mas_equalTo(CGSizeMake(viewWidth, 24));
- }];
-
- UIView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_left"]];
- [guideView addSubview:leftView];
- [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(textView.mas_left);
- make.centerY.equalTo(textView.mas_top);
- make.size.mas_equalTo(CGSizeMake(24, 19));
- }];
-
- UIView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_right"]];
- [guideView addSubview:rightView];
- [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(textView);
- make.bottom.equalTo(textView.mas_top);
- make.size.mas_equalTo(CGSizeMake(10, 10));
- }];
-
- UILabel *textLabel = [[UILabel alloc] init];
- textLabel.font = showFont;
- textLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- textLabel.text = showText;
- [textView addSubview:textLabel];
- [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(0);
- }];
-
- UIImageView *lineView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_line_up"]];
- [guideView addSubview:lineView];
- [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(bottomY + 2);
- make.centerX.equalTo(guideView.mas_left).offset(holeCenterX);
- make.size.mas_equalTo(CGSizeMake(10, 58));
- }];
-
- UIView *arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_guilde_arrow_up"]];
- [guideView addSubview:arrowView];
- [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(textView.mas_top).offset(1);
- make.centerX.equalTo(lineView);
- make.size.mas_equalTo(CGSizeMake(11, 6));
- }];
- }
- #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.showDataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- WEAKSELF
- MOLiveList *model;
-
- //因为牵扯Follow逻辑, 容易出现数组越界崩溃, 先这样处理
- if(indexPath.row < self.showDataArr.count){
- model = self.showDataArr[indexPath.row];
- if (model.bannerTag) {
- MOSquareBannerReusableView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOSquareBannerReusableView_ID forIndexPath:indexPath];
- cell.imageArr = self.bannerArr;
- return cell;
- } else {
- MOLiveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOLiveCell_ID forIndexPath:indexPath];
- cell.model = model;
-
- //更多按钮点击事件
- cell.moreBtnBlock = ^(MOLiveList * _Nonnull model) {
- for (MOLiveList *object in weakSelf.dataArr) {
- if([object.id isEqualToString:model.id]){
- object.isViewSelect = YES;
- }
- }
- };
-
- cell.cancelBtnBlock = ^(MOLiveList * _Nonnull model) {
- for (MOLiveList *object in weakSelf.dataArr) {
- if([object.id isEqualToString:model.id]){
- object.isViewSelect = NO;
- }
- }
- };
-
- __weak __typeof__(cell) weakCell = cell;
- cell.noLikeBlock = ^(MOLiveList * _Nonnull model) {
- NSIndexPath *newIndexPath = [weakSelf.collectionView indexPathForCell:weakCell];
- if(weakSelf.showDataArr.count > newIndexPath.row){
- MOLiveList *liveModel = [weakSelf.showDataArr objectAtIndex:newIndexPath.row];
- [weakSelf.showDataArr removeObject:liveModel];
- [weakSelf.collectionView performBatchUpdates:^{
- [weakSelf.collectionView deleteItemsAtIndexPaths:@[newIndexPath]];
- } completion:^(BOOL finished) {
- [weakSelf.dataArr removeObject:liveModel];
- [weakSelf handleDataAndReloadCollectionViewData];
- }];
- }
- };
- return cell;
- }
- }
-
- return [collectionView dequeueReusableCellWithReuseIdentifier:MOLiveCell_ID forIndexPath:indexPath];
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (self.isProcessingSelection) {
- return;
- }
- self.isProcessingSelection = YES;
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- if(!self.homeVC){
- return;
- }
-
- [MOShowAgoraKitManager shareManager].isFirstShow = YES;
- [MOShowAgoraKitManager shareManager].beginIndex = indexPath.row;
- [MOShowAgoraKitManager shareManager].isCreatLive = NO;
-
- MOLiveList *model = self.showDataArr[indexPath.row];
- //TODO: 进入直播房
- MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
- vc.userType = MOShowLiveAudienceType;
- vc.roomList = [self.dataArr mutableCopy];
- vc.searchType = self.searchType;
- vc.next = self.next;
- vc.countryString = self.countryString;
- vc.roomType = self.roomType;
- vc.sortType = self.sortType;
- NSInteger index = 0;
-
- int x = 0;
- for (MOLiveList *listModel in self.dataArr) {
- if([listModel.id isEqualToString:model.id]){
- index = x;
- }
- x ++;
- }
-
- vc.focusIndex = index;
-
- WEAKSELF
- vc.deleteCloseRoomBlock = ^(NSString * _Nonnull roomId) {
-
- if(roomId.length == 0){
- return;
- }
-
- BOOL isHave = NO;
- NSInteger theRow = 0;
- for (MOLiveList *listModel in weakSelf.dataArr) {
- if([roomId isEqualToString:listModel.id]){
- isHave = YES;
- break;
- }
- theRow ++;
- }
-
- if(isHave == YES){
- NSIndexPath *theIndexPath = [NSIndexPath indexPathForRow:theRow inSection:0];
- [weakSelf.showDataArr removeObjectAtIndex:theRow];
- [weakSelf handleDataAndReloadCollectionViewData];
- }
- };
-
- //关闭直播间的回调
- vc.closeRoomBlock = ^{
- NSArray *checkArr = [MOShowAgoraKitManager getSurroundingElementsWith:weakSelf.dataArr Range:10];
- [[MOShowAgoraKitManager shareManager] toCheckTheLiveRoomWithRoomListArr:checkArr andBlock:^(NSArray * _Nonnull closeArr) {
-
- NSMutableArray *deleteIndexArr = [NSMutableArray array];
-
- // 创建一个可变的NSIndexSet,用于添加不连续的索引
- NSMutableIndexSet *indexesToRemove = [NSMutableIndexSet indexSet];
-
- for (int x = 0; x < weakSelf.dataArr.count; x ++) {
- MOLiveList *liveModel = weakSelf.dataArr[x];
-
- NSString *roomIdStr = liveModel.id;
-
- if([closeArr containsObject:roomIdStr]){
- [indexesToRemove addIndex:x];
- }
- }
-
- [weakSelf.dataArr removeObjectsAtIndexes:indexesToRemove];
- [weakSelf handleDataAndReloadCollectionViewData];
- }];
- };
-
- vc.dataChangeBlock = ^(NSString * _Nonnull nextStr, NSMutableArray * _Nonnull roomList) {
- if(nextStr.length == 0){
- //最后一页
- [weakSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
-
- if(roomList.count > weakSelf.dataArr.count){
- weakSelf.dataArr = [roomList mutableCopy];
- [weakSelf handleDataAndReloadCollectionViewData];
- weakSelf.collectionView.mj_footer.hidden = (weakSelf.dataArr.count > 0) ? NO : YES;
- }
- };
-
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
- // nav.modalPresentationStyle = UIModalPresentationFullScreen;
- // [self.homeVC presentViewController:nav animated:YES completion:nil];
- vc.hidesBottomBarWhenPushed = YES;
- [self.homeVC.navigationController pushViewController:vc animated:YES];
-
- self.isNeedWillRefresh = YES;
-
- //重置状态
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.isProcessingSelection = NO;
- });
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
- viewForSupplementaryElementOfKind:(NSString *)kind
- atIndexPath:(NSIndexPath *)indexPath {
- if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
- if (self.isFollow && self.followInfoData.recommend) {
- MOFollowNoDataView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
- withReuseIdentifier:@"MOFollowNoDataView"
- forIndexPath:indexPath];
- headView.backgroundColor = [UIColor clearColor];
- return headView;
- } else {
- // 返回一个空 header 防止崩溃
- UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"sectionHeader" forIndexPath:indexPath];
- return view;
- }
- } else {
- UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot" forIndexPath:indexPath];
- return view;
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
-
- if(self.isFollow && self.followInfoData.recommend){
- return CGSizeMake(SCREENWIDTH, 180);
- }
- return CGSizeMake(SCREENWIDTH, 0.01);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- MOLiveList* model = self.showDataArr[indexPath.row];
- if (model.bannerTag) {
- CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2;
- return CGSizeMake(collectionWidth, 82);
- } else {
- CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2 - 7.0;
- return CGSizeMake(collectionWidth / 2.0 , 229);
- }
- }
- // 开始拖动时隐藏 tabBar
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- if (![scrollView isContentVerticallyScrollable]) {
- return;
- }
- [[MOMainTabController sharedSingleton] hideTabbarWithAnimation:YES];
- if (self.beginScrollBlock) {
- self.beginScrollBlock();
- }
- }
- // 停止滚动时显示 tabBar(包括减速完成)
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- if (![scrollView isContentVerticallyScrollable]) {
- return;
- }
- [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
- }
- // 如果没有减速(立即停止),也要显示 tabBar
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- if (!decelerate) {
- [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
- }
- }
- #pragma mark - Http
- //获取界面数据
- - (void)getHttpDataWithDict:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager getLiveRoomListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
-
- __strong typeof(weakSelf) self = weakSelf;
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- weakSelf.isNeedWillRefresh = NO;
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- MOLiveBase *baseModel = [MOLiveBase modelObjectWithDictionary:data[@"data"]];
- if(baseModel.next == nil || baseModel.next.length == 0){
- if(self.next == nil || self.next.length == 0){
- //第一页
- [self.dataArr removeAllObjects];
- [self toAddNewListDataWith:baseModel.liveList];
- }
- else{
- //最后一页
- [self toAddNewListDataWith:baseModel.liveList];
- }
- self.next = @"";
-
- [self.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- if(self.next == nil || self.next.length == 0){
- //第一页
- [self.dataArr removeAllObjects];
- [self toAddNewListDataWith:baseModel.liveList];
- }
- else{
- //最后一页
- [self toAddNewListDataWith:baseModel.liveList];
- }
- self.next = baseModel.next;
- }
- // [self.collectionView reloadData];
- [self handleDataAndReloadCollectionViewData];
-
- self.collectionView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
- self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
- if (self.dataArr.count > 0) {
- [MOMinimizeManager shareManager].roomList = self.dataArr;
- }
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)toAddNewListDataWith:(NSArray *)liveListArr{
- NSMutableArray *elementsToAdd = [NSMutableArray array];
-
- BOOL isOpen = [MOTools toJudgeShowWame];
-
- for (MOLiveList *listModel in liveListArr) {
- BOOL isElementFound = NO;
-
- // 检查数组A中是否存在相同元素
- for (NSInteger i = 0; i < self.dataArr.count; i++) {
- MOLiveList *elementA = self.dataArr[i];
-
- if([elementA.anchorUser.id isEqualToString:listModel.anchorUser.id]){
- [self.dataArr replaceObjectAtIndex:i withObject:listModel];
- isElementFound = YES;
- break;
- }
- }
-
- if(!isOpen){
- if(listModel.roomType == 2 || listModel.roomType == 3){
- continue;
- }
- }
-
- // 未找到则记录待添加
- if (!isElementFound) {
- [elementsToAdd addObject:listModel];
- }
- }
-
- // 将B中独有的元素添加到A
- [self.dataArr addObjectsFromArray:elementsToAdd];
- }
- - (void)toGetHttpFollowDataWithDict:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager getLiveRoomFollowListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
-
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- self.isNeedWillRefresh = NO;
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- self.followInfoData = [MOLiveBase modelObjectWithDictionary:data[@"data"]];
- if(self.followInfoData.next == nil || self.followInfoData.next.length == 0){
- if(self.next == nil || self.next.length == 0){
- //第一页
- [self.dataArr removeAllObjects];
- [self toAddNewListDataWith:self.followInfoData.liveList];
- }
- else{
- //最后一页
- [self toAddNewListDataWith:self.followInfoData.liveList];
- }
- self.next = @"";
-
- [self.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
-
- if(self.next == nil || self.next.length == 0){
- [self.dataArr removeAllObjects];
- [self toAddNewListDataWith:self.followInfoData.liveList];
- }
- else{
- [self toAddNewListDataWith:self.followInfoData.liveList];
- }
-
- self.next = self.followInfoData.next;
-
- }
- [self handleDataAndReloadCollectionViewData];
- // [self.collectionView reloadData];
- [self updateFollowViewUI];
-
- self.collectionView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
- self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
- if (self.dataArr.count > 0) {
- [MOMinimizeManager shareManager].roomList = self.dataArr;
- }
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)getSquareBannerListDataWith:(NSInteger)type{
- WEAKSELF
- //banner分类(1=首页图片,2=直播间图片,3=New页图片,4=启动页图片,5=开播页图片,6=语音列表图片)
- NSDictionary *dict = @{@"category":@(type)};
- [kHttpManager getBaseBannerListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOBannerData *baseModel = [MOBannerData modelObjectWithDictionary:data[@"data"]];
- weakSelf.headView.imageArr = [baseModel.JumpList copy];
- weakSelf.bannerArr = [baseModel.JumpList copy];
-
- if(!weakSelf.isFirstShow){
- weakSelf.isFirstShow = YES;
- [weakSelf.collectionView reloadData];
- }
-
- }
- else{
- // kShowNetError(data)
- }
- }];
- }
- //获取国家列表
- - (void)getHttpDataAboutCountry{
- WEAKSELF
- [[MOSvgaSourceManage shareManager].countryArr removeAllObjects];
- [kHttpManager getCountryAndRegionListWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
-
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
-
- for (MOCountryList *object in countryBase.countryList) {
- if(object.code.length != 0){
- [[MODataCache sharedYYCache] setObject:object forKey:[NSString stringWithFormat:@"%@_%@",kCountryArrInfo,object.code]];
- }
- }
-
- [MOSvgaSourceManage shareManager].countryArr = [countryBase.countryList mutableCopy];
- // self.countryDataArr = [countryBase.countryList mutableCopy];
- //
- //第一个数据位推荐数据
- MOCountryList *firstModel = [[MOCountryList alloc] init];
- firstModel.name = NSLocalString(@"mimo_hot_recommend");
- firstModel.icon = @"";
- [[MOSvgaSourceManage shareManager].countryArr insertObject:firstModel atIndex:0];
- //
- // [self setCountryChooseBlock];
-
- [self.collectionView reloadData];
- }
- else
- {
- kShowNetError(data)
- }
- }];
- }
- - (void)getHttpDataAboutCategroy{
- WEAKSELF
- [kHttpManager toGetTheLiveRoomCategoryDataWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
-
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
-
- self.countryDataArr = [countryBase.countryList mutableCopy];
-
- //第一个数据位推荐数据
- MOCountryList *firstModel = [[MOCountryList alloc] init];
- firstModel.name = NSLocalString(@"mimo_hot_recommend");
- firstModel.icon = @"";
- [self.countryDataArr insertObject:firstModel atIndex:0];
-
- [self setCountryChooseBlock];
-
- // [self.collectionView reloadData];
- }
- else
- {
- kShowNetError(data)
- }
- }];
- }
- - (void)handleDataAndReloadCollectionViewData {
- self.showDataArr = self.dataArr.mutableCopy;
- if (!self.isFollow) {
- MOLiveList *bannerModel = [[MOLiveList alloc] init];
- bannerModel.bannerTag = YES;
- if (self.showDataArr.count <= kInsertBannerIndex) {
- [self.showDataArr addObject:bannerModel];
- } else {
- [self.showDataArr insertObject:bannerModel atIndex:kInsertBannerIndex];
- }
- }
- [self.collectionView reloadData];
-
- if (self.pullRefresh) {//下拉刷新需要显示tabbar
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[MOMainTabController sharedSingleton] showTabbarWithAnimation:YES];
- self.pullRefresh = NO;
- });
- }
- }
- #pragma mark - Lazy
- - (UICollectionView *)collectionView
- {
- if (!_collectionView)
- {
- CGFloat collectionWidth = SCREENWIDTH - kCollectionViewLeftAndRight * 2 - 7.0;
-
- MOLeftAlignedFlowLayout *layout = [[MOLeftAlignedFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- layout.minimumLineSpacing = 7.0;
- layout.minimumInteritemSpacing = 7.0;
- layout.itemSize = CGSizeMake(collectionWidth / 2.0 , 229);
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, collectionWidth, collectionWidth / 2) collectionViewLayout:layout];
- [_collectionView registerClass:[MOLiveCell class] forCellWithReuseIdentifier:MOLiveCell_ID];
- [_collectionView registerClass:[MOSquareBannerReusableView class] forCellWithReuseIdentifier:MOSquareBannerReusableView_ID];
- [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(MOFollowNoDataView.class) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass(MOFollowNoDataView.class)];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"sectionHeader"];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.backgroundColor = [UIColor clearColor];
-
- WEAKSELF
-
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- __strong typeof(weakSelf) self = weakSelf;
- self.pullRefresh = YES;
- //获取banner数据
- self.next = @"";
- if(self.isFollow){
- //关注列表数据
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"roomType":@(self.roomType),
- @"sortType":@(self.sortType),
- @"page":basePage};
- [weakSelf toGetHttpFollowDataWithDict:baseDict];
- return;
- }
- else{
- if(self.searchType == 2){
- //视频直播
- [self getSquareBannerListDataWith:1];
- }
- else if (self.searchType == 3){
- //音频直播
- [self getSquareBannerListDataWith:6];
- }
- else if (self.searchType == 4){
- //新人
- [self getSquareBannerListDataWith:3];
- }
-
- if(self.countryDataArr.count == 0 && !self.isFollow){
- [self getHttpDataAboutCategroy];
- }
-
- //国家列表数据缓存
- if([MOSvgaSourceManage shareManager].countryArr.count == 0){
- [self getHttpDataAboutCountry];
- }
-
- //视频直播
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next ?: @""};
- NSDictionary *baseDict = @{@"searchType":@(self.searchType),
- @"category":self.countryString ?: @"",
- @"page":basePage};
- [self getHttpDataWithDict:baseDict];
- }
- }];
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.hidden = YES;
-
- _collectionView.mj_header = header;
-
-
- _collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
-
- if(weakSelf.next.length == 0){
- return;
- }
-
- if(weakSelf.isFollow){
- //关注列表数据
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
- NSDictionary *baseDict = @{@"roomType":@(weakSelf.roomType),
- @"sortType":@(weakSelf.sortType),
- @"page":basePage};
- [weakSelf toGetHttpFollowDataWithDict:baseDict];
- return;
- }
- else{
- //视频直播
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
- NSDictionary *baseDict = @{@"searchType":@(weakSelf.searchType),
- @"category":weakSelf.countryString ?: @"",
- @"page":basePage};
- [weakSelf getHttpDataWithDict:baseDict];
- }
- }];
-
- _collectionView.mj_footer.hidden = YES;
- }
- return _collectionView;
- }
- - (NSMutableArray<MOLiveList *> *)dataArr {
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (NSMutableArray<MOLiveList *> *)showDataArr {
- if (!_showDataArr) {
- _showDataArr = [NSMutableArray array];
- }
- return _showDataArr;
- }
- - (NSMutableArray *)countryDataArr{
- if(!_countryDataArr){
- _countryDataArr = [NSMutableArray array];
- }
- return _countryDataArr;
- }
- - (MOScrollMenuView *)followTypeView{
- if(!_followTypeView){
- CGFloat width = SCREENWIDTH - 15.0 * 2.0;
- _followTypeView = [[MOScrollMenuView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 24.0)];
-
- MOCountryList *firstModel = [[MOCountryList alloc] init];
- firstModel.name = NSLocalString(@"mimo_Anchor_Live");
- firstModel.icon = @"";
-
- // MOCountryList *secondModel = [[MOCountryList alloc] init];
- // secondModel.name = NSLocalString(@"mimo_Anchor_Party");
- // secondModel.icon = @"";
-
- // _followTypeView.titleArray = @[firstModel,secondModel];
- _followTypeView.titleArray = @[firstModel];
- }
- return _followTypeView;
- }
- - (MOFollowInfoView *)followInfoView{
- if(!_followInfoView){
- _followInfoView = [MOFollowInfoView moFollowInfoView];
- }
- return _followInfoView;
- }
- - (MOFollowNoDataView *)followNoData{
- if(!_followNoData){
- _followNoData = [MOFollowNoDataView moFollowNoDataView];
- _followNoData.backgroundColor = [UIColor clearColor];
- }
- return _followNoData;
- }
- - (MONoMoreDataView *)noMoreDataView{
- if(!_noMoreDataView){
- _noMoreDataView = [MONoMoreDataView new];
- }
- return _noMoreDataView;
- }
- - (UIView *)bgView{
- if(!_bgView){
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [UIColor clearColor];
- }
- return _bgView;
- }
- - (MOScrollMenuView *)countryView{
- if(!_countryView){
- CGFloat width = SCREENWIDTH - 15.0 * 2.0;
- _countryView = [[MOScrollMenuView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 24.0)];
-
- MOCountryList *firstModel = [[MOCountryList alloc] init];
- firstModel.name = NSLocalString(@"mimo_hot_recommend");
- firstModel.icon = @"";
- _countryView.titleArray = @[firstModel];
- }
- return _countryView;
- }
- - (BigBtn *)allCountryBtn{
- if (!_allCountryBtn)
- {
- _allCountryBtn = [BigBtn buttonWithType:UIButtonTypeCustom];
- _allCountryBtn.backgroundColor = [UIColor clearColor];
- _allCountryBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
- _allCountryBtn.imageView.layer.masksToBounds = YES;
- [_allCountryBtn setImage:[UIImage imageNamed:@"icon_square_more_back"] forState:UIControlStateNormal];
- [_allCountryBtn addTarget:self action:@selector(allCountryBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _allCountryBtn;
- }
- - (void)allCountryBtnClick{
- [self showCountryMoreView];
- }
- - (void)showCountryMoreView{
-
- if(self.countryDataArr.count == 0){
- return;
- }
-
- WEAKSELF
- MOMoreCountryView *view = [MOMoreCountryView moMoreCountryView];
-
- NSArray *tempArr = [self.countryDataArr mutableCopy];
-
- for (MOCountryList *model in tempArr) {
- model.isChoose = NO;
- }
-
- MOCountryList *chooseModel = tempArr[self.countryView.currentButtonIndex];
- chooseModel.isChoose = YES;
-
- view.dataArr = tempArr;
-
- UIWindow *keyWindow = kKeyWindow;
-
- [keyWindow addSubview:view];
- [view showMoreCountryView];
- view.clickBlock = ^(MOCountryList * _Nonnull listModel, NSIndexPath * _Nonnull indexPath) {
-
- weakSelf.countryView.currentButtonIndex = indexPath.row;
-
- __strong typeof(weakSelf) self = weakSelf;
- if(indexPath.row == 0){
- //推荐
- self.countryString = @"";
- }
- else{
- self.countryString = listModel.id;
- }
-
- //第一次位空字符串
- self.next = @"";
- //视频直播
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"searchType":@(self.searchType),
- @"country":self.countryString,
- @"page":basePage};
- [self getHttpDataWithDict:baseDict];
- };
- }
- @end
|