ifish/Ifish/controllers/IfishYooseeFile/IfishYooseeControlller/IfishcameraBottomHView/CameraRecordViewController.m

370 lines
14 KiB
Objective-C

//
// CameraRecordViewController.m
// Ifish
//
// Created by imac on 16/12/9.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "CameraRecordViewController.h"
#import "P2PClient.h"
#import "IfishCameraRecordfirstCell.h"
#import "IfishCameraRecordSecondCell.h"
#import "IfishCameraRecordThirdCell.h"
#import "TemperatureSetModel.h"
#import "TemperatureSetCell.h"
#import "MydatePickerView.h"
#define RECODIEECELL_TIME 911
#define RECODIEECELL_BTN 922
#define RECODIEECELL_SWiTCH 933
static const CGFloat ToastFade = 0.2;
#import "NSTimer+Convenience.h"
#import "IfishCameraRecordFourCell.h"
@interface CameraRecordViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView *tab;
@property(nonatomic) NSInteger second;
@property(nonatomic) NSInteger minute;
@property(nonatomic,strong) NSTimer*timer;
@property(nonatomic,copy) NSString *timestr;
@property (nonatomic, assign) BOOL isConnectCamera;
@property(nonatomic) BOOL isRecording;
@property(nonatomic) NSIndexPath *timerIndex;
@property(nonatomic) NSIndexPath *switchIndex;
@property(nonatomic) NSIndexPath *buttonIndex;
@property(assign) unsigned int remoteRecordState;
//本app 需求模式 非摄像头模式
@property(nonatomic,strong) NSMutableArray*array;
@property(nonatomic,strong) NSString*recordType;
@property (nonatomic, strong)MydatePickerView *mydatepicView;
@end
@implementation CameraRecordViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"录制视频"];
self.recordType=[[DataCenter defaultDtacenter].cache stringForKey:@"recordType"];
if (self.recordType.length)
{
self.recordType=@"0";
}
[self creatUI];
// self.view.backgroundColor = RGB(242, 242, 242);
}
-(void)goBackAction{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)creatUI{
self.tab = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStylePlain];
self.tab.delegate = self;
self.tab.dataSource = self;
self.tab.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tab.showsVerticalScrollIndicator = NO;
self.tab.scrollEnabled = NO;
//self.tab.backgroundColor = RGB(242, 242, 242);
[self.view addSubview:self.tab];
}
-(void)connectDevice{
UserModel *model=[dataContorl getUserInfo];
NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
//初始化设备
if ([GWP2PClient sharedClient].linkStatus != P2PLinkStatusOK) {
NSLog(@"正在检查P2P连接状态");
BOOL connectDevice = [[GWP2PClient sharedClient] connectWithAccount:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2 sessionID1:model.sessionID sessionID2:model.sessionID2 customerIDs:nil];
if (connectDevice) {
[[GWP2PClient sharedClient] setDeviceRecordDefinition:GWP2PRecordDefinitionStandardDefinition withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
}else{
[self.view makeToast:@"p2pConnect failure.失败,不能操作设备,请重试"];
}
}
else
{
[[GWP2PClient sharedClient] setDeviceRecordDefinition:GWP2PRecordDefinitionStandardDefinition withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
#pragma mark - receiveRemoteMessage
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
TemperatureSetCell*cell=[tableView dequeueReusableCellWithIdentifier:@"TemperatureSetCell"];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"TemperatureSetCell" owner:self options:nil]lastObject];
}
cell.backgroundView=nil;
cell.backgroundColor= RGB(242, 242, 242);
if (indexPath.section ==0 && indexPath.row ==0) {
TemperatureSetModel*model=[[TemperatureSetModel alloc]init];
model.title=@"即时录制";
model.temperatureLabel=@"";
model.status=self.recordType;;
cell.titleLabel.text=model.title;
cell.temperaturelabel.text=model.temperatureLabel;
[cell.temPSwitch addTarget:self action:@selector(nowRecordBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateSelected];
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal];
cell.temPSwitch.selected=[model.status isEqualToString:@"1"];
}else if (indexPath.section ==1 && indexPath.row ==0){
TemperatureSetModel*model=[[TemperatureSetModel alloc]init];
model.title=@"定时录制";
model.temperatureLabel=[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"].length?[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"]:@"09:00-16:00";
model.status=self.recordType;;
cell.titleLabel.text=model.title;
cell.temperaturelabel.text=model.temperatureLabel;
[cell.temPSwitch addTarget:self action:@selector(schduleRecordAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateSelected];
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal];
cell.temPSwitch.selected=[model.status isEqualToString:@"2"];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 5;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *sectionV2=[[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width,5)];
sectionV2.backgroundColor =[UIColor whiteColor];
return sectionV2;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==1)
{
if (!self.mydatepicView) {
_mydatepicView=[[MydatePickerView alloc]init];
_mydatepicView.frame=CGRectMake(0,0,kScreenSize.width,kScreenSize.height);
[_mydatepicView setIsNewXuanduo:YES];
[_mydatepicView.picView reloadAllComponents];
[_mydatepicView.cancleButton addTarget:self action:@selector(cancleButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_mydatepicView.sureButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
NSString*time=[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"].length?[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"]:@"09:00-16:00";
NSString*start=[[time componentsSeparatedByString:@"-"] firstObject];
NSString*end=[[time componentsSeparatedByString:@"-"] lastObject];
NSString*startHour=[[start componentsSeparatedByString:@":"] firstObject];
NSString*startMin=[[start componentsSeparatedByString:@":"] lastObject];
NSString*endHour=[[end componentsSeparatedByString:@":"] firstObject];
NSString*endMin=[[end componentsSeparatedByString:@":"] lastObject];
_mydatepicView.startString=startHour;
_mydatepicView.endString=startMin;
_mydatepicView.startString1=endHour;
_mydatepicView.endString1=endHour;
[_mydatepicView.picView selectRow:[(NSArray*)(_mydatepicView.dataArr[0]) indexOfObject:startHour] inComponent:0 animated:YES];
[_mydatepicView.picView selectRow:[(NSArray*)(_mydatepicView.dataArr[1]) indexOfObject:startMin] inComponent:1 animated:YES];
[_mydatepicView.picView selectRow:[(NSArray*)(_mydatepicView.dataArr[2]) indexOfObject:endHour] inComponent:2 animated:YES];
[_mydatepicView.picView selectRow:[(NSArray*)(_mydatepicView.dataArr[3]) indexOfObject:endMin] inComponent:3 animated:YES];
}
[self.view addSubview:_mydatepicView];
}
}
#pragma mark - recordBtnAction
#pragma mark 设置时间段
-(void)doneButtonClick{
_mydatepicView.resultString=nil;
if (_mydatepicView.startString==nil||_mydatepicView.endString==nil) {
[self showTitle:@"" messsage:@"请选择时间"];
}else{
_mydatepicView.resultString=[NSString stringWithFormat:@"%@:%@-%@:%@",_mydatepicView.startString,_mydatepicView.endString,_mydatepicView.startString1,_mydatepicView.endString1];
[[DataCenter defaultDtacenter].cache setString:_mydatepicView.resultString forKey:@"schduleRecordTime"];
[_mydatepicView removeFromSuperview];
TemperatureSetCell*cell=[self.tab cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
cell.temperaturelabel.text=_mydatepicView.resultString;
}
}
-(void)cancleButtonClick{
[_mydatepicView removeFromSuperview];
}
-(void)nowRecordBtnAction:(UIButton*)btn{
btn.selected=!btn.selected;
;
if (btn.selected)
{
self.recordType=@"1";
[[DataCenter defaultDtacenter].cache setString:self.recordType forKey:@"recordType"];
[[GWP2PClient sharedClient] setDeviceRecordType:GWP2PRecordTypeManual withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
if (success)
{
[self.view makeToast:@"设置成功"];
}
else
{
[self.view makeToast:@"设置失败"];
}
}];
}else
{
self.recordType=@"0";
[[DataCenter defaultDtacenter].cache setString:self.recordType forKey:@"recordType"];
[[GWP2PClient sharedClient] setDeviceRecordType:GWP2PRecordTypeAlarm withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
NSLog(@"data=%@",dataDictionary);
}];
[[GWP2PClient sharedClient] setDevicePrerecordState:YES withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
[[GWP2PClient sharedClient] setDeviceAlarmRecordTime:3 withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
}
[self.tab reloadData];
}
-(void)schduleRecordAction:(UISwitch*)btn
{
btn.selected=!btn.selected;
if (btn.selected) {
self.recordType=@"2";
[[DataCenter defaultDtacenter].cache setString:self.recordType forKey:@"recordType"];
[[GWP2PClient sharedClient] setDeviceRecordType:GWP2PRecordTypeSchedule withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
NSLog(@"data=%@",dataDictionary);
}];
NSString*time=[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"].length?[[DataCenter defaultDtacenter].cache stringForKey:@"schduleRecordTime"]:@"09:00-16:00";
NSString*start=[[time componentsSeparatedByString:@"-"] firstObject];
NSString*end=[[time componentsSeparatedByString:@"-"] lastObject];
NSString*startHour=[[start componentsSeparatedByString:@":"] firstObject];
NSString*startMin=[[start componentsSeparatedByString:@":"] lastObject];
NSString*endHour=[[end componentsSeparatedByString:@":"] firstObject];
NSString*endMin=[[end componentsSeparatedByString:@":"] lastObject];
[[GWP2PClient sharedClient] setDevicePlanedRecordTimeWithFromHour:startHour.integerValue fromMinute:startMin.integerValue toHour:endHour.integerValue toMinute:endMin.integerValue deviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
if (success)
{
[self.view makeToast:@"设置成功"];
}
else
{
[self.view makeToast:@"设置失败"];
}
}];
}else{
self.recordType=@"0";
[[DataCenter defaultDtacenter].cache setString:self.recordType forKey:@"recordType"];
[[GWP2PClient sharedClient] setDeviceRecordType:GWP2PRecordTypeAlarm withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
NSLog(@"data=%@",dataDictionary);
}];
[[GWP2PClient sharedClient] setDevicePrerecordState:YES withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
[[GWP2PClient sharedClient] setDeviceAlarmRecordTime:3 withDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
}];
}
[self.tab reloadData];
}
@end