| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- //
- // SHomeLiveV.m
- // BuguLive
- //
- // Created by 丁凯 on 2017/8/26.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "SHomeLiveV.h"
- #import "MainLiveTableViewCell.h"
- @implementation SHomeLiveV
- - (instancetype)initWithFrame:(CGRect)frame andUserId:(NSString *)userId
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- self.backgroundColor = kBackGroundColor;
- self.user_id = userId;
- [self creatMainView];
- [self loadNewNetDataWithPage:1];
- [self loadHotNetDataWithPage:1];
- }
- return self;
- }
- - (void)creatMainView
- {
- self.liveTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, kScreenW, self.height)];
- self.liveTableView.backgroundColor = kBackGroundColor;
- self.liveTableView.dataSource = self;
- self.liveTableView.delegate = self;
- self.liveTableView.tableHeaderView = self.newestOrHotView;
- self.liveTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self addSubview:self.liveTableView];
- [self.liveTableView registerNib:[UINib nibWithNibName:@"MainLiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"MainLiveTableViewCell"];
- [BGMJRefreshManager refresh:_liveTableView target:self headerRereshAction:nil footerRereshAction:@selector(footerRereshing)];
- }
- #pragma mark 尾部刷新
- - (void)footerRereshing
- {
- if (_has_next == 1)
- {
- self.currentPage ++;
- if (self.newOrHotType == 0)
- {
- [self loadNewNetDataWithPage:self.currentPage];
- }else
- {
- [self loadHotNetDataWithPage:self.currentPage];
- }
- }else
- {
- [BGMJRefreshManager endRefresh:self.liveTableView];
- return;
- }
- }
- #pragma mark 最新
- - (void)loadNewNetDataWithPage:(int)page
- {
- NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
- [parmDict setObject:@"user" forKey:@"ctl"];
- if (self.user_id)
- {
- [parmDict setObject:self.user_id forKey:@"to_user_id"];
- }
- [parmDict setObject:@"user_review" forKey:@"act"];
- [parmDict setObject:@"0" forKey:@"sort"];
- [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
- FWWeakify(self)
- [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
-
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- self.currentPage = [responseJson toInt:@"page"];
- self.has_next = [responseJson toInt:@"has_next"];
- self.newHotLabel.text = [NSString stringWithFormat:ASLocalizedString(@"共%d个精彩回放"),[responseJson toInt:@"count"]];
- if ([responseJson toInt:@"page"] <= 1)
- {
- [self.newestArray removeAllObjects];
- }
- NSArray *array = [responseJson objectForKey:@"list"];
- if (array)
- {
- if (array.count > 0)
- {
- for (NSDictionary *dict in array)
- {
- SenderModel *model = [SenderModel mj_objectWithKeyValues:dict];
- [self.newestArray addObject:model];
- }
- }
- }
-
- if (!self.newestArray.count)
- {
- [self showNoContentViewOnView:self.liveTableView];
- }else
- {
- [self hideNoContentViewOnView:self.liveTableView];
- }
- [self.liveTableView reloadData];
- }
- [BGMJRefreshManager endRefresh:self.liveTableView];
-
- } FailureBlock:^(NSError *error) {
-
- FWStrongify(self)
- [BGMJRefreshManager endRefresh:self.liveTableView];
-
- }];
- }
- #pragma mark 最热
- - (void)loadHotNetDataWithPage:(int)page
- {
- NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
- [parmDict setObject:@"user" forKey:@"ctl"];
- if (self.user_id)
- {
- [parmDict setObject:self.user_id forKey:@"to_user_id"];
- }
- [parmDict setObject:@"user_review" forKey:@"act"];
- [parmDict setObject:@"1" forKey:@"sort"];
- [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
- FWWeakify(self)
- [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- self.currentPage = [responseJson toInt:@"page"];
- self.has_next = [responseJson toInt:@"has_next"];
- self.newHotLabel.text = [NSString stringWithFormat:ASLocalizedString(@"共%d个精彩回放"),[responseJson toInt:@"count"]];
- if ([responseJson toInt:@"page"] <= 1)
- {
- [self.hotArray removeAllObjects];
- }
- NSArray *array = [responseJson objectForKey:@"list"];
- if (array)
- {
- if (array.count > 0)
- {
- for (NSDictionary *dict in array)
- {
- SenderModel *model = [SenderModel mj_objectWithKeyValues:dict];
- [self.hotArray addObject:model];
- }
- }
- }
- if (self.isCouldLiveData)
- {
- [self.liveTableView reloadData];
- if (self.hotArray.count > 0)
- {
- [self hideNoContentViewOnView:self.liveTableView];
- }else
- {
- [self showNoContentViewOnView:self.liveTableView];
- }
- }
- }
- [BGMJRefreshManager endRefresh:self.liveTableView];
-
- } FailureBlock:^(NSError *error)
- {
- [BGMJRefreshManager endRefresh:self.liveTableView];
- NSLog(@"error==%@",error);
- }];
- }
- #pragma mark -UITableViewDelegate&UITableViewDataSource
- //返回段数
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- //返回行数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (self.newOrHotType == 0)//最新
- {
- return self.newestArray.count;
- }else //最热
- {
- return self.hotArray.count;
- }
- }
- //返回cell高度
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 55*kAppRowHScale;
- }
- //返回单元格
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- int newRow = (int)indexPath.row;
- MainLiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainLiveTableViewCell" forIndexPath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (self.newOrHotType == 0)
- {
- if (indexPath.row < self.newestArray.count)
- {
- SenderModel *model = self.newestArray[newRow];
- [cell creatCellWithModel:model];
- }
- }else
- {
- if (indexPath.row < self.hotArray.count)
- {
- SenderModel *model = self.hotArray[newRow];
- [cell creatCellWithModel:model];
- }
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ([self.BuguLive.liveState.roomId intValue]>0)
- {
- [FanweMessage alert:ASLocalizedString(@"当前有视频正在播放")];
- }
- else
- {
- UserModel *liveModel;
- if (self.newOrHotType == 0)
- {
- if (indexPath.row < self.newestArray.count)
- {
- liveModel = self.newestArray[indexPath.row];
- }
- }else if (self.newOrHotType == 1)
- {
- if (indexPath.row < self.hotArray.count)
- {
- liveModel = self.hotArray[indexPath.row];
- }
- }
- if (self.LDelegate)
- {
- [self.LDelegate goToLiveRoomWithModel:liveModel andView:self];
- }
- }
- }
- #pragma mark 最新和最热的点击事件
- - (void)NHBtnClick:(UIButton *)btn
- {
- for (UIButton *newBtn in self.newestOrHotView.subviews)
- {
- if ([newBtn isKindOfClass:[UIButton class]])
- {
- if (newBtn.tag ==btn.tag)
- {
- [newBtn setTitleColor:kAppGrayColor1 forState:0];
- }else
- {
- [newBtn setTitleColor:kAppGrayColor3 forState:0];
- }
- }
- }
- self.isCouldLiveData = YES;
- self.newOrHotType = (int)btn.tag;
- [self.liveTableView reloadData];
- if (self.newOrHotType == 0)
- {
- [self loadNewNetDataWithPage:1];
- }else
- {
- [self loadHotNetDataWithPage:1];
- }
- }
- #pragma mark 最新和最热的界面
- - (UIView *)newestOrHotView
- {
- if (!_newestOrHotView)
- {
- _newestOrHotView = [[UIView alloc]initWithFrame:CGRectMake(0,0,kScreenW,50)];
- _newestOrHotView.backgroundColor = kBackGroundColor;
-
- [_newestOrHotView addSubview:self.newHotLabel];
- NSArray *array2 = [[NSArray alloc]initWithObjects:ASLocalizedString(@"最新"),ASLocalizedString(@"最热"), nil];
- for (int i= 0; i < 2; i ++)
- {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];;
- button.frame = CGRectMake(kScreenW*3/4+kScreenW*i/8, 0, kScreenW/8, 50);
- [button setTitle:array2[i] forState:0];
- button.titleLabel.font = [UIFont systemFontOfSize:12];
- button.tag = i;
- [button addTarget:self action:@selector(NHBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [_newestOrHotView addSubview:button];
- if (i == self.newOrHotType)
- {
- [button setTitleColor:[UIColor colorWithHexString:@"#887BFF"] forState:0];
- }else
- {
- [button setTitleColor:kAppGrayColor3 forState:0];
- }
- }
- }
- return _newestOrHotView;
- }
- - (UILabel *)newHotLabel
- {
- if (!_newHotLabel)
- {
- _newHotLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenW/3, 49)];
- _newHotLabel.font = [UIFont systemFontOfSize:12];
- _newHotLabel.textColor = kAppGrayColor1;
- }
- return _newHotLabel;
- }
- - (NSMutableArray *)hotArray
- {
- if (!_hotArray)
- {
- _hotArray = [[NSMutableArray alloc]init];
- }
- return _hotArray;
- }
- - (NSMutableArray *)newestArray
- {
- if (!_newestArray)
- {
- _newestArray = [[NSMutableArray alloc]init];
- }
- return _newestArray;
- }
- @end
|