| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- //
- // VideoViewController.m
- // BuguLive
- //
- // Created by 王珂 on 17/5/2.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "VoiceListViewController.h"
- #import "VideoCollectionViewCell.h"
- #import "HMHotModel.h"
- #import "NewestItemCell.h"
- @interface VoiceListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) NSMutableArray * dataArray;
- @property (nonatomic, strong) UICollectionView * collectionView;
- @property (nonatomic, assign) int page;
- @property (nonatomic, assign) int has_next;
- @property (nonatomic, assign) BOOL canClickItem;
- @property (nonatomic, strong) HMHotModel * videoModel;
- @property (nonatomic, weak) UIScrollView *currentScrollView;
- @end
- @implementation VoiceListViewController
- - (void)addHeaderRefresh {
- __weak __typeof(self) weakSelf = self;
- self.currentScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- __strong __typeof(weakSelf) self = weakSelf;
- [self.currentScrollView.mj_header endRefreshing];
- }];
-
- self.currentScrollView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- NSLog(@"上拉加载");
- [self.currentScrollView.mj_footer endRefreshing];
- [self footerRereshing];
- }];
-
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (NSMutableArray *)dataArray
- {
- if (_dataArray == nil)
- {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- [self createView];
-
-
-
- // [self setNetworing:1];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.navigationController.navigationBar.hidden = YES;
- }
- - (void)createView
- {
- self.view.backgroundColor = kClearColor;
-
- UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc] init] ;
- // CGFloat itemW = (self.viewFrame.size.width-3)/2.0;
- // CGFloat itemH = (self.viewFrame.size.width-3)/2.0;
- // //设置cell的大小
- // flow.itemSize = CGSizeMake(itemW, itemH) ;
- // flow.minimumLineSpacing = 3;
- // flow.minimumInteritemSpacing = 3;
- // flow.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10) ;
- _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flow];
- self.currentScrollView = self.collectionView;
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- _collectionView.backgroundColor = kClearColor;
- // _collectionView.tag = 1107;
- [_collectionView registerNib:[UINib nibWithNibName:@"NewestItemCell" bundle:nil] forCellWithReuseIdentifier:@"NewestItemCell"];
- // [_collectionView registerClass:[NewestItemCell class] forCellWithReuseIdentifier:@"NewestItemCell"];
- [self.view addSubview:_collectionView];
-
- [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
-
- // [BGMJRefreshManager refresh:self.self.collectionView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(refreshFooter)];
- // [BGMJRefreshManager refresh:_collectionView target:self headerRereshAction:@selector(headerReresh) shouldHeaderBeginRefresh:NO footerRereshAction:@selector(footerRereshing)];
- _canClickItem = YES;
-
- [self headerReresh];
- }
- - (void)refreshFooter {
-
- }
- #pragma mark -- 头部刷新
- - (void)headerReresh
- {
- [self setNetworing:1];
- }
- //尾部刷新
- - (void)footerRereshing
- {
- if (_has_next == 1)
- {
- _page ++;
- [self setNetworing:_page];
- }
- else
- {
- // [BGMJRefreshManager endRefresh:_collectionView];
- }
- }
- -(void)setTypes:(NSString *)types
- {
- _types = types;
- [self headerReresh];
- }
- - (void)setNetworing:(int)page
- {
-
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
-
- if(self.types.length > 0)
- {
- if([self.types isEqualToString:@"0"])
- {
- [parmDict setObject:@"index" forKey:@"ctl"];
- [parmDict setObject:@"focus_video" forKey:@"act"];
- }
- else
- {
- [parmDict setObject:@"index" forKey:@"ctl"];
- [parmDict setObject:@"index" forKey:@"act"];
- }
- }
- else
- {
- [parmDict setObject:@"index" forKey:@"ctl"];
- [parmDict setObject:@"classify" forKey:@"act"];
- [parmDict setObject:@(_classified_id) forKey:@"classified_id"];
- }
-
- [parmDict setObject:@"1" forKey:@"is_voice"];
- [parmDict setObject:@(page) forKey:@"p"];
- FWWeakify(self)
- [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
-
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- self.has_next = [responseJson toInt:@"has_next"];
- // self.page = [responseJson toInt:@"page"];
- if (page == 1)
- {
- [self.dataArray removeAllObjects];
- }
-
- if([self.types isEqualToString:@"0"])
- {
- NSMutableArray *array = [NSMutableArray array];
- for (int i=0; i<((NSArray *)responseJson[@"data"]).count; i++) {
- [array addObject:[HMHotItemModel modelWithJSON:((NSArray *)responseJson[@"data"])[i]]];
- }
- // self.videoModel = [HMHotModel mj_objectWithKeyValues:responseJson[@"data"]];
- [self.dataArray addObjectsFromArray:array];
- [self.collectionView reloadData];
- }
- else
- {
- self.videoModel = [HMHotModel mj_objectWithKeyValues:responseJson];
- [self.dataArray addObjectsFromArray:self.videoModel.list];
- [self.collectionView reloadData];
- }
-
-
- }
-
- // [BGMJRefreshManager endRefresh:self.collectionView];
-
- // if (!self.dataArray.count)
- // {
- // [self showNoContentView];
- // }
- // else
- // {
- // [self hideNoContentView];
- // }
-
- } FailureBlock:^(NSError *error) {
-
- FWStrongify(self)
- // [BGMJRefreshManager endRefresh:self.collectionView];
-
- }];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- // VideoCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCollectionViewCell" forIndexPath:indexPath] ;
- // cell.model = self.dataArray[indexPath.item];
- // return cell ;
-
- NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
- cell.backgroundColor = [UIColor whiteColor];
- LivingModel *LModel = _dataArray[indexPath.row];
- [cell setCellContent:LModel Type:1];
- return cell;
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- HMHotItemModel *model = self.dataArray[indexPath.item];
- if(model.password.length > 0)
- {
-
- }
- else
- {
- [self joinLivingRoom:self.dataArray[indexPath.item]];
- return;
- }
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请输入房间密码")preferredStyle:UIAlertControllerStyleAlert];
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.placeholder = ASLocalizedString(@"请输入密码");
- textField.delegate = self;
- textField.keyboardType = UIKeyboardTypeNumberPad;
- }];
- UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertController addAction:actionCacel];
- UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- NSString *password = alertController.textFields.firstObject.text;
- NSString *md5Str = [[NSString md5String:password] uppercaseString];
- //转化为大写
- NSLog(@"%@",md5Str);
-
- if ([md5Str isEqualToString:model.password]) {
- [self joinLivingRoom:self.dataArray[indexPath.item]];
- }else{
- [FanweMessage alertHUD:ASLocalizedString(@"密码不正确")];
- }
- }];
- [alertController addAction:actionConfirm];
- [self presentViewController:alertController animated:YES completion:nil];
-
- }
- #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;
- }
-
-
- if ([IMAPlatform sharedInstance].host)
- {
- TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc]init];
- liveRoom.chatRoomId = model.group_id;
- liveRoom.avRoomId = model.room_id;
- liveRoom.title = [NSString stringWithFormat:@"%d",model.room_id];
- liveRoom.vagueImgUrl = model.head_image;
- liveRoom.is_voice = model.is_voice;
- TCShowUser *showUser = [[TCShowUser alloc]init];
- showUser.uid = model.user_id;
- showUser.avatar = model.head_image;
- showUser.username = model.nick_name;
- liveRoom.host = showUser;
-
- if (model.live_in == FW_LIVE_STATE_ING)
- {
- liveRoom.liveType = FW_LIVE_TYPE_AUDIENCE;
- }
- // else if (model.live_in == FW_LIVE_STATE_RELIVE)
- // {
- // liveRoom.liveType = FW_LIVE_TYPE_RELIVE;
- // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
- // }
-
- if ([LiveCenterManager sharedInstance].itemModel) {
-
- [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLiveRoomNotification" object:nil];
- }
-
- //2020-1-7 小直播变大
- [LiveCenterManager sharedInstance].itemModel=liveRoom;
- BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
- [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:liveRoom modelArr:self.dataArray isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
- }];
- }
- else
- {
- [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
- [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
- } completion:^{
-
- }];
- }
-
-
- // // model 转为 dic
- // NSDictionary *dic = model.mj_keyValues;
- //
- //
- //
- // // 直播管理中心开启观众直播
- // BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
- // [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofPramaDic:dic.mutableCopy isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
- // }];
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- return CGSizeMake((kScreenW-30)/2.0f, (kScreenW-30) / 2.0f + kRealValue(32));
- // return CGSizeMake((kScreenW-30)/2.0f, (kScreenW-30)/2.0f);
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
-
- return 10;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
-
- return 0;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
-
- return UIEdgeInsetsMake(10, 10, 0, 10);
- }
- #pragma mark - GKPageSmoothListViewDelegate
- - (UIScrollView *)listScrollView {
- return self.collectionView;
- }
- - (UIView *)listView {
- return self.view;
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- !self.listScrollViewScrollCallback ? : self.listScrollViewScrollCallback(scrollView);
- }
- - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
- self.listScrollViewScrollCallback = callback;
- }
- - (void)reloadData {
- [self.collectionView reloadData];
- }
- @end
|