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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//
//  attentionView.m
//  BuWanVideo2.0
//
//  Created by weikou on 16/8/1.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "attentionView.h"
#import "AttentionCell.h"
#import "LoggingViewController.h"
#import "WebControllerView.h"
#import "XYRDetailViewController.h"
 
@interface attentionView()<UITableViewDataSource,UITableViewDelegate>{
    UIImageView * wawa;   //未登录  娃娃
    UIButton * login;     //未登录  登录按钮
    UILabel * Clewlabel;  //未登录  提示文字
    UIView * tishi;       //登陆后提示没有关注
    NSMutableArray * information;    //数据
    int page;
}
 
 
@end
 
 
 
@implementation attentionView
 
@synthesize temp;
@synthesize tableview;
 
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor= kGlobalBackgroundColor;
        
        [self initScene];
    }
    return self;
}
 
-(void)initScene{
    
    wawa = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"登录娃娃"]];
    wawa.frame = CGRectMake(self.frame.size.width / 2 - 140,(self.frame.size.height - 100) /2, 102, 130);
    [self addSubview:wawa];
    
    Clewlabel = [UILabel new];
    Clewlabel.text = @"登陆后,你关注的剧集更新时会立即为你展示在这里.";
    Clewlabel.numberOfLines = 0;
    Clewlabel.textColor = KGlobalLightGreyColor_153;
    Clewlabel.font = [UIFont systemFontOfSize:15];
    Clewlabel.frame = CGRectMake(self.frame.size.width / 2 - 30 , wawa.frame.origin.y + 20, 170, 36);
    [self addSubview:Clewlabel];
    
    login = [UIButton new];
    [login setTitle:@"立即登录" forState:UIControlStateNormal];
    [login setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    login.titleLabel.font = [UIFont systemFontOfSize:17];
    login.frame = CGRectMake(Clewlabel.frame.origin.x + Clewlabel.frame.size.width / 2 - 50, wawa.frame.size.height / 2 + wawa.frame.origin.y + 20 , 80,30);
    login.backgroundColor = kGlobalYellowColor;
    [login addTarget:self action:@selector(ClickLogin:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:login];
    
    tableview = [[UITableView alloc]initWithFrame:CGRectMake( 10 , 0, self.frame.size.width -20, self.frame.size.height ) style:UITableViewStyleGrouped];
    tableview.contentInset = UIEdgeInsetsMake(5,0,0,0);
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.showsVerticalScrollIndicator = NO;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:tableview];
    tableview.backgroundColor = kGlobalBackgroundColor;
    [tableview registerNib:[UINib nibWithNibName:@"AttentionCell" bundle:nil] forCellReuseIdentifier:@"AttentionCell"];
    [self addSubview:tableview];
    tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(updatahead)];
    tableview.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(updatafoot)];
    tableview.hidden = YES;
    
    //添加一个观察者监听登录和退出登录
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadScene) name:@"RELOAD_DATA" object:nil];
    
    //初始化视图判断是否登录
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        [self ReloadScene];
    }
    
    tishi = [UIView new]; //登录娃娃  没有关注提示  // 102, 130   224  43
    tishi.frame = CGRectMake((self.frame.size.width - 224) / 2 , self.frame.size.height / 4, 224, 180);
    [self addSubview:tishi];
    
    UIImageView *tishiwawa = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"登录娃娃"]];
    tishiwawa.frame = CGRectMake((tishi.frame.size.width- 102)/2, 0 , 102, 130);
    [tishi addSubview:tishiwawa];
    
    UIImageView *tishiwenzi = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"没有关注提示"]];
    tishiwenzi.frame = CGRectMake(0,tishiwawa.frame.size.height + 10, 224, 43);
    [tishi addSubview:tishiwenzi];
    tishi.hidden = YES;
}
 
/**
 *  登录成功后更新视图
 */
-(void)ReloadScene{
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){  //用户已经登录
        [tableview.mj_header beginRefreshing];
    }else{
        [information removeAllObjects];
    }
    [self updateHidden];
}
 
/**
 *  更新影藏的视图
 */
-(void)updateHidden{
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        tableview.hidden = NO;
        wawa.hidden = YES;
        Clewlabel.hidden = YES;
        login.hidden = YES;
        
        if(information.count>0){
            tishi.hidden = YES;
        }else{
            tishi.hidden = NO;
        }
    }else{
        tableview.hidden = YES;
        wawa.hidden = NO;
        Clewlabel.hidden = NO;
        login.hidden = NO;
        tishi.hidden = YES;
    }
    
 
}
 
/**
 *  刷新数据
 */
-(void)updatahead{
    page = 1;
    [[YTHNetInterface startInterface]getAttentionUpdateListWithUid:[YTHsharedManger startManger].Uid WithPage:[NSString stringWithFormat:@"%d",page] WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            information = [[result objectForKey:@"Data"]objectForKey:@"data"];
            [tableview reloadData];
            page++;
        }else{
            NSLog(@"%@",error);
        }
        [self updateHidden];
        [tableview.mj_header endRefreshing];
    }];
}
 
-(void)updatafoot{
    [[YTHNetInterface startInterface]getAttentionUpdateListWithUid:[YTHsharedManger startManger].Uid WithPage:[NSString stringWithFormat:@"%d",page] WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            
            NSArray* newdata = [[result objectForKey:@"Data"]objectForKey:@"data"];
            
            if(newdata.count>0){
                NSMutableArray *arr = [NSMutableArray new];
                for (int i = 0 ;  i < newdata.count ; ++i ) {
                    NSIndexPath *dex = [NSIndexPath indexPathForRow:0 inSection:information.count + i];
                    [arr addObject:dex];
                }
                [tableview insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];
                [information addObjectsFromArray:newdata];
                
                page++;
            }else{
            }
            [tableview reloadData];
        }else{
            NSLog(@"%@",error);
        }
        [self updateHidden];
        [tableview.mj_footer endRefreshing];
    }];
}
 
/**
 *  登录
 */
-(void)ClickLogin:(id)sender{
    LoggingViewController *LG = [LoggingViewController new];
    [temp.navigationController pushViewController:LG animated:YES];
}
 
#pragma mark UITableViewDataSource  UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return information.count;
}
 
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AttentionCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AttentionCell"];
    NSDictionary * dic = [[information objectAtIndex:indexPath.section]objectForKey:@"VideoInfo"];
    NSDictionary *dic2=[dic objectForKey:@"VideoDetailList"][0];
 
    [cell.HeadImage setYthImageWithURL:[dic objectForKey:@"Picture"] placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
    [cell.MovieImage setYthImageWithURL:[dic2 objectForKey:@"Picture"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    cell.StarNmae.text = [dic objectForKey:@"Name"];
    cell.UpdateTime.text = [dic objectForKey:@"Updatetime"];
    cell.Play.text = [dic objectForKey:@"WatchCount"];
 
    NSNumber *num =[dic objectForKey:@"ReadCount"];
    cell.CommmentNum.text = [NSString stringWithFormat:@"%d",num.intValue];
    
    NSDictionary * diclistone = [dic objectForKey:@"VideoDetailList"][0];
    //做这个判断的目的是,防止因为后台数据的疏漏,造成数组越界,如果没有这个数据,类型就为NSNull
    if(![diclistone isKindOfClass:[NSNull class]]){
        if(diclistone && [[diclistone allKeys]containsObject:@"Tag"]){
            cell.MovieName.text = [diclistone objectForKey:@"Tag"];
        }
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
 
//-(BOOL)IsNewline:(NSString*)str:(float)width{
//    UILabel *lb = [UILabel new];
//    lb.text = str;
//    lb.numberOfLines = 0;
//    lb.font =[UIFont systemFontOfSize:15];
//    CGSize size = [lb sizeThatFits:CGSizeMake(width, MAXFLOAT)];
//    if(size.height > 20){
//        return NO;
//    }else{
//        return YES;
//    }
//}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5;//section头部高度
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
    [YTHsharedManger startManger].preController = self;
    play.modalPresentationStyle = 0;
    NSDictionary *dic = [information[indexPath.section]objectForKey:@"VideoInfo"];
    play.Model = [XYRVideoInfoModel yy_modelWithDictionary:dic];
    [temp presentViewController:play animated:YES completion:^{ }];
}
 
-(void)updataattention{
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        [tableview.mj_header beginRefreshing];
    }
}
 
@end