admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//
//  liveOnLineView.m
//  BuWanVideo2.0
//
//  Created by apple on 16/10/26.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "liveOnLineView.h"
 
#import "HotLiveTableViewCell.h"
#import "AllLiveTypeTableViewCell.h"
#import "LiveListTableViewCell.h"
 
#import "WEBViewController.h"
 
#import "liveTopicViewController.h"//直播的专题页面
@interface liveOnLineView()<UITableViewDelegate,UITableViewDataSource>{
    NSMutableArray *_HotLive;//获取热门直播
    NSMutableArray *_AllLiveType;//直播类别
    NSMutableArray *_LiveList;//直播列表
    UITableView *_livetableView;//直播列表
    int nowPage;//最新直播请求多少页
}
 
@end
 
@implementation liveOnLineView
 
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        nowPage = 1;
        if (!_livetableView) {
            _livetableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStyleGrouped];
            _livetableView.delegate=self;
            _livetableView.dataSource=self;
            [_livetableView registerNib:[UINib nibWithNibName:@"HotLiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"HotLiveTableViewCell"];
            [_livetableView registerNib:[UINib nibWithNibName:@"AllLiveTypeTableViewCell" bundle:nil] forCellReuseIdentifier:@"AllLiveTypeTableViewCell"];
            [_livetableView registerNib:[UINib nibWithNibName:@"LiveListTableViewCell" bundle:nil] forCellReuseIdentifier:@"LiveListTableViewCell"];
            
            _livetableView.separatorStyle = UITableViewCellSelectionStyleNone;
            
            //下拉刷新
            _livetableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
                nowPage = 1;
                [self reloadHotLiveData];
            }];
            //上拉加载更多
            _livetableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                [self reloadLiveList];
            }];
            
            [self addSubview:_livetableView];
            [_livetableView.mj_header beginRefreshing];
        }
    }
    
    return self;
}
 
/**
 获取热门直播
 */
-(void)reloadHotLiveData{
    [[YTHNetInterface startInterface] getHotLiveWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            [self reloadAllLiveType];
            
            _HotLive=[[result objectForKey:@"Data"] objectForKey:@"data"];
            
        }else{
            [self reloadAllLiveType];
            NSLog(@"网络连接失败!");
        }
    }];
}
 
/**
 获取直播类别
 */
-(void)reloadAllLiveType{
    [[YTHNetInterface startInterface] getAllLiveTypeWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            [self reloadLiveList];
            
            _AllLiveType=[[result objectForKey:@"Data"] objectForKey:@"data"];
            
        }else{
            [self reloadLiveList];
            NSLog(@"网络连接失败!");
        }
    }];
}
 
/**
 获取直播列表
 */
-(void)reloadLiveList{
    [[YTHNetInterface startInterface] getLiveListWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withPage:[NSString stringWithFormat:@"%d",nowPage] WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            if (nowPage == 1) {
                _LiveList=[[result objectForKey:@"Data"] objectForKey:@"data"];
            }else{
                NSMutableArray *tempArr=[NSMutableArray arrayWithCapacity:0];
                tempArr=[[result objectForKey:@"Data"] objectForKey:@"data"];
                [_LiveList addObjectsFromArray:tempArr];
            }
            
            ++nowPage;
            //刷新
            [_livetableView reloadData];
            
            [_livetableView.mj_header endRefreshing];
            [_livetableView.mj_footer endRefreshing];
        }else{
            [_livetableView.mj_header endRefreshing];
            [_livetableView.mj_footer endRefreshing];
            NSLog(@"网络连接失败!");
        }
    }];
}
 
/**
 统计直播点击
 */
-(void)addStatisticsPostWithType:(NSString *)Type WithRoomId:(NSString *)RoomId{
    [[YTHNetInterface startInterface] addStatisticsWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithType:Type WithRoomId:RoomId WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSLog(@"统计上传成功!");
        }
    }];
}
 
/**
 *  返回当前视图的控制器
 */
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}
 
#pragma mark -UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        HotLiveTableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"HotLiveTableViewCell" forIndexPath:indexPath];
        cell1.cellData=_HotLive;
        cell1.backgroundColor=[UIColor whiteColor];
        cell1.clickIndexpath = ^(NSIndexPath *index) {
            WEBViewController *webVC=[[WEBViewController alloc] init];
            webVC.url=[_HotLive[index.row] objectForKey:@"H5Url"];
            webVC.orMake=UIInterfaceOrientationMaskPortrait;
            [[self viewController] presentViewController:webVC animated:YES completion:^{
                
            }];
        };
        return cell1;
    }else if (indexPath.section == 1){
        AllLiveTypeTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"AllLiveTypeTableViewCell" forIndexPath:indexPath];
        cell2.cellData=_AllLiveType;
        cell2.backgroundColor=[UIColor whiteColor];
        cell2.clickIndexpath = ^(NSIndexPath *index) {
            
            
            liveTopicViewController *liveTopicView=[[liveTopicViewController alloc] init];
            liveTopicView.titleStr=[_AllLiveType[index.row] objectForKey:@"Name"];
            liveTopicView.type=[_AllLiveType[index.row] objectForKey:@"Id"];
            [[self viewController].navigationController pushViewController:liveTopicView animated:YES];
        };
        
        return cell2;
    }else{
        LiveListTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:@"LiveListTableViewCell" forIndexPath:indexPath];
        cell3.cellData=_LiveList;
        cell3.clickIndexpath = ^(NSIndexPath * index) {
            WEBViewController *webVC=[[WEBViewController alloc] init];
            webVC.url=[_LiveList[index.row] objectForKey:@"H5Url"];
            webVC.orMake=UIInterfaceOrientationMaskPortrait;
            [[self viewController] presentViewController:webVC animated:YES completion:^{
                
            }];
        };
        
        return cell3;
    }
}
 
#pragma mark -UITableViewDelegate
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 40;
    }
    return 10;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 160;
    }else if(indexPath.section==1){
        if (_AllLiveType.count==0) {
            return 0.01;
        }else{
            return 85;
        }
    }else{
        return (_LiveList.count/2)*((KScreenW-8)/2+50);
    }
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==0) {
        UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 40)];
        headerView.backgroundColor=[UIColor whiteColor];
        
        UILabel *headerLabel=[[UILabel alloc] initWithFrame:CGRectMake(13, 0, KScreenW-13, 40)];
        headerLabel.text=@"热门推荐";
        headerLabel.font=[UIFont systemFontOfSize:15];
        headerLabel.textColor=YTHColor(110, 110, 110);
        [headerView addSubview:headerLabel];
        return headerView;
    }
    return nil;
}
 
@end