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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//
//  MyRegardController.m
//  BuWanVideo2.0
//
//  Created by weikou2016 on 16/8/16.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "MyRegardController.h"
#import "RegardCell.h"
#import "UIImageView+YTH.h"
#import "LoggingViewController.h"
#import "XYRDetailViewController.h"
 
 
@interface MyRegardController ()<UITableViewDataSource,UITableViewDelegate>{
    UITableView *mytableview;
    NSMutableArray *ListDataArray; //数据源
    int number;                    //确定标定的下表
    int *IsSelect;                 //指向标定下表的指针 为动态实现
    int page;                      //页码
    
    UIView * prompt;                //没有信息时,提示视图
}
 
@end
 
@implementation MyRegardController
 
@synthesize viewcontroller;
 
- (void)viewDidLoad {
    [super viewDidLoad];
    //加载基础视图
    [self initScene];
}
 
-(void)initScene{
    self.view.backgroundColor = kGlobalBackgroundColor;
    
    //设置导航栏
    [self createNavgationBar];
    
    //创建列表
    [self initlist];
    
    //没有数据时的提示视图
    [self promptView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadNewData];
}
-(void)createNavgationBar{
    self.navigationItem.title = @"我的关注";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:18]};
    
    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;
}
 
-(void)initlist{
    mytableview = [[UITableView alloc]initWithFrame:CGRectMake(10, 0, KScreenW - 20, KScreenH - 5) style:UITableViewStylePlain];
    mytableview.delegate = self;
    mytableview.dataSource = self;
    mytableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    mytableview.showsVerticalScrollIndicator = NO;
    mytableview.backgroundColor = [UIColor clearColor];
    //注册cell
    [mytableview registerNib:[UINib nibWithNibName:@"RegardCell" bundle:nil] forCellReuseIdentifier:@"RegardCell"];
    //下拉刷新
    mytableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    mytableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self loadOldData];
    }];
    [mytableview.mj_header beginRefreshing];
    [self.view addSubview:mytableview];
}
 
-(void)loadNewData{
    page = 1;
    [self GetRegardData];
}
 
-(void)loadOldData{
    [self GetRegardData];
}
 
-(void)promptView{
    prompt = [UIView new];
    prompt.frame = CGRectMake((self.view.frame.size.width - 224) / 2 , self.view.frame.size.height / 3, 224, 180);
    [self.view addSubview:prompt];
    [prompt setHidden:YES];
    
    UIImageView *buwanImag = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"登录娃娃"]];
    buwanImag.frame = CGRectMake((prompt.frame.size.width- 102)/2, 0 , 102, 130);
    [prompt addSubview:buwanImag];
    
    UIImageView *tipMessage= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"没有关注提示"]];
    tipMessage.frame = CGRectMake(0,buwanImag.frame.size.height + 10, 224, 43);
    [prompt addSubview:tipMessage];
}
 
 
-(void)GetRegardData{
    [[YTHNetInterface startInterface]getAttentionListWithUid:[YTHsharedManger startManger].Uid WithPage:[NSString stringWithFormat:@"%d",page] WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            if (!ListDataArray) {
                ListDataArray=[NSMutableArray arrayWithCapacity:0];
            }
            //如果page==1,说明进行了刷新操作
            if(page==1){
                [ListDataArray removeAllObjects];
            }
            NSArray *arr= [[result objectForKey:@"Data"]objectForKey:@"data"];
       
            
            //判断是否请求到新数据
            if(arr> 0){
                page++;
                [ListDataArray addObjectsFromArray:arr];
                [mytableview reloadData];
            }
            //判断整个关注里面是否有数据,如果没有数据,就显示提示视图
            if (ListDataArray.count==0) {
                [prompt setHidden:NO];
            }
            if (arr.count < 20) {
                [mytableview.mj_footer endRefreshingWithNoMoreData];
            }
            if (ListDataArray.count < 20) {
                mytableview.mj_footer.hidden = YES;
            }else{
                mytableview.mj_footer.hidden = NO;
            }
        }else{
            NSLog(@"%@",error);
            if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
                [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
            }
        }
        [mytableview.mj_header endRefreshing];
    }];
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return ListDataArray.count;
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return ListDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RegardCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RegardCell"];
    NSDictionary * dic = [ListDataArray[indexPath.section] objectForKey:@"VideoInfo"];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    //名称
    cell.Name.text = [dic objectForKey:@"Name"];
    
    //最新跟新时间
    NSString *time = [[YTHNetInterface startInterface] getDate:[dic objectForKey:@"Createtime"]];
    if (time.length >= 17) {
        time = [time substringToIndex:11];
    }
    cell.Timeupdate.text = time;
    
    //图片
    [cell.image setYthImageWithURL:[dic objectForKey:@"Hpicture"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    
    //关注按钮选中状态
    [cell.button setTitle:@"已关注" forState:UIControlStateSelected];
    [cell.button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    cell.button.backgroundColor = kGlobalLightGreyColor_210;
    cell.button.tintColor=kGlobalLightGreyColor_210;
    
    //关注按钮未选中状态
    [cell.button setTitle:@"关注" forState:UIControlStateNormal];
    [cell.button setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
    
    //关注按钮默认选中
    [cell.button setSelected:YES];
    
    //设置tag的值
    cell.button.tag = indexPath.section + 1000;
    cell.expandbutton.tag=indexPath.section + 1000;
    NSLog(@"%ld",(long)indexPath.row);
    
    [cell.button addTarget:self action:@selector(ClickButton:) forControlEvents:UIControlEventTouchUpInside];
    [cell.expandbutton addTarget:self action:@selector(ClickButton:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    NSDictionary * dic = [ListDataArray[indexPath.section] objectForKey:@"VideoInfo"];
    NSLog(@"%ld",(long)indexPath.section);
    XYRDetailViewController *play = [[XYRDetailViewController alloc]init];
    [YTHsharedManger startManger].preController = self;
    play.modalPresentationStyle = 0;
    play.Model = [XYRVideoInfoModel yy_modelWithDictionary:dic];
    [self presentViewController:play animated:YES completion:^{
        
    }];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, 20)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
/**
 *  退出并向服务器发出新的关注新信息
 */
-(void)back:(id)sender{
    //取消关注的请求
    [self.navigationController  popToRootViewControllerAnimated:YES];
}
 
/**
 关注按钮
 
 @param sender 按钮
 */
-(void)ClickButton:(UIButton *)sender{
    UIButton *button = [sender.superview subviews][1];
//    UIButton *button = sender;
 
    if([button isSelected]){//取消关注的操作
        [button setSelected:NO];
        button.backgroundColor = kGlobalYellowColor;
        button.tintColor=kGlobalYellowColor;
        
        NSString *str=[[ListDataArray[sender.tag - 1000] objectForKey:@"VideoInfo"]objectForKey:@"Id"];
        NSLog(@"%@",ListDataArray[sender.tag - 1000]);
        NSLog(@"%@",[[ListDataArray[sender.tag - 1000] objectForKey:@"VideoInfo"]objectForKey:@"Name"]);
 
        NSLog(@"%ld",(long)sender.tag);
        [[YTHNetInterface startInterface] cancelAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:str WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if(isSuccessful){
                NSNotification *notification = [NSNotification notificationWithName:@"RELOAD_DATA" object:nil userInfo:nil];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            }else{
                [button setSelected:YES];
                button.backgroundColor = kGlobalLightGreyColor_210;
                button.tintColor=kGlobalLightGreyColor_210;
                NSLog(@"%@",error);
            }
        }];
    }else{//关注的操作
        [button setSelected:YES];
        button.backgroundColor = kGlobalLightGreyColor_210;
        button.tintColor=kGlobalLightGreyColor_210;
        
        NSString *str=[NSString stringWithFormat:@"%@,",[[ListDataArray[sender.tag - 1000] objectForKey:@"VideoInfo"]objectForKey:@"Id"]];
        NSLog(@"%ld",(long)sender.tag);
        
        [[YTHNetInterface startInterface] addAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:str WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if(isSuccessful){
                NSNotification *notification = [NSNotification notificationWithName:@"RELOAD_DATA" object:nil userInfo:nil];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            }else{
                [button setSelected:NO];
                button.backgroundColor = kGlobalYellowColor;
                button.tintColor=kGlobalYellowColor;
                NSLog(@"%@",error);
            }
        }];
    }
}
 
@end