developer
2023-05-20 c1ffd99c4b60066774eb2c97b31e4aaa014e7f51
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
//
//  IndividualStarController.m
//  BuWanVideo2.0
//
//  Created by weikou2016 on 16/8/18.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "IndividualStarController.h"
#import "Starview.h"
#import "StarmovieCell.h"
#import "XYRDetailViewController.h"
 
@interface IndividualStarController ()<UITableViewDataSource,UITableViewDelegate>{
    UITableView *tableview;
    NSMutableDictionary *data;
    NSMutableArray *movelist;
    int page;
}
 
@end
 
@implementation IndividualStarController
@synthesize data;
 
 
- (void)viewDidLoad {
    [super viewDidLoad];
    //[MobClick beginLogPageView:@"进入单个明星"];
    //初始化界面
    [self initScene];
}
 
-(void)dealloc{
    //[MobClick beginLogPageView:@"退出单个明星"];
}
 
-(void)initScene{
    self.navigationItem.title = @"明星详情";
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]};
    
    //默认加载第一页的数据
    page=1;
    
    //设置背景色
    self.view.backgroundColor = kGlobalBackgroundColor;
    
    //返回按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 32, 32);
    UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = iconBarItem;
    
    //明星个人资料
    Starview * star =[Starview initwithFrame:CGRectMake(10, kNavigationBarH + 10 , self.view.frame.size.width - 20, 100) WithDic:data];
    [self.view addSubview:star];
    
    //计算明星简介内容需要盛放的高度
    float IntroductionHeight = [self getHeightWithStr:star.Production.text WithWidth:KScreenW-130];
    star.ProductionHeight.constant += IntroductionHeight;
    if(IntroductionHeight > 15){
        star.frame = CGRectMake(star.frame.origin.x, star.frame.origin.y, star.frame.size.width, star.frame.size.height+ IntroductionHeight-14);
    }
    //装载作品的视图
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, star.frame.origin.y + star.frame.size.height + 10, self.view.frame.size.width, KScreenH-star.frame.origin.y - star.frame.size.height - 10) style:UITableViewStylePlain];
    tableview.delegate =self;
    tableview.dataSource = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableview.backgroundColor = kGlobalBackgroundColor;
    [self.view addSubview:tableview];
    
    //head
    UIView * ui = [UIView new];
    ui.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
    ui.backgroundColor = kGlobalBackgroundColor;
    
    UILabel *lb = [UILabel new];
    lb.frame = CGRectMake(15, 0, 100, 30);
    lb.text = @"影视列表";
    lb.font = [UIFont systemFontOfSize:14];
    [ui addSubview:lb];
    tableview.tableHeaderView =ui;
    
    //注册cell
    [tableview registerNib:[UINib nibWithNibName:@"StarmovieCell" bundle:nil] forCellReuseIdentifier:@"StarmovieCell"];
    tableview.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self headupdata];
    } ];
    //刷新 并加载数据
    [tableview.mj_header beginRefreshing];
}
 
/**
 *  字符串高度计算
 */
-(float)getHeightWithStr:(NSString*)str WithWidth:(float)width{
    UILabel *lb = [UILabel new];
    lb.text = str;
    lb.numberOfLines = 0;
    lb.font  = [UIFont systemFontOfSize:12];
    CGSize size = [lb sizeThatFits:CGSizeMake(width, MAXFLOAT)];
    return size.height - 15;
}
 
/**
 下拉刷新
 */
-(void)headupdata{
    page = 1;
    [[YTHNetInterface startInterface]getHotStarsVideoWithUid:[YTHsharedManger startManger].Uid withStarId:[data objectForKey:@"Id"] withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            if (movelist==nil) {
                movelist=[NSMutableArray arrayWithCapacity:0];
            }else{
                [movelist removeAllObjects];
            }
            
            movelist = [[result objectForKey:@"Data"]objectForKey:@"data"];
            if (movelist.count>15) {
                tableview.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                    [self footupdata];
                }];
            }
            ++page;
            [tableview reloadData];
        }else{
            NSLog(@"%@",error);
        }
        [tableview.mj_header endRefreshing];
    }];
}
 
 
/**
 *  上拉加载更多
 */
-(void)footupdata{
    [[YTHNetInterface startInterface]getHotStarsVideoWithUid:[YTHsharedManger startManger].Uid withStarId:[data objectForKey:@"Id"] withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            NSArray *newdata = [[result objectForKey:@"Data"]objectForKey:@"data"];
            if (newdata.count>0) {
                if (movelist==nil) {
                    movelist=[NSMutableArray arrayWithCapacity:0];
                }
                if (page==1) {
                    [movelist removeAllObjects];
                }else{
                    ++page;
                }
                for (int i = 0 ; i < newdata.count ; ++i) {
                    [movelist addObject:[newdata objectAtIndex:i]];
                }
                [tableview reloadData];
            }
        }else{
            NSLog(@"%@",error);
        }
        [tableview.mj_footer endRefreshing];
    }];
    
}
 
#pragma mark    UITableViewDataSource   UITableViewDelegate
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return movelist.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    StarmovieCell * cell = [tableView dequeueReusableCellWithIdentifier:@"StarmovieCell"];
    NSDictionary *dic = movelist[indexPath.row];
    [cell.image setYthImageWithURL:[dic objectForKey:@"Hpicture"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    cell.moviename.text = [dic objectForKey:@"Name"];
    cell.grade.text = [NSString stringWithFormat:@"评分%@",[dic objectForKey:@"Score"]];
    float watchnum = ((NSString*)[dic objectForKey:@"WatchCount"]).floatValue;
    if( watchnum+0.1 > 10000){
        cell.play.text = [NSString stringWithFormat:@"%.2f万",watchnum/10000];
    }else{
        cell.play.text = [dic objectForKey:@"WatchCount"];
    }
    
    float Commentnum = ((NSString*)[dic objectForKey:@"CommentCount"]).floatValue;
    if( Commentnum+0.1 > 10000){
        cell.commentnum.text = [NSString stringWithFormat:@"%.2f万",Commentnum/10000];
    }else{
        cell.commentnum.text = [NSString stringWithFormat:@"%.0f",Commentnum];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 85;
}
 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic = movelist[indexPath.row];
    XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
    [YTHsharedManger startManger].preController = self;
    play.modalPresentationStyle = 0;
    play.Model = [XYRVideoInfoModel yy_modelWithDictionary:dic];
    [self presentViewController:play animated:YES completion:^{
        
    }];
}
 
/**
 返回方法
 */
-(void)back:(UIButton*)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
@end