809 lines
26 KiB
Objective-C
809 lines
26 KiB
Objective-C
//
|
||
// 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 "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 ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource>
|
||
|
||
@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<deviceA.count; i++) {
|
||
//这里也可随机选择
|
||
NSArray *arr=@[@"device_03",@"device_01",@"device_03",@"device_03",@"device_01"];
|
||
|
||
[ _cellImageArr addObject:arr[i]];
|
||
|
||
}
|
||
}
|
||
|
||
return _cellImageArr;
|
||
}
|
||
|
||
- (NSMutableArray *)cellDescArr{
|
||
|
||
NSArray *deviceA=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
|
||
NSMutableArray*arr=[[NSMutableArray alloc]init];
|
||
|
||
for (DeviceModel*deviceModel in deviceA) {
|
||
|
||
[arr addObject:deviceModel.showName];
|
||
|
||
}
|
||
|
||
|
||
if (!_cellDescArr) {
|
||
|
||
self.cellDescArr = arr;
|
||
}
|
||
|
||
return _cellDescArr;
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - ICSDrawerControllerPresenting
|
||
|
||
//
|
||
//- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
|
||
//{
|
||
// self.view.userInteractionEnabled = NO;
|
||
//}
|
||
//
|
||
//- (void)drawerControllerDidOpen:(ICSDrawerController *)drawerController
|
||
//{
|
||
// self.view.userInteractionEnabled = YES;
|
||
//}
|
||
//
|
||
//- (void)drawerControllerWillClose:(ICSDrawerController *)drawerController
|
||
//{
|
||
// self.view.userInteractionEnabled = NO;
|
||
//}
|
||
//
|
||
//- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
|
||
//{
|
||
// self.view.userInteractionEnabled = YES;
|
||
//}
|
||
//
|
||
|
||
-(void)creatUI{
|
||
|
||
self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||
self.flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||
|
||
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width , kScreenSize.height) collectionViewLayout:self.flowLayout];
|
||
self.collectionView.backgroundColor = [UIColor colorWithRed:64/255.0f green:64/255.0 blue:64/255.0f alpha:1.0];
|
||
|
||
self.collectionView.delegate = self;
|
||
self.collectionView.dataSource = self;
|
||
|
||
[self.view addSubview:self.collectionView];
|
||
|
||
[self.collectionView registerClass:[rightDeviceCollectionViewCell class] forCellWithReuseIdentifier:@"CollectionCell"];
|
||
|
||
[self.collectionView registerNib:[UINib nibWithNibName:@"infoCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CELLID"];
|
||
|
||
[self.collectionView registerClass:[rightDeviceCollectionViewCell class] forCellWithReuseIdentifier:@"CameraViewCell"];
|
||
|
||
|
||
//加入脚部头部视图;
|
||
[self.collectionView registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"rightHeader2"];
|
||
|
||
[self.collectionView registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"rightHeader"];
|
||
|
||
|
||
[self.collectionView registerNib:[UINib nibWithNibName:@"emptyInfoCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"EMPTY"];
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - UICollectionViewDataSource
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||
|
||
|
||
if (section == 0) {
|
||
|
||
//SectionModel *sec = [self.dataSectionArray objectAtIndex:section];
|
||
|
||
return self.dataCellArray.count;
|
||
|
||
}else if(section == 1){
|
||
|
||
return self.cameraDataArr.count;
|
||
|
||
}
|
||
|
||
return 0;
|
||
|
||
}
|
||
|
||
#pragma mark 加载脚步视图
|
||
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
if (indexPath.section == 0) {
|
||
|
||
if (kind == UICollectionElementKindSectionHeader){
|
||
|
||
self.reusableView1 =[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"rightHeader" forIndexPath:indexPath];
|
||
|
||
self.reusableView1.titleLabel.text= @"我的水族箱";
|
||
self.reusableView1.backgroundColor = [UIColor colorWithRed:53/255.0f green:53/255.0 blue:53/255.0f alpha:1.0];
|
||
if ([_deviceArr count]!=0) {
|
||
|
||
return self.reusableView1;
|
||
}else{
|
||
return nil;
|
||
}
|
||
|
||
}else{
|
||
|
||
return nil;
|
||
|
||
}
|
||
|
||
}else{
|
||
|
||
if (kind == UICollectionElementKindSectionHeader) {
|
||
|
||
self.reusableView2 = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"rightHeader2" forIndexPath:indexPath];
|
||
self.reusableView2.titleLabel.text = @"我的摄像头";
|
||
self.reusableView2.backgroundColor = [UIColor colorWithRed:53/255.0f green:53/255.0 blue:53/255.0f alpha:1.0];
|
||
if ([_cameraArr count]!=0) {
|
||
|
||
return self.reusableView2;
|
||
}else{
|
||
|
||
return nil;
|
||
}
|
||
|
||
}else{
|
||
|
||
return nil;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
||
|
||
if (section ==0) {
|
||
if ([_deviceArr count]!=0) {
|
||
|
||
return CGSizeMake(kScreenSize.width , 40);
|
||
}else{
|
||
return CGSizeZero;
|
||
}
|
||
|
||
|
||
}else if (section == 1){
|
||
|
||
if ([_cameraArr count]!=0) {
|
||
return CGSizeMake(kScreenSize.width , 40);
|
||
|
||
}else{
|
||
return CGSizeZero;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
return CGSizeZero;
|
||
|
||
}
|
||
|
||
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||
{
|
||
return 2;
|
||
}
|
||
|
||
#pragma mark 设置item内容
|
||
|
||
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
|
||
|
||
//NSArray *arr=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
|
||
if (indexPath.section == 0) {
|
||
|
||
rightDeviceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
|
||
|
||
self.celmodel = [self.dataCellArray objectAtIndex:indexPath.row];
|
||
//取出数据;
|
||
cell.imageView.image = [UIImage imageNamed:self.celmodel.cellImage];
|
||
cell.descbutton.tag = 1000 + (int )indexPath.row +(int)indexPath.section*10;
|
||
|
||
cell.tag = 2000 + (int )indexPath.row;
|
||
|
||
[cell.descbutton setTitle:self.celmodel.cellDesc forState:UIControlStateNormal];
|
||
|
||
cell.descbutton.userInteractionEnabled = NO;
|
||
|
||
|
||
//[cell.descbutton addTarget:self action:@selector(SetBtnclick:) forControlEvents:UIControlEventTouchUpInside];
|
||
cell.backgroundColor = [UIColor colorWithRed:64/255.0f green:64/255.0f blue:64/255.0 alpha:1.0];
|
||
|
||
|
||
|
||
//[cell.deleteButton addTarget:self action:@selector(deleteCellButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
return cell;
|
||
|
||
}else if (indexPath.section == 1){
|
||
|
||
rightDeviceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
|
||
|
||
|
||
self.celmodel= [self.cameraDataArr objectAtIndex:indexPath.row];
|
||
|
||
cell.imageView.image = [UIImage imageNamed:self.celmodel.cellImage];
|
||
|
||
[cell.descbutton setTitle:self.celmodel.cellDesc forState:UIControlStateNormal];
|
||
cell.descbutton.tag = 3000 + (int )indexPath.row +(int)indexPath.section*10;
|
||
|
||
cell.tag = 4000 + (int )indexPath.row;
|
||
|
||
|
||
|
||
cell.backgroundColor = [UIColor colorWithRed:64/255.0f green:64/255.0f blue:64/255.0 alpha:1.0];
|
||
cell.descbutton.userInteractionEnabled = NO;
|
||
|
||
|
||
|
||
return cell;
|
||
|
||
|
||
}else{
|
||
return nil;
|
||
}
|
||
|
||
}
|
||
|
||
//设置item size
|
||
#pragma 设置item size
|
||
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
|
||
if (indexPath.section == 0) {
|
||
|
||
if ([_deviceArr count]!=0) {
|
||
|
||
return CGSizeMake((kScreenSize.width /3) - 20 , (kScreenSize.width )/3 - 20);
|
||
}else{
|
||
|
||
return CGSizeZero;
|
||
}
|
||
|
||
}else if (indexPath.section == 1){
|
||
|
||
if ([_cameraArr count]!=0) {
|
||
|
||
return CGSizeMake((kScreenSize.width /3) - 20 , (kScreenSize.width )/3 - 20);
|
||
}else{
|
||
|
||
return CGSizeZero;
|
||
}
|
||
|
||
}
|
||
|
||
return CGSizeZero;
|
||
|
||
}
|
||
|
||
//距离上下左右的间距
|
||
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
|
||
{
|
||
|
||
if (section == 0) {
|
||
|
||
return UIEdgeInsetsMake(10, 10, 10, 0);
|
||
|
||
}else if (section == 1){
|
||
|
||
return UIEdgeInsetsMake(10, 10, 10, 0);
|
||
|
||
}
|
||
return UIEdgeInsetsMake(0, 0, 0, 0);
|
||
|
||
}
|
||
|
||
|
||
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
|
||
{
|
||
//设置最小的列间距
|
||
if (section == 0 || section == 1) {
|
||
|
||
return 10.0f;
|
||
}else{
|
||
|
||
return 0.0f;
|
||
}
|
||
|
||
|
||
}
|
||
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
|
||
{
|
||
//设置最小的行间距
|
||
|
||
if (section == 0 || section == 1) {
|
||
|
||
return 10.0f;
|
||
|
||
}else{
|
||
|
||
return 0.0f;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
#pragma mark 点击item方法
|
||
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
|
||
|
||
|
||
//取出是某一个section;
|
||
|
||
|
||
if (indexPath.section == 0) {
|
||
|
||
//selectIndexPath =indexPath;
|
||
|
||
for(rightDeviceCollectionViewCell *cell in self.collectionView.visibleCells){
|
||
|
||
NSIndexPath *selectIndexPath = [self.collectionView indexPathForCell:cell];
|
||
|
||
if (selectIndexPath.section == 0) {
|
||
|
||
//除最后一个cell外都显示删除按钮;
|
||
//&& CellState == NormalState
|
||
if (selectIndexPath.row != self.dataCellArray.count && selectIndexPath.row == indexPath.row ){
|
||
|
||
|
||
DeviceModel*deviceModel=_deviceArr[indexPath.row];
|
||
|
||
|
||
//切换时主动 断开 soket
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
//存储选中下标
|
||
//存储下标 再次启动程序时默认选中位置 切换也需更新下标
|
||
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||
NSInteger index=selectIndexPath.row;
|
||
[userdefult setObject:nil forKey:@"cameralastIndex"];
|
||
[userdefult setInteger:index forKey:@"lastIndex"];
|
||
[userdefult synchronize];
|
||
|
||
|
||
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:deviceModel addWithdissMisVc:nil];
|
||
|
||
// [cell.point setHidden:NO];
|
||
|
||
}else{
|
||
|
||
//[cell.point setHidden:YES];
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}else if (indexPath.section ==1){
|
||
|
||
for(rightDeviceCollectionViewCell *cell in self.collectionView.visibleCells){
|
||
|
||
NSIndexPath *selectIndexPath = [self.collectionView indexPathForCell:cell];
|
||
|
||
if (selectIndexPath.section == 1) {
|
||
|
||
//除最后一个cell外都显示删除按钮;
|
||
//&& CellState == NormalState
|
||
if (selectIndexPath.row != self.cameraDataArr.count && selectIndexPath.row == indexPath.row ){
|
||
|
||
|
||
IfishCameraModel*cameraModel=_cameraArr[indexPath.row];
|
||
|
||
//切换时主动 断开 soket
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
//存储选中下标
|
||
//存储下标 再次启动程序时默认选中位置 切换也需更新下标
|
||
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||
NSInteger index=selectIndexPath.row;
|
||
|
||
[userdefult setObject:nil forKey:@"lastIndex"];
|
||
|
||
[userdefult setInteger:index forKey:@"cameralastIndex"];
|
||
[userdefult synchronize];
|
||
|
||
|
||
|
||
//跳转摄像头
|
||
// LeftViewController*left=[[LeftViewController alloc]init];
|
||
//
|
||
// RightViewController *rightVC=[[RightViewController alloc] init];
|
||
//
|
||
// YooseeCenterViewController *yoocvc=[[YooseeCenterViewController alloc] init];
|
||
// yoocvc.cameraModel = cameraModel;
|
||
//
|
||
// ICSDrawerController*ics=[[ICSDrawerController alloc]initWithLeftViewController:left centerViewController:yoocvc rightViewController:rightVC];
|
||
//
|
||
//
|
||
// UIApplication*app=[UIApplication sharedApplication];
|
||
// AppDelegate*app1=app.delegate;
|
||
// UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ics];
|
||
// [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
|
||
// app1.window.rootViewController=nav;
|
||
|
||
IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init];
|
||
|
||
p2pVC.contact = cameraModel;
|
||
|
||
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:p2pVC];
|
||
UIApplication*app=[UIApplication sharedApplication];
|
||
AppDelegate*app1=(AppDelegate*)app.delegate;
|
||
app1.window.rootViewController=nav;
|
||
|
||
}else{
|
||
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//static BOOL _isPoping;
|
||
//
|
||
//-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
|
||
// if (!_isPoping) {
|
||
// _isPoping = YES;
|
||
// return YES;
|
||
// }
|
||
// return NO;
|
||
//}
|
||
//
|
||
//-(void)viewWillAppear:(BOOL)animated{
|
||
//
|
||
// //开启ios右滑返回
|
||
// if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
|
||
// self.navigationController.interactivePopGestureRecognizer.delegate = nil;
|
||
// }
|
||
//}
|
||
//-(void)viewDidAppear:(BOOL)animated{
|
||
//
|
||
// //在didAppear时置为NO
|
||
// _isPoping = NO;
|
||
//}
|
||
@end
|