//
|
// 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
|