327 lines
10 KiB
Objective-C
327 lines
10 KiB
Objective-C
//
|
|
// Xuanduo2fController.m
|
|
// Ifish
|
|
//
|
|
// Created by Alex on 2019/4/13.
|
|
// Copyright © 2019 lianlian. All rights reserved.
|
|
//
|
|
|
|
#import "Xuanduo2fController.h"
|
|
#import "LXPopView.h"
|
|
#import "DXPopover.h"
|
|
#import "DeviceCameraModel.h"
|
|
#import "XuToControlNameViewController.h"
|
|
#import "IfishDataUnity.h"
|
|
#import "XuToSetViewController.h"
|
|
#import "CreatErWeiMaController.h"
|
|
#import "XuToControlName.h"
|
|
#import "UserExtendataArchaver.h"
|
|
|
|
@interface Xuanduo2fController ()<LxPopViewDelegate>
|
|
@property(nonatomic,strong) DXPopover *popover;
|
|
@property (weak, nonatomic) IBOutlet UIView *positionView;
|
|
@property (weak, nonatomic) IBOutlet UILabel *shajunLight;
|
|
@property (weak, nonatomic) IBOutlet UILabel *zengyangLabel;
|
|
@property (weak, nonatomic) IBOutlet UILabel *light1Label;
|
|
@property (weak, nonatomic) IBOutlet UILabel *light2Label;
|
|
@property (weak, nonatomic) IBOutlet UILabel *zaolangLabel;
|
|
@property (weak, nonatomic) IBOutlet UILabel *huliLabel;
|
|
@property (weak, nonatomic) IBOutlet UILabel *xunhuanLabel;
|
|
@property (weak, nonatomic) IBOutlet UILabel *jiareLabel;
|
|
|
|
@end
|
|
|
|
@implementation Xuanduo2fController
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName :[UIColor blackColor]};
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self setup];
|
|
// Do any additional setup after loading the view from its nib.
|
|
}
|
|
|
|
- (void)setup{
|
|
self.title = self.currentDevice.showName;
|
|
//右侧菜单
|
|
UIImage *MyEquipmentImage = [UIImage imageNamed:@"ifishnav_dropview_list"];
|
|
UIButton *rightPopButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[rightPopButton setImage:MyEquipmentImage forState:UIControlStateNormal];
|
|
rightPopButton.frame=CGRectMake(kScreenWidth-60,0,60,44);
|
|
[rightPopButton setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
|
|
|
|
[rightPopButton addTarget:self action:@selector(presentPopView) forControlEvents:UIControlEventTouchUpInside];
|
|
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightPopButton];
|
|
self.navigationItem.rightBarButtonItem =rightItem;
|
|
[self initCHNames];
|
|
}
|
|
|
|
#pragma -- actions --
|
|
- (void)goBackAction{
|
|
[[Socketsingleton sharedInstance] cutOffSocket];
|
|
[[IfishDataUnity shareDataInstance] setAppTabRoot];
|
|
}
|
|
|
|
- (IBAction)shajunAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)zengyangAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)dengguang1Action:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)dengguang2Action:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)zaoyangAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)huliAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)xunhuanAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
- (IBAction)jiareAction:(UIButton*)sender {
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
-(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);
|
|
//主控
|
|
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",@"ifishdropview_set_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:_positionView 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];
|
|
}else if (Index.row == 3){
|
|
[self setting];
|
|
}
|
|
|
|
}
|
|
|
|
#pragma mark - 修改设备名
|
|
|
|
-(void)shezhiMingCheng{
|
|
XuToControlNameViewController *_changeNameVC = [[XuToControlNameViewController alloc] init];
|
|
_changeNameVC.isNewdevice = YES;
|
|
_changeNameVC.name = self.title;
|
|
_changeNameVC.device = self.currentDevice;
|
|
__weak typeof (self)wself = self;
|
|
_changeNameVC.NameWithBlock = ^(NSString *nameStr){
|
|
wself.title = nameStr;
|
|
[wself initCHNames];
|
|
};
|
|
[ wself.navigationController pushViewController: _changeNameVC animated:YES];
|
|
}
|
|
|
|
-(void)initCHNames{
|
|
|
|
XuToControlName *name = [UserExtendataArchaver currentNewXuToControlName:self.currentDevice.macAddress];
|
|
self.shajunLight.text = name.shajunLight;
|
|
self.zengyangLabel.text = name.zengyangPump;
|
|
self.light1Label.text = name.light1;
|
|
self.light2Label.text = name.light2;
|
|
self.zaolangLabel.text = name.zaolangPump;
|
|
self.huliLabel.text = name.huLiDeng;
|
|
self.xunhuanLabel.text = name.xunhuanPump;
|
|
self.jiareLabel.text = name.jiaRe;
|
|
}
|
|
|
|
#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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[[IfishDataUnity shareDataInstance] 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.isNewdevice = YES;
|
|
vc.erdevicemodel=self.currentDevice;
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
|
|
|
#pragma mark -设置页面 -
|
|
- (void)setting {
|
|
XuToSetViewController * _xuToSetVC=[[XuToSetViewController alloc] init];
|
|
_xuToSetVC.currentdevice=self.currentDevice;
|
|
_xuToSetVC.isNewDevice = YES;
|
|
[self.navigationController pushViewController:_xuToSetVC animated:YES];
|
|
}
|
|
|
|
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
|
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
|
|
[alert show];
|
|
|
|
}
|
|
|
|
|
|
@end
|