1085 lines
34 KiB
Objective-C
1085 lines
34 KiB
Objective-C
//
|
||
// CenterViewController.m
|
||
// Ifish
|
||
//
|
||
// Created by imac on 15/10/7.
|
||
// Copyright © 2015年 imac. All rights reserved.
|
||
//
|
||
|
||
#import "CenterViewController.h"
|
||
#import "SetViewController.h"
|
||
#import "AFNetworking.h"
|
||
#import "MyFishTankCell.h"
|
||
#import "SetTimeController.h"
|
||
#import "FishTankModel.h"
|
||
#import "StoreViewController.h"
|
||
#import "SongBaoViewController.h"
|
||
#import "searchDeviceModel.h"
|
||
#import "appLogin.h"
|
||
#import "BackmassegeModel.h"
|
||
#import "JHRefresh.h"
|
||
#import "setWaringTpModel.h"
|
||
#import "workTypeModel.h"
|
||
#import "manulswitchMSModel.h"
|
||
#import "UIImageView+WebCache.h"
|
||
#import "ConnectWifiViewController.h"
|
||
#define DELETDEVICE_ALERT 4230
|
||
#import "MBProgressHUD.h"
|
||
#import "MorShopViewController.h"
|
||
#import "ShopNameCellModel.h"
|
||
#import "shopNameCell.h"
|
||
#import "merchantModel.h"
|
||
#import "AppDelegate.h"
|
||
|
||
#import "CreatErWeiMaController.h"
|
||
|
||
#define URRENTVERSIONALERT 4200
|
||
#define CANCELALERT 5200
|
||
#import "DownLoadViewController.h"
|
||
#import "LeftViewController.h"
|
||
#define JPUSHMASSAGE_ALERT 4510
|
||
|
||
#import "FirstConnectWifiController.h"
|
||
|
||
#define btnWid 100
|
||
#define kPlace ([UIScreen mainScreen].bounds.size.width - btnWid*2) /4
|
||
|
||
#import "UIButton+WebCache.h"
|
||
|
||
//老版本选择设备界面
|
||
//#import "SelectDeviceViewController.h"
|
||
//#import "IfishSelectCardViewController.h"
|
||
#import "IfishBindDeviceSelectViewController.h"
|
||
|
||
#import "IfishMianTabViewController.h"
|
||
#import "LXPopView.h"
|
||
#import "DXPopover.h"
|
||
#import "SetNameTextViewController.h"
|
||
#import "DeviceCameraModel.h"
|
||
#import "IfishDataUnity.h"
|
||
|
||
@interface CenterViewController ()<UITableViewDelegate,UITableViewDataSource,MBProgressHUDDelegate,UIAlertViewDelegate,LxPopViewDelegate>
|
||
|
||
@property(nonatomic,strong)UIButton *openDrawerButton;
|
||
|
||
@property(nonatomic)BOOL readed;
|
||
|
||
@property(nonatomic,strong)NSIndexPath* indexPath;
|
||
|
||
@property(nonatomic)UILabel*animateLabel;
|
||
|
||
@property(nonatomic)MBProgressHUD*HUD;
|
||
|
||
@property(nonatomic,strong)UIButton*notbindButton;
|
||
@property(nonatomic,strong)UITapGestureRecognizer*gesture;
|
||
|
||
@property(nonatomic,strong) DXPopover *popover;
|
||
@property(nonatomic,strong) UIButton *rightPopButton;
|
||
@property (nonatomic,strong) SetNameTextViewController *setNameVC;
|
||
@property (nonatomic,strong) NSString *xinName;
|
||
|
||
|
||
@end
|
||
|
||
|
||
@implementation CenterViewController
|
||
- (void)viewDidLoad {
|
||
|
||
[super viewDidLoad];
|
||
|
||
_binddeviceArr=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
NSLog(@"%@",_binddeviceArr);
|
||
|
||
|
||
[self.tableView registerNib:[UINib nibWithNibName:@"MyFishTankCell" bundle:nil] forCellReuseIdentifier:@"MyFishTankCell"];
|
||
|
||
//self.navigationBar.alpha=0;
|
||
self.view.backgroundColor=COLOR_MIAN;
|
||
[self creatTableView];
|
||
[self initUI];
|
||
[self fishTankData];
|
||
|
||
[self creatMyindicaterView];
|
||
[self notBindDeviceState];
|
||
[self creatRefreshView];
|
||
|
||
|
||
}
|
||
|
||
-(void)viewDidAppear:(BOOL)animated{
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
-(void)fishTankData{
|
||
|
||
self.dataArr=@[@"logo.png"];
|
||
self.labelArr=@[@"品牌展示位"];
|
||
}
|
||
|
||
#pragma mark - InitUI
|
||
|
||
-(void)initUI{
|
||
|
||
|
||
// 左侧按钮背景
|
||
|
||
UIImage *hamburger = [[UIImage imageNamed:@"back_btn"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||
self.openDrawerButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
self.openDrawerButton.frame = CGRectMake(0, 0, 47,44);
|
||
[self.openDrawerButton setImage:hamburger forState:UIControlStateNormal];
|
||
//[self.openDrawerButton addTarget:self action:@selector(openDrawer:) forControlEvents:UIControlEventTouchUpInside];
|
||
[self.openDrawerButton addTarget:self action:@selector(leftBtnGoBackAction) forControlEvents:UIControlEventTouchUpInside];
|
||
self.openDrawerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||
[self.openDrawerButton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)];
|
||
UIBarButtonItem * backItem=[[UIBarButtonItem alloc] initWithCustomView:self.openDrawerButton];
|
||
|
||
self.navigationItem.leftBarButtonItem=backItem;
|
||
|
||
|
||
//标题
|
||
self.name=[[UILabel alloc]init ];
|
||
//CGRectMake(kScreenSize.width/2-30,13,120, 60)];
|
||
// name.text=@"爱鱼奇";
|
||
self.name.text=self.currentDevice.showName;
|
||
if (!self.name.text) {
|
||
self.name.text = @"设备名";
|
||
}
|
||
|
||
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:self.name.text];
|
||
|
||
[self.name setAttributedText:attributedString];
|
||
self.name.textAlignment = NSTextAlignmentCenter;
|
||
[self.name sizeToFit];
|
||
CGFloat labelSizeW = [self widthForString:self.name.text fontSize:20 andHeight:20];
|
||
CGFloat labelH= [self heightForString:self.name.text fontSize:20 andWidth:labelSizeW];
|
||
|
||
|
||
self.name.frame = CGRectMake(kScreenSize.width/2-labelSizeW/2, 20 - labelH/2 +24 ,labelSizeW , labelH);
|
||
|
||
self.name.textColor=[UIColor whiteColor];
|
||
self.navigationItem.titleView = self.name;
|
||
|
||
|
||
//右侧菜单
|
||
|
||
UIImage*MyEquipmentImage=[UIImage imageNamed:@"ifishnav_dropview_list"];
|
||
self.rightPopButton=[UIButton buttonWithType:UIButtonTypeCustom]
|
||
;
|
||
|
||
[self.rightPopButton setImage:MyEquipmentImage forState:UIControlStateNormal];
|
||
self.rightPopButton.frame=CGRectMake(kScreenWidth-60,0,60,44);
|
||
[self.rightPopButton setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
|
||
|
||
[self.rightPopButton addTarget:self action:@selector(presentPopView) forControlEvents:UIControlEventTouchUpInside];
|
||
UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] init];
|
||
rightItem.customView =self.rightPopButton;
|
||
|
||
self.navigationItem.rightBarButtonItem =rightItem;
|
||
|
||
|
||
// 预警温度背景
|
||
|
||
|
||
UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(35 , kPlace/3 , kPlace * 2 + btnWid - 60, (kPlace * 2 + btnWid - 60)/2)];
|
||
|
||
|
||
// leftBtn.backgroundColor = [UIColor redColor];
|
||
|
||
UILabel *textLbl = [[UILabel alloc] initWithFrame:CGRectMake(0 , kPlace/3 +(kPlace * 2 + btnWid - 50)/2 + 5, kScreenSize.width / 2 , 20)];
|
||
textLbl.text = @"品牌展示位";
|
||
textLbl.textColor = [UIColor whiteColor];
|
||
textLbl.font = [UIFont boldSystemFontOfSize:14];
|
||
// textLbl.backgroundColor = [UIColor redColor];
|
||
textLbl.textAlignment = NSTextAlignmentCenter;
|
||
|
||
if ([_binddeviceArr count]==0) {
|
||
[leftBtn setBackgroundImage:[UIImage imageNamed:@"brandLogo_hold"] forState:UIControlStateNormal];
|
||
}else{
|
||
[leftBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetLogUrl,self.currentDevice.logo]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"brandLogo_hold"] ];
|
||
textLbl.text = self.currentDevice.brandName;
|
||
}
|
||
|
||
|
||
[leftBtn addTarget:self action:@selector(pinPaiZhanShi:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
[self.tableView addSubview:textLbl];
|
||
[self.tableView addSubview:leftBtn];
|
||
|
||
//
|
||
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(kPlace + btnWid +kPlace -2 , kPlace/3, 5, 80)];
|
||
//line.backgroundColor = [UIColor colorWithRed:215/255.0f green:245/255.0f blue:246/254.0f alpha:0.7];
|
||
line.image = [UIImage imageNamed:@"line"];
|
||
[self.tableView addSubview:line];
|
||
|
||
|
||
|
||
CGFloat withSetPlace = kScreenSize.width/2 - (5 /2) + (kScreenSize.width/4 -(btnWid - 60)/2 ) ;
|
||
|
||
_setbackBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
||
_setbackBtn.frame =CGRectMake(CGRectGetMaxX(line.frame) + 5 , 0 ,kScreenSize.width-CGRectGetMaxX(line.frame) - 5 -60,CGRectGetMaxY(textLbl.frame));
|
||
|
||
|
||
[self.tableView addSubview: _setbackBtn];
|
||
|
||
_setImag=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xutosetting"]];
|
||
//_setImag.frame=CGRectMake(backBtn.frame.size.width/2 - (btnWid - 60)/2 , kPlace/3 , btnWid - 60 ,btnWid - 60);
|
||
_setImag.frame=CGRectMake(withSetPlace , kPlace/3 + (((kPlace * 2 + btnWid - 50)/2) -(btnWid - 60))/2 , btnWid - 60 ,btnWid - 60);
|
||
_setImag.userInteractionEnabled=YES;
|
||
|
||
[self.tableView addSubview:_setImag];
|
||
|
||
textLbl = [[UILabel alloc] initWithFrame:CGRectMake(kScreenSize.width / 2 ,kPlace/3 +(kPlace * 2 + btnWid - 50)/2 + 5, kScreenSize.width / 2 , 20)];
|
||
textLbl.text = @"水族箱设置";
|
||
UIButton *setNamebtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||
setNamebtn.frame = CGRectMake(kScreenSize.width / 2 ,kPlace/3 +(kPlace * 2 + btnWid - 50)/2 + 5, kScreenSize.width / 2 , 20);
|
||
textLbl.textAlignment = NSTextAlignmentCenter;
|
||
textLbl.font = [UIFont boldSystemFontOfSize:14];
|
||
textLbl.textColor = [UIColor whiteColor];
|
||
[self.tableView addSubview:textLbl];
|
||
|
||
[self.view bringSubviewToFront:_setbackBtn];
|
||
|
||
|
||
|
||
CGFloat animViewHeight= kScreenSize.width/4;
|
||
if (kScreenSize.height==480) {
|
||
|
||
self.bubble = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenSize.width -(kScreenSize.width - 2 * kPlace)*2/3)/2, kPlace + 80 , (kScreenSize.width - 2 * kPlace)*2/3, (kScreenSize.width - 2 * kPlace)*2/3)];
|
||
|
||
|
||
self.temperature = [[UILabel alloc] initWithFrame:CGRectMake(30, 70, (kScreenSize.width - 2 * kPlace - 100)*2/3, (kScreenSize.width - 2 * kPlace - 200)*2/3)];
|
||
self.temperature.font = [UIFont fontWithName:@"Avenir Next Condensed" size:46];
|
||
|
||
self.dulabel = [[UILabel alloc] initWithFrame:CGRectMake( (kScreenSize.width - 2 * kPlace - 100)*2/3,74,50, kScreenSize.width - 2 * kPlace - 210)];
|
||
|
||
|
||
self.dulabel.font = [UIFont fontWithName:@"Avenir Next Condensed" size:20];
|
||
self.animView= [[UIImageView alloc] initWithFrame:CGRectMake(0, kPlace + 80 + (kScreenSize.width - 2 * kPlace) -animViewHeight/2 - 15-80, kScreenSize.width, animViewHeight)];
|
||
|
||
self.notOnLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, kScreenSize.width - 2 * kPlace - 100, kScreenSize.width - 2 * kPlace - 200)];
|
||
self.notOnLineLabel .font = [UIFont fontWithName:@"Avenir Next Condensed" size:15];
|
||
|
||
|
||
}else{
|
||
|
||
self.temperature = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, kScreenSize.width - 2 * kPlace - 100, kScreenSize.width - 2 * kPlace - 200)];
|
||
self.temperature.font = [UIFont fontWithName:@"Avenir Next Condensed" size:70];
|
||
|
||
|
||
self.bubble = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenSize.width -(kScreenSize.width - 2 * kPlace ))/2, kPlace + 80 , kScreenSize.width - 2 * kPlace, kScreenSize.width - 2 * kPlace)];
|
||
self.dulabel = [[UILabel alloc] initWithFrame:CGRectMake((kScreenSize.width - 2 * kPlace)/3*2 -10 , 110 ,50, kScreenSize.width - 2 * kPlace - 210)];
|
||
self.dulabel.font = [UIFont fontWithName:@"Avenir Next Condensed" size:40];
|
||
self.animView= [[UIImageView alloc] initWithFrame:CGRectMake(0, kPlace + 80 + (kScreenSize.width - 2 * kPlace) -animViewHeight/2 - 15, kScreenSize.width, animViewHeight)];
|
||
|
||
|
||
self.notOnLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(((kScreenSize.width - 2 * kPlace) -(kScreenSize.width - 2 * kPlace - 100))/2 , 100, kScreenSize.width - 2 * kPlace - 100, kScreenSize.width - 2 * kPlace - 200)];
|
||
|
||
self.notOnLineLabel .font = [UIFont fontWithName:@"Avenir Next Condensed" size:20];
|
||
|
||
}
|
||
|
||
//设备不在线 label
|
||
|
||
self.notOnLineLabel.textColor=[UIColor colorWithRed:101/255.0f green:103/255.0f blue:103/255.0f alpha:1];
|
||
|
||
self.notOnLineLabel.text=@"该设备已离线";
|
||
self.notOnLineLabel.hidden = YES;
|
||
|
||
self.notOnLineLabel.textAlignment=NSTextAlignmentCenter;
|
||
//self.notOnLineLabel.backgroundColor= [UIColor redColor];
|
||
[self.bubble addSubview:self.notOnLineLabel];
|
||
|
||
|
||
//bubble.backgroundColor = [UIColor redColor];
|
||
self.bubble.image = [UIImage imageNamed:@"bubble"];
|
||
[self.tableView addSubview:self.bubble];
|
||
|
||
|
||
|
||
|
||
self.temperature.text = @"°C";
|
||
|
||
//temp.font = [UIFont systemFontOfSize:60];
|
||
|
||
self.temperature.textColor = [UIColor colorWithRed:101/255.0f green:103/255.0f blue:103/255.0f alpha:1];
|
||
// temp.backgroundColor = [UIColor yellowColor];
|
||
self.temperature.textAlignment = NSTextAlignmentCenter;
|
||
[self.bubble addSubview:self.temperature];
|
||
|
||
self.dulabel.text = @"°C";
|
||
self.dulabel.textColor = [UIColor colorWithRed:101/255.0f green:103/255.0f blue:103/254.0f alpha:1];
|
||
self.dulabel.textAlignment = NSTextAlignmentCenter;
|
||
[self.bubble addSubview: self.dulabel];
|
||
// NSLog(@"-----%@",[UIFont familyNames]);
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - 左侧按钮事件
|
||
|
||
-(void)leftBtnGoBackAction{
|
||
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
[self setAppTabRoot];
|
||
|
||
}
|
||
|
||
-(void)setAppTabRoot{
|
||
|
||
IfishMianTabViewController *mianVC=[[IfishMianTabViewController alloc] init];
|
||
UIApplication*app=[UIApplication sharedApplication];
|
||
AppDelegate*app1=(AppDelegate*)app.delegate;
|
||
|
||
app1.window.rootViewController=mianVC;
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - 右侧按钮事件
|
||
|
||
-(void)presentPopView{
|
||
|
||
UIImage *image = [UIImage imageNamed:@"popover_background_image_notrangle"];
|
||
NSArray *titleImgs = nil;
|
||
|
||
NSArray *titles=nil;
|
||
LXPopView *pop=[[LXPopView alloc] init];
|
||
CGFloat popRowH=160*(image.size.height/image.size.width);
|
||
if ([self.currentDevice.isMaster isEqualToString:@"1"]) {
|
||
//主控
|
||
pop.frame = CGRectMake(0, 0, 160, 160*(image.size.height/image.size.width) + (popRowH -12)/2);
|
||
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"Ifish_share_device"];
|
||
|
||
titles=@[@"修改名称",@"删除设备",@"分享设备"];
|
||
|
||
}else{
|
||
pop.frame = CGRectMake(0,0, 160, 160*(image.size.height/image.size.width));
|
||
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device"];
|
||
|
||
titles=@[@"修改名称",@"删除设备"];
|
||
|
||
}
|
||
|
||
pop.delegate = self;
|
||
|
||
pop.backgroundImage =image
|
||
;
|
||
pop.titles = titles;
|
||
|
||
pop.titleImgs =titleImgs;
|
||
|
||
DXPopover *popover = [DXPopover popover];
|
||
|
||
self.popover = popover;
|
||
|
||
popover.arrowSize = CGSizeMake(0.0,0.0);
|
||
|
||
[popover showAtView:self.setImag withContentView:pop];
|
||
NSLog(@"设备右侧pop");
|
||
|
||
}
|
||
|
||
#pragma mark - PopViewDelagate
|
||
|
||
-(void)disSelectedPopViewIndex:(NSIndexPath *)Index{
|
||
|
||
[self.popover dismiss];
|
||
|
||
if (Index.row == 0) {
|
||
//修改名称
|
||
[self shezhiMingCheng];
|
||
|
||
|
||
}else if (Index.row == 1){
|
||
//删除设备
|
||
|
||
[self deletDevice];
|
||
|
||
}else if (Index.row == 2){
|
||
//分享设备
|
||
|
||
[self fenXiangSheBei];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
#pragma mark - 修改设备名
|
||
|
||
-(void)shezhiMingCheng{
|
||
|
||
self.setNameVC = [[SetNameTextViewController alloc] init];
|
||
|
||
self.setNameVC.name = self.name.text;
|
||
self.setNameVC.device = self.currentDevice;
|
||
self.setNameVC.deviceType = 0;
|
||
|
||
__weak typeof (self)wself = self;
|
||
_setNameVC.NameWithBlock = ^(NSString *nameStr){
|
||
|
||
wself.name.text = nameStr;
|
||
|
||
};
|
||
|
||
|
||
[ wself.navigationController pushViewController: wself.setNameVC animated:YES];
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - 删除设备
|
||
|
||
-(void)deletDevice{
|
||
|
||
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"提示" message:@"确认删除设备?" preferredStyle:UIAlertControllerStyleAlert];
|
||
|
||
[self presentViewController:ac animated:YES completion:nil];
|
||
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
|
||
|
||
|
||
|
||
}]];
|
||
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
|
||
|
||
|
||
//先判断此设备是否有关联 摄像头
|
||
|
||
//DeviceModel*deviceModel=[_deviceArr objectAtIndex:indexpath.row];
|
||
//要删除的设设备id
|
||
|
||
//存在则 解除关系 删除对应的cameraId
|
||
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
|
||
|
||
for (DeviceCameraModel *model in guanxiiArr) {
|
||
|
||
if (self.currentDevice.deviceId == model.deviceId ) {
|
||
|
||
|
||
[guanxiiArr removeObject:model];
|
||
//保存新关系数组
|
||
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[self deleteDeviceRequset];
|
||
|
||
|
||
}]];
|
||
|
||
}
|
||
|
||
-(void)deleteDeviceRequset{
|
||
|
||
|
||
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
||
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||
NSMutableDictionary * para = [NSMutableDictionary dictionary];
|
||
|
||
NSString *priId=self.currentDevice.deviceId;
|
||
;
|
||
NSString*userId=self.currentDevice.userId;
|
||
|
||
[para setValue:priId forKey:@"priId.deviceId"];
|
||
[para setValue:userId forKey:@"priId.userId"];
|
||
// __weak typeof (self)weakSelf=self;
|
||
[mannager POST:kDeleteDeviceUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||
if (responseObject) {
|
||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||
NSLog(@"result:%@",resultDic[@"result"]);
|
||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self showTitle:@"" messsage:@"删除成功"];
|
||
//重置数据库
|
||
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
|
||
|
||
for (DeviceModel *model in deviceArry) {
|
||
|
||
if ([model.deviceId isEqual:self.currentDevice.deviceId]) {
|
||
|
||
[newArr removeObject:model];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"];
|
||
|
||
if ([newArr count]==0) {
|
||
|
||
NSArray *cameraArr= [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"];
|
||
if ([cameraArr count]!=0) {
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
}else{
|
||
//两种设备都
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[self setAppTabRoot];
|
||
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||
|
||
[self showTitle:@"" messsage:@"删除失败"];
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
|
||
|
||
[self showTitle:@"" messsage:@"请求验证失败,请重新登陆"];
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
|
||
|
||
[self showTitle:@"" messsage:@"请求被舍弃,未执行"];
|
||
}
|
||
}
|
||
|
||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||
|
||
[self showTitle:@"" messsage:@"请求异常"];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - 分享设备
|
||
|
||
-(void)fenXiangSheBei{
|
||
|
||
CreatErWeiMaController*vc=[[CreatErWeiMaController alloc]init]
|
||
;
|
||
vc.erdevicemodel=self.currentDevice;
|
||
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
|
||
}
|
||
|
||
|
||
#pragma mark - 游动的鱼
|
||
|
||
-(void)creatFishAnimation{
|
||
|
||
NSMutableArray *arry = [[NSMutableArray alloc] init];
|
||
|
||
for (int i = 2; i <= 76; i ++) {
|
||
|
||
if (i < 10) {
|
||
[arry addObject:[UIImage imageNamed:[NSString stringWithFormat:@"swimmingfish000%d",i]]];
|
||
|
||
}else{
|
||
[arry addObject:[UIImage imageNamed:[NSString stringWithFormat:@"swimmingfish00%d",i]]];
|
||
}
|
||
|
||
}
|
||
|
||
_animView.animationImages = arry;
|
||
// all frames will execute in 3 seconds
|
||
_animView.animationDuration = 3;
|
||
// repeat the annimation forever
|
||
_animView.animationRepeatCount = 1;
|
||
// start animating
|
||
[_animView startAnimating];
|
||
// add the animation view to the main window
|
||
|
||
[self.tableView addSubview:_animView];
|
||
[self.tableView bringSubviewToFront:_animView];
|
||
|
||
|
||
}
|
||
|
||
|
||
-(void)centerTapgestureRecognizer{
|
||
if (self.binddeviceArr.count==0) {
|
||
[self pushWiFiConnectVC];
|
||
}
|
||
}
|
||
|
||
-(void)centerSetClick{
|
||
|
||
if (self.binddeviceArr.count==0) {
|
||
[self pushWiFiConnectVC];
|
||
}
|
||
|
||
}
|
||
#pragma mark 分享二维码
|
||
|
||
-(void)erWeiMa{
|
||
|
||
CreatErWeiMaController*vc=[[CreatErWeiMaController alloc]init]
|
||
;
|
||
vc.erdevicemodel=self.currentDevice;
|
||
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
self.navigationController.navigationBarHidden=NO;
|
||
|
||
}
|
||
|
||
#pragma mark 我的设备 下拉菜按钮单点击事件
|
||
//原为展示右侧边栏 已去 主界面 为侧边栏中心界面 这里保留侧边栏 但只显示主界面
|
||
//左右侧边栏均不展示
|
||
|
||
-(void)MyEuipmentClick{
|
||
|
||
[self.drawer openRight];
|
||
|
||
}
|
||
|
||
#pragma mark - 创建tableview
|
||
|
||
-(void)creatTableView{
|
||
|
||
if (self.tableView==nil) {
|
||
UITableView*table=[[UITableView alloc]init];
|
||
table.frame=CGRectMake(0,0, kScreenSize.width, kScreenSize.height-TOP_HEIGHT);
|
||
table.dataSource=self;
|
||
table.delegate=self;
|
||
table.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
|
||
self.tableView=table;
|
||
self.tableView.hidden=NO;
|
||
UIImageView *backImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Puasiphysical"]];
|
||
[self.tableView setBackgroundView:backImage];
|
||
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
|
||
[self.view addSubview:self.tableView];
|
||
}
|
||
}
|
||
|
||
#pragma mark -主界面tableview dataSource add delegate
|
||
|
||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||
{
|
||
return 0;
|
||
}
|
||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||
return 0;
|
||
}
|
||
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
|
||
|
||
return nil;
|
||
|
||
}
|
||
|
||
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
AppDelegate*lauotDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
|
||
return 50*lauotDelegate.autoSizeScaleY;
|
||
}
|
||
|
||
#pragma mark -品牌展示按钮事件
|
||
|
||
-(void)pinPaiZhanShi:(UIButton*)sender{
|
||
|
||
if ([_binddeviceArr count]==0) {
|
||
|
||
[self pushWiFiConnectVC];
|
||
|
||
}else{
|
||
|
||
SongBaoViewController*brand=[[SongBaoViewController alloc]init];
|
||
brand.brandIntroduce=self.currentDevice.brandIntroduce;
|
||
[self.navigationController pushViewController:brand animated:YES];
|
||
self.navigationController.navigationBarHidden=NO;
|
||
}
|
||
}
|
||
|
||
#pragma mark - Open drawer button
|
||
- (void)openDrawer:(id)sender
|
||
{
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[self.drawer openLeft];
|
||
});
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
|
||
}
|
||
|
||
#pragma mark - Configuring the view’s layout behavior
|
||
|
||
- (BOOL)prefersStatusBarHidden
|
||
{
|
||
return NO;
|
||
}
|
||
|
||
#pragma mark - ICSDrawerControllerPresenting
|
||
|
||
#pragma mark center 主界面抽屉代理方法
|
||
|
||
- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
|
||
{
|
||
self.view.userInteractionEnabled = NO;
|
||
//self.navigationBarHidden=NO;
|
||
}
|
||
- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
|
||
{
|
||
self.view.userInteractionEnabled = YES;
|
||
// self.navigationBarHidden=NO;
|
||
}
|
||
|
||
#pragma mark -viewWillAppear
|
||
|
||
-(void)viewWillAppear:(BOOL)animated{
|
||
|
||
|
||
|
||
[self creatFishAnimation];
|
||
self.clockView.hidden=YES;
|
||
self.waringLabel.hidden=YES;
|
||
|
||
|
||
|
||
}
|
||
|
||
-(void)viewWillDisappear:(BOOL)animated{
|
||
|
||
|
||
}
|
||
|
||
//通过分享绑定设备
|
||
|
||
|
||
-(void)bindDeviceFromeShareView{
|
||
|
||
|
||
}
|
||
|
||
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
||
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
|
||
[alert show];
|
||
|
||
}
|
||
|
||
#pragma mark - app登录指令
|
||
-(void)requesDeviceData{
|
||
// 登录
|
||
appLogin *logModel=[[appLogin alloc]init];
|
||
// 十六进制转NSdata
|
||
logModel.sendmacId = self.currentDevice.macAddress;
|
||
logModel.resavemacId = self.currentDevice.macAddress;
|
||
NSData*data=[dataContorl stringToHexData:logModel.description];//1337AE5
|
||
|
||
[[Socketsingleton sharedInstance].clientSocket writeData:data withTimeout:-1 tag:0 ];
|
||
//为了得到服务端的回执,这里等待接受数据
|
||
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
|
||
if ([Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
//soket 未断开时显示
|
||
[_indicatorView startAnimating];
|
||
}
|
||
}
|
||
|
||
#pragma mark - 连接socket
|
||
|
||
-(void)InitSocket{
|
||
NSLog(@"******%d",[Socketsingleton sharedInstance].clientSocket.isConnected);
|
||
if (![Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
|
||
//[[Socketsingleton sharedInstance];
|
||
}
|
||
// 切换设备 先断开然后重连
|
||
|
||
|
||
[[Socketsingleton sharedInstance] socketConnectHost];
|
||
|
||
[Socketsingleton sharedInstance].macAddress = self.currentDevice.macAddress;
|
||
|
||
|
||
// if ([self.singletonSocket.clientSocket canSafelySetDelegate]==YES) {
|
||
// self.singletonSocket.clientSocket=[[AsyncSocket alloc]initWithDelegate:self];
|
||
// }else{
|
||
// NSLog(@"当前的委托有悬而未决的业务(读/写)");
|
||
// }
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
#pragma mark 通信监听communiteDelegate
|
||
|
||
//当已经和服务端断开连接后调用该代理方法
|
||
//断线重连功能需要在这里进行
|
||
|
||
-(void)ifishSocketDidDisconnect:(AsyncSocket *)sock{
|
||
|
||
_isconnect=NO;
|
||
[self endRefreshing];
|
||
[_indicatorView stopAnimating];
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[self deviceNotOnlineState1];//设备离线
|
||
});
|
||
NSLog(@"已经和服务端断开连接");
|
||
}
|
||
|
||
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err{
|
||
// NSLog(@"soket错误断开");
|
||
// NSLog(@"存留数据%@",[sock unreadData]);
|
||
|
||
}
|
||
|
||
-(BOOL)ifishSocketWillConnect:(AsyncSocket *)sock{
|
||
|
||
// NSLog(@"将要链接");
|
||
return YES;
|
||
|
||
}
|
||
|
||
#pragma mark 当已经与服务端建立连接后调用的代理方法
|
||
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock ifishSocketdidConnectToHost:(NSString *)host port:(UInt16)port{
|
||
//已建立连接 登陆指令同意在soket单例中
|
||
_isconnect=YES;
|
||
|
||
}
|
||
|
||
//发送完成处理
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag{
|
||
|
||
[self endRefreshing];
|
||
|
||
}
|
||
|
||
#pragma mark 登陆成功后收到服务端的回执之后,调用的代理方法
|
||
|
||
//父类里面不执行此方法 接收服务器返回信息 在子类中做处理
|
||
|
||
//communiteDelegate
|
||
|
||
-(void)socketDidGetBackmsgData:(NSData *)data onsoket:(AsyncSocket *)sock{
|
||
|
||
}
|
||
-(void)ifishDeviceLogInFail{
|
||
|
||
}
|
||
|
||
-(void)ifishDeviceLogInSuccees{
|
||
|
||
}
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket{
|
||
|
||
}
|
||
|
||
#pragma mark -soket链接后设备不在线状态界面设置
|
||
|
||
-(void)deviceNotOnlineState{
|
||
|
||
self.dulabel.hidden=YES;
|
||
self.temperature.hidden=YES;
|
||
self.notOnLineLabel.hidden = NO;
|
||
|
||
//[self showLableAction:@"设备已离线"];
|
||
|
||
}
|
||
//状态1 无labelAction
|
||
-(void)deviceNotOnlineState1{
|
||
|
||
self.dulabel.hidden = NO;
|
||
self.temperature.hidden = NO;
|
||
self.notOnLineLabel.hidden = YES;
|
||
|
||
}
|
||
|
||
#pragma mark - 请求温度
|
||
|
||
-(void)wenduRequest{// 查询设备状态信息
|
||
|
||
searchDeviceModel*xinxiModel=[[searchDeviceModel alloc]init];
|
||
xinxiModel.resavemacId = self.currentDevice.macAddress;
|
||
xinxiModel.sendmacId = self.currentDevice.macAddress;
|
||
|
||
NSString*requestStr=xinxiModel.description;
|
||
NSData*data1=[dataContorl stringToHexData:requestStr];
|
||
[[Socketsingleton sharedInstance].clientSocket writeData:data1 withTimeout:-1 tag:0];
|
||
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
|
||
|
||
}
|
||
|
||
#pragma mark - 刷新
|
||
-(void)creatRefreshView{
|
||
|
||
__weak typeof (self)weakSelf=self;
|
||
[weakSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
|
||
if (weakSelf.isRefeshing) {
|
||
return ;
|
||
}
|
||
|
||
weakSelf.isRefeshing=YES;
|
||
if (_isconnect==YES) {
|
||
//
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[weakSelf wenduRequest];
|
||
});
|
||
|
||
|
||
}else{// socket中断
|
||
[weakSelf InitSocket];
|
||
|
||
}
|
||
}];
|
||
}
|
||
-(void)endRefreshing{
|
||
if (self.isRefeshing) {
|
||
self.isRefeshing=NO;
|
||
[self.tableView headerEndRefreshingWithResult:JHRefreshResultSuccess];
|
||
}
|
||
}
|
||
|
||
#pragma mark alert 动态显示
|
||
|
||
-(void)showAlert{
|
||
NSString*title=nil;
|
||
NSString*message=@"设备未连接服务器";
|
||
NSTimeInterval dismissSeconds=2.0;
|
||
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
||
[alertView show];
|
||
[self performSelector:@selector(dismissAlert:) withObject:alertView afterDelay:dismissSeconds];
|
||
}
|
||
-(void)dismissAlert:(UIAlertView*)alertView{
|
||
[alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES];
|
||
}
|
||
-(void)addAlertView{
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[self showAlert];
|
||
});
|
||
}
|
||
|
||
#pragma mark - loding 效果
|
||
|
||
-(void)creatMyindicaterView{
|
||
_indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||
// _indicatorView.center=CGPointMake(kScreenSize.width/2, kScreenSize.height/2+100);
|
||
//[_indicatorView startAnimating];
|
||
_indicatorView.frame=CGRectMake(kScreenSize.width/2-20,kScreenSize.height/2-20,40, 40);
|
||
// _indicatorView.backgroundColor=[UIColor lightGrayColor];
|
||
[self.view addSubview:_indicatorView];
|
||
}
|
||
|
||
-(void)initHUD{
|
||
|
||
_myhud=[[MyHud alloc]init];
|
||
|
||
_myhud.frame=CGRectMake(0, kScreenSize.height*2/3 , kScreenSize.width,kScreenSize.height/3);
|
||
|
||
[_myhud myhudtimeOut];
|
||
|
||
[self.view addSubview:_myhud];
|
||
}
|
||
|
||
- (void)showLableAction:(NSString *)str{
|
||
|
||
UILabel *laberAction =[[UILabel alloc]init];
|
||
laberAction.frame =CGRectMake((kScreenSize.width/2) - 50, kScreenSize.height/2 , 100, 50);
|
||
laberAction.clipsToBounds =YES;
|
||
laberAction.layer.cornerRadius =5;
|
||
laberAction.alpha =1;
|
||
laberAction.text =str;
|
||
laberAction.textAlignment =NSTextAlignmentCenter;
|
||
laberAction.backgroundColor =IndicatorBack_COLOR;
|
||
laberAction.font=[UIFont systemFontOfSize:12];
|
||
laberAction.textColor=[UIColor whiteColor];
|
||
|
||
[UIView animateWithDuration:2.0 animations:^{
|
||
laberAction.alpha =0;
|
||
}completion:^(BOOL finished) {
|
||
[laberAction removeFromSuperview];
|
||
}];
|
||
[self.view addSubview:laberAction];
|
||
}
|
||
|
||
#pragma mark - 判断用户是否绑定设备
|
||
|
||
-(void)notBindDeviceState{
|
||
self.notbindButton=[UIButton buttonWithType:UIButtonTypeSystem];
|
||
[self.notbindButton addTarget:self action:@selector(notbindButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
self.notbindButton.frame=CGRectMake(40, self.bubble.frame.size.height/2 -30, self.bubble.frame.size.width-80, 60);
|
||
self.notbindButton.titleLabel.numberOfLines = 0;
|
||
self.notbindButton.titleLabel.textAlignment = NSTextAlignmentCenter;
|
||
[self.notbindButton setTitle:@"您未绑定设备\n点我绑定设备" forState:UIControlStateNormal];
|
||
|
||
self.notbindButton.tintColor=[UIColor colorWithRed:101/255.0f green:103/255.0f blue:103/254.0f alpha:1];
|
||
self.bubble.userInteractionEnabled = YES;
|
||
// self.bubble更新UI及app 框架后已去
|
||
//[self.bubble addSubview:self.notbindButton];
|
||
|
||
if ([_binddeviceArr count]==0){// 未绑定
|
||
|
||
self.waringLabel.hidden=YES;
|
||
self.dulabel.hidden=YES;
|
||
self.clockView.hidden=YES;
|
||
self.notbindButton.hidden=NO;
|
||
self.tableView.bounces=NO;
|
||
|
||
self.rightPopButton.hidden = YES;
|
||
|
||
}else{
|
||
|
||
|
||
self.tableView.bounces=YES;
|
||
|
||
if (self.currentDevice.isBlacklist) {
|
||
|
||
if ([self.currentDevice.isBlacklist isEqualToString:@"0"]) {
|
||
|
||
[self InitSocket];//允许请求数据
|
||
|
||
}else{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
self.clockView.hidden=NO;
|
||
self.bubble.hidden=NO;
|
||
self.waringLabel.hidden = NO;
|
||
self.dulabel.hidden = NO;
|
||
self.notbindButton.hidden=YES;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#pragma mark 未绑定设备跳转
|
||
|
||
-(void)notbindButtonClick{
|
||
|
||
[self pushWiFiConnectVC];
|
||
|
||
}
|
||
|
||
-(void)pushWiFiConnectVC{
|
||
|
||
IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init];
|
||
[self.navigationController pushViewController:connectVC animated:YES];
|
||
self.navigationController.navigationBarHidden=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;
|
||
}
|
||
|
||
@end
|