| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- //
- // HMHotViewController.m
- // BuguLive
- //
- // Created by xfg on 2017/7/5.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "HMHotViewController.h"
- #import "HMHotModel.h"
- #import "HMHotTableViewCell.h"
- #import "SDCycleScrollView.h"
- #import "ChooseAreaCell.h"
- #import "AdJumpViewModel.h"
- #import "PublishLivestViewController.h"
- #import "AgreementViewController.h"
- #import "SChooseAreaView.h"
- // 这样子写主要是为了方便拓展
- typedef NS_ENUM(NSInteger, HMHotViewSections)
- {
- HMHotViewSectionsBanner, // 广告栏
- HMHotViewSectionsArea, // 地区选择
- HMHotViewSectionsLiveItem, // 直播项
- };
- static NSString *const cellReuseIdentifier0 = @"cellReuseIdentifier0";
- static NSString *const cellReuseIdentifier1 = @"cellReuseIdentifier1";
- // 广告图默认滚动时间
- static float const bannerAutoScrollTimeInterval = 7;
- @interface HMHotViewController () <SDCycleScrollViewDelegate, HMHotTableViewCellDelegate, UITableViewDelegate, UITableViewDataSource>
- {
-
- ChooseAreaCell *_chooseAreaCell;
- }
- @property (nonatomic, strong) NSMutableArray *mainDataMArray;
- @property (nonatomic, strong) HMHotModel *hotModel;
- @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
- @property (nonatomic, assign) BOOL canClickItem; // 防止视频列表被重复点击
- @end
- @implementation HMHotViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:NO];
- }
- - (void)initFWVariables
- {
- [super initFWVariables];
-
- self.canClickItem = YES;
- }
- - (void)initFWUI
- {
- [super initFWUI];
-
- self.view.backgroundColor = kBackGroundColor;
-
- CGRect tmpFrame;
- if (_tableViewFrame.size.height)
- {
- tmpFrame = _tableViewFrame;
- }
- else
- {
- tmpFrame = CGRectMake(0, 0, kScreenW, self.view.frame.size.height);
- }
- self.tableView = [[UITableView alloc] initWithFrame:tmpFrame];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = kBackGroundColor;
- [self.view addSubview:self.tableView];
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.tableView registerNib:[UINib nibWithNibName:@"ChooseAreaCell" bundle:nil] forCellReuseIdentifier:cellReuseIdentifier1];
- [self.tableView registerNib:[UINib nibWithNibName:@"HMHotTableViewCell" bundle:nil] forCellReuseIdentifier:cellReuseIdentifier];
-
- // 话题页相关
- if (![BGUtils isBlankString:self.topicName])
- {
- self.navigationItem.title = self.topicName;
- }
- if (![BGUtils isBlankString:self.cate_id])
- {
- [self initJoinTopicView];
- [self setupBackBtnWithBlock:nil];
- }
- }
- - (void)initFWData
- {
- [super initFWData];
-
- [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(headerRefresh) footerRereshAction:nil];
-
- // 刷新该页面(主要为了删除最新页已经退出的直播间)
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHome:) name:kRefreshHomeItem object:nil];
- }
- - (void)refreshHome:(NSNotification *)noti
- {
- if (noti)
- {
- NSDictionary *tmpDict = (NSDictionary *)noti.object;
- NSString *room_id = [tmpDict toString:@"room_id"];
-
- @synchronized (self.mainDataMArray)
- {
- NSMutableArray *tmpArray = self.mainDataMArray;
- for (HMHotItemModel *model in tmpArray)
- {
- if (model.room_id == [room_id intValue])
- {
- [tmpArray removeObject:model];
- self.mainDataMArray = tmpArray;
- [_tableView reloadData];
- return;
- }
- }
- }
- }
- }
- - (void)headerRefresh
- {
- [self loadDataFromNet:1];
- }
- - (void)initBanner
- {
- if (!_cycleScrollView)
- {
- // 网络加载 创建带标题的图片轮播器
- self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenW, [self bannerHeight]) delegate:self placeholderImage:nil];
- self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
- self.cycleScrollView.currentPageDotColor = kAppMainColor; // 自定义分页控件小圆标颜色
- self.cycleScrollView.autoScrollTimeInterval = bannerAutoScrollTimeInterval;
- self.cycleScrollView.backgroundColor = kWhiteColor;
- }
-
- NSMutableArray *tmpMArray = [NSMutableArray array];
- for (HMHotBannerModel *bannerModel in self.hotModel.banner)
- {
- [tmpMArray addObject:bannerModel.image];
- }
-
- // 加载延迟
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- self.cycleScrollView.imageURLStringsGroup = tmpMArray;
-
- });
- }
- #pragma mark 点击图片回调
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
- {
- HMHotBannerModel *hotBannerModel = [self.hotModel.banner objectAtIndex:index];
- if ([AdJumpViewModel adToOthersWith:hotBannerModel])
- {
- [[AppDelegate sharedAppDelegate]pushViewController:[AdJumpViewModel adToOthersWith:hotBannerModel] animated:YES];
- }
- }
- - (CGFloat)bannerHeight
- {
- if (self.hotModel.banner)
- {
- if ([self.hotModel.banner count])
- {
- HMHotBannerModel *bannerModel = [self.hotModel.banner firstObject];
- return bannerModel.bannerHeight;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
- }
- #pragma mark 加载热门页数据
- - (void)loadDataFromNet:(int)page
- {
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"index" forKey:@"ctl"];
- [parmDict setObject:@"index" forKey:@"act"];
-
- if (![BGUtils isBlankString:_sexString])
- {
- [parmDict setObject:_sexString forKey:@"sex"];
- }
- if (![BGUtils isBlankString:_areaString])
- {
- [parmDict setObject:_areaString forKey:@"city"];
- }
- if (![BGUtils isBlankString:self.cate_id])
- {
- [parmDict setObject:self.cate_id forKey:@"cate_id"];
- }
-
- [parmDict setObject:@(page) forKey:@"p"];
-
- FWWeakify(self)
-
- [NetWorkManager asyncPostWithParameters:parmDict successBlock:^(NSDictionary *responseJson, AppNetWorkModel *netWorkModel) {
-
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- self.hotModel = [HMHotModel mj_objectWithKeyValues:responseJson];
- self.mainDataMArray = self.hotModel.list;
- [self initBanner];
- [self.tableView reloadData];
- }
-
- [BGMJRefreshManager endRefresh:self.tableView];
-
- } failureBlock:^(NSError *error, AppNetWorkModel *netWorkModel) {
-
- FWStrongify(self)
- [BGMJRefreshManager endRefresh:self.tableView];
-
- }];
- }
- #pragma mark - Table view data source
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- if (section == 2)
- {
- return kDefaultMargin;
- }
- else
- {
- return 0;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- if (section == 2)
- {
- UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kDefaultMargin)];
- tmpView.backgroundColor = kClearColor;
- return tmpView;
- }
- else
- {
- return nil;
- }
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- if (!_hotModel)
- {
- return 0;
- }
- else
- {
- return 3;
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (section == HMHotViewSectionsBanner)
- {
- if (![BGUtils isBlankString:self.cate_id])
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- else if (section == HMHotViewSectionsArea)
- {
- if (![BGUtils isBlankString:self.cate_id])
- {
- return 0;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- return [self.mainDataMArray count];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == HMHotViewSectionsBanner)
- {
- return [self bannerHeight];
- }
- else if (indexPath.section == HMHotViewSectionsArea)
- {
- return 44;
- }
- else
- {
- if ([self.mainDataMArray count])
- {
- HMHotItemModel *itemModel = self.mainDataMArray[indexPath.row];
- if ([itemModel.title isEqualToString:@""])
- {
- return kScreenW + 70;
- }
- else
- {
- return kScreenW + 110;
- }
- }
- else
- {
- return 0;
- }
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == HMHotViewSectionsBanner)
- {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier0];
- if (!cell)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier0];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- [cell.contentView addSubview:self.cycleScrollView];
- return cell;
- }
- else if (indexPath.section == HMHotViewSectionsArea)
- {
- _chooseAreaCell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier1 forIndexPath:indexPath];
- _chooseAreaCell.selectionStyle = UITableViewCellSelectionStyleNone;
- if ([BGUtils isBlankString:_areaString])
- {
- _chooseAreaCell.areaLabel.text = ASLocalizedString(@"热门");
- }
- else
- {
- _chooseAreaCell.areaLabel.text = _areaString;
- }
- return _chooseAreaCell;
- }
- else
- {
- HMHotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier forIndexPath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.delegate = self;
- if ([self.mainDataMArray count] > indexPath.row)
- {
- HMHotItemModel *tmpModel = [self.mainDataMArray objectAtIndex:indexPath.row];
- [cell initWidthModel:tmpModel rowIndex:indexPath.row];
- }
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == HMHotViewSectionsArea)
- {
- //if need,could to do
- }
- else if (indexPath.section == HMHotViewSectionsLiveItem)
- {
- if ([self.mainDataMArray count] > indexPath.row)
- {
- HMHotItemModel *tmpModel = [self.mainDataMArray objectAtIndex:indexPath.row];
- [self joinLivingRoom:tmpModel];
- }
- }
- }
- - (void)changeClickState
- {
-
- }
- #pragma mark 加入直播间
- - (void)joinLivingRoom:(HMHotItemModel *)model
- {
- // 防止重复点击
- if (self.canClickItem)
- {
- self.canClickItem = NO;
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- self.canClickItem = YES;
-
- });
- }
- else
- {
- return;
- }
-
- if (![BGUtils isNetConnected])
- {
- return;
- }
- // model 转为 dic
- NSDictionary *dic = model.mj_keyValues;
- // 直播管理中心开启观众直播
- BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
- [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofPramaDic:dic.mutableCopy isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
- }];
- }
- #pragma mark - ----------------------- 代理 -----------------------
- #pragma mark 热门搜索的代理
- - (void)sentAreaWithName:(NSString *)name andType:(NSString *)typeString
- {
- _chooseAreaCell.areaLabel.text = name;
- NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
- [dict setObject:name forKey:@"name"];
- [dict setObject:typeString forKey:@"sexType"];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"updateTitleName" object:dict];
- _areaString = name;
- _sexString = typeString;
- [self loadDataFromNet:1];
- }
- /**
- 点击跳转到话题
-
- @param rowIndex 当前行的下标
- */
- - (void)pushToTopic:(NSInteger)rowIndex
- {
- // if ([self.mainDataMArray count] > rowIndex)
- // {
- // HMHotItemModel *tmpModel = [self.mainDataMArray objectAtIndex:rowIndex];
- // HMHotViewController *tmpController = [[HMHotViewController alloc]init];
- // tmpController.topicName = tmpModel.title;
- // tmpController.cate_id = tmpModel.cate_id;
- // [[AppDelegate sharedAppDelegate] pushViewController:tmpController];
- // }
- }
- /**
- 点击用户头像
-
- @param rowIndex 当前行的下标
- */
- - (void)clickUserIcon:(NSInteger)rowIndex
- {
- if ([self.delegate respondsToSelector:@selector(goToMainPage:)])
- {
- if ([self.mainDataMArray count] > rowIndex)
- {
- HMHotItemModel *tmpModel = [self.mainDataMArray objectAtIndex:rowIndex];
- [self.delegate goToMainPage:tmpModel.user_id];
- }
- }
- }
- #pragma mark - ----------------------- 其他 -----------------------
- #pragma mark 话题点击按钮
- - (void)initJoinTopicView
- {
- UIImageView *jionView = [UIImageView imageViewWithImage:[UIImage imageNamed:@"ic_create_topic_room"]];
- jionView.frame = CGRectMake((kScreenW - 50) / 2, kScreenH - 180, 50, 50);
- jionView.layer.cornerRadius = 25;
- jionView.layer.masksToBounds = YES;
- jionView.layer.borderWidth = 0.5;
- jionView.layer.borderColor = kAppBorderColor;
- [self.view addSubview:jionView];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleToTopic)];
- jionView.userInteractionEnabled = YES;
- [jionView addGestureRecognizer:tap];
- }
- #pragma mark 点击事件
- - (void)handleToTopic
- {
- IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
- if (loginParam.isAgree ==1)
- {
- if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
- [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
- return;
- }
-
- PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
- pvc.titleTopic = self.topicName;
-
- [self presentViewController:pvc animated:YES completion:nil];
- }
- else
- {
- loginParam.isAgree = 1;
- [loginParam saveToLocal];
- AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
- BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:agreeVC];
- [self presentViewController:nav animated:YES completion:nil];
- }
- }
- #pragma mark - ----------------------- GET方法 -----------------------
- - (NSMutableArray *)mainDataMArray
- {
- if (!_mainDataMArray)
- {
- _mainDataMArray = [NSMutableArray array];
- }
- return _mainDataMArray;
- }
- @end
|