// // RightViewController.m // Ifish // // Created by imac on 16/3/25. // Copyright © 2016年 imac. All rights reserved. // #import "RightViewController.h" #import "rightDeviceCollectionViewCell.h" #import "CollectionReusableView.h" //#import "SectionModel.h" #import "CellModel.h" #import "infoCollectionViewCell.h" #import "ConnectInfoCollectionModel.h" #import "SetNameTextViewController.h" #import "FirstConnectWifiController.h" #import "CenterViewController.h" #import "PushmessageModel.h" #import "IfishDatabaseManager.h" #import "DeviceModel.h" #import "emptyInfoCollectionViewCell.h" #import "IfishDataUnity.h" //#import "SelectDeviceViewController.h" //#import "IfishSelectCardViewController.h" #import "IfishBindDeviceSelectViewController.h" #import "CameraViewCell.h" #define DESCREPTION_TAG 1000 #define DESCREPTION_DEVICENAME1_TAG 1001 #define DESCREPTION_DEVICENAME2_TAG 1002 #define DESCREPTION_DEVICENAME3_TAG 1003 #define DESCREPTION_DEVICENAME4_TAG 1004 #define DESCREPTION_CAMERANAME0_TAG 3010 #define DESCREPTION_CAMERANAME1_TAG 3011 #define DESCREPTION_CAMERANAME2_TAG 3012 #define DESCREPTION_CAMERANAME3_TAG 3013 #define DESCREPTION_CAMERANAME4_TAG 3014 #import "YooseConnectFirstViewController.h" #import "DeviceCameraModel.h" #import "IfishP2PMonitorController.h" //NS_ENUM(NSInteger,CellState){ // // //右上角编辑按钮的两种状态; // //正常的状态,按钮显示“编辑”; // NormalState, // //正在删除时候的状态,按钮显示“完成”; // DeleteState // //}; NS_ENUM(NSInteger,indexViewState){ //右上角编辑按钮的两种状态; //正常的状态,按钮显示“编辑”; indexViewHidien, //正在删除时候的状态,按钮显示“完成”; indexViewApper }; NS_ENUM(NSInteger,deviceType){ FishTank, Camera }; @interface RightViewController () @property (nonatomic,strong) UIButton *editButton; @property (nonatomic,strong) UICollectionView *collectionView; @property (nonatomic,strong) UICollectionViewFlowLayout *flowLayout; //@property (nonatomic,strong) enum CellState; @property (nonatomic,strong) enum indexViewState; @property (nonatomic,strong) enum deviceType; //下面数组用来存放头部标题; @property(strong,nonatomic) NSMutableArray *headerArray; //里面存放section对象,也就是section模型,模型由SectionModel定义; //@property (nonatomic,strong) NSMutableArray *dataSectionArray; //里面存放cell对象,也就是cell模型,模型由CellModel定义; //水族箱数组 @property (nonatomic,strong) NSMutableArray *dataCellArray; @property(nonatomic,strong) NSMutableArray *cellImageArr; @property(nonatomic,strong) NSMutableArray *cellDescArr; @property (nonatomic,strong) CollectionReusableView *reusableView1; @property (nonatomic,strong) CollectionReusableView *reusableView2; @property (nonatomic,strong) SetNameTextViewController *setNameVC; @property (nonatomic,strong) NSMutableArray *ConnectData; @property (nonatomic,strong) NSMutableArray *IconArr; @property (nonatomic,strong) NSMutableArray *TitleArr; //摄像头数组 @property (nonatomic,strong) NSMutableArray *cameraDataArr; @property (nonatomic,strong) NSMutableArray *cameraArr; @property (nonatomic,strong) CellModel *celmodel; @property (nonatomic,strong) NSString *xinCameraName; //第一分区下标 设备 @property (nonatomic) int indexPathBlock; //第2分区下标 摄像头 @property (nonatomic) int indexSecondBlock; @property(nonatomic,strong) NSMutableArray* deviceArr; @property(nonatomic,copy) NSString *pushId; @property (nonatomic,strong) NSDictionary *parameters; @property(nonatomic,strong) UIButton *notbindBtn; @end // NSIndexPath*selectIndexPath; BOOL collectionViewselect;//是否有选中设备 extern BOOL isfromCameraView; @implementation RightViewController -(void)viewDidLoad{ [self loadSecData]; [self setNav]; [self creatUI]; self.view.backgroundColor = COLOR_MIAN; collectionViewselect= NO; [self notBindDevicestate]; } -(void)notBindDevicestate{ NSArray * deviceArr =[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; NSArray * cameraArr =[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"]; if ([deviceArr count]==0 && [cameraArr count]==0) { self.collectionView.hidden = YES; self.notbindBtn=[UIButton buttonWithType:UIButtonTypeCustom]; NSString *title=@"您暂未绑定设备,前往绑定。"; [self.notbindBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:title]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:8]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [title length])]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(8,5)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,8)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange([title length]-1,1)]; [self.notbindBtn setAttributedTitle:attributedString forState:UIControlStateNormal]; [self.notbindBtn sizeToFit]; self.notbindBtn.titleLabel.textAlignment = NSTextAlignmentCenter; CGFloat btnTitleW =[self widthForString:self.notbindBtn.titleLabel.text fontSize:20 andHeight:10]; CGFloat btnTitleH = [self heightForString:self.notbindBtn.titleLabel.text fontSize:20 andWidth:btnTitleW]; self.notbindBtn.frame =CGRectMake(self.view.frame.size.width/2 -btnTitleW/2,self.view.frame.size.height/2 -btnTitleH/2, btnTitleW, btnTitleH); [self.notbindBtn addTarget:self action:@selector(noUserDeviceClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.notbindBtn]; }else{ self.collectionView.hidden = NO; if (self.notbindBtn) { self.notbindBtn.hidden = YES; } } } -(void)noUserDeviceClick{ self.hidesBottomBarWhenPushed = YES; IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init]; [self.navigationController pushViewController:connectVC animated:YES]; //self.hidesBottomBarWhenPushed = NO; } #pragma -mark -functions //获取字符串的宽度 -(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height { CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置 return sizeToFit.width; } //获得字符串的高度 -(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width { CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置 return sizeToFit.height; } -(void)setNav{ UIButton *bakbutton = [UIButton buttonWithType:UIButtonTypeCustom]; bakbutton.frame = CGRectMake(0,0,48,44); [bakbutton setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; [bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside]; bakbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [bakbutton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)]; UIBarButtonItem *back=[[UIBarButtonItem alloc] initWithCustomView:bakbutton]; self.navigationItem.leftBarButtonItem=back; self.title = @"切换设备"; } -(void)goBackAction{ [self.navigationController popViewControllerAnimated:YES]; } - (NSMutableArray *)dataCellArray{ NSMutableArray*arr=[[NSMutableArray alloc]init]; for (DeviceModel*deviceModel in _deviceArr) { [arr addObject:deviceModel.showName]; } NSUInteger Allcount=0; Allcount = arr.count; //dataCellArray 数组总数 arr.count + 醉后一个按钮 或 arr.count + 摄像头按钮 + 醉后一个按钮 _dataCellArray = [[NSMutableArray alloc] initWithCapacity:Allcount]; for (int j = 0; j < Allcount; j++) { //默认一个section中有6个cell; //初始化每一个cell; CellModel *cellModel = [[CellModel alloc] init]; cellModel.cellImage = self.cellImageArr[j]; cellModel.cellDesc = self.cellDescArr[j]; //添加到cell数组中; [_dataCellArray addObject:cellModel]; } return _dataCellArray; } -(NSMutableArray *)cameraDataArr{ _cameraArr = [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"]; if (!_cameraArr) { _cameraArr = [[NSMutableArray alloc] init]; } NSMutableArray *arr=[[NSMutableArray alloc] init]; for (IfishCameraModel *cameraModel in _cameraArr) { [arr addObject:cameraModel.showName]; } _cameraDataArr = [[NSMutableArray alloc] init]; for (int i =0; i<_cameraArr.count ; i++) { CellModel *cellModel = [[CellModel alloc] init]; cellModel.cellImage = @"right_camera_logo"; cellModel.cellDesc = arr[i]; [_cameraDataArr addObject:cellModel]; } return _cameraDataArr; } -(void)loadSecData{ //水族箱 if (!_deviceArr) { _deviceArr=[[NSMutableArray alloc] init]; _deviceArr=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; } //摄像头 if (!_cameraArr) { _cameraArr = [[NSMutableArray alloc] init]; _cameraArr = [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"]; } } - (NSMutableArray *)cellImageArr{ NSArray *deviceA=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; if (!_cellImageArr) { _cellImageArr = [[NSMutableArray alloc] init]; for (NSInteger i=0; i