ThingsDetailViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //
  2. // ThingsDetailViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/16/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "RequestHandler.h"
  9. #import "DeviceModel.h"
  10. #import "CustomImageView.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTextField.h"
  13. #import "CustomButton.h"
  14. #import "UIImageView+WebCache.h"
  15. #import "CommandClassControlDetailView.h"
  16. #import "ThingsModifyViewController.h"
  17. #import "ThingsInfoViewController.h"
  18. #import "ThingsDetailViewController.h"
  19. #import "ValidateUtil.h"
  20. #import "ThingsViewController.h"
  21. #import "CustomAlertView.h"
  22. #import "ModifySecureKeyPopupView.h"
  23. @implementation ThingsDetailImageViewCell
  24. - (void)awakeFromNib {
  25. self.backgroundColor = [UIColor clearColor];
  26. self.selectionStyle = UITableViewCellSelectionStyleNone;
  27. }
  28. @end
  29. @implementation ThingsDetailControlViewCell
  30. - (void)awakeFromNib {
  31. self.backgroundColor = [UIColor clearColor];
  32. self.selectionStyle = UITableViewCellSelectionStyleNone;
  33. }
  34. @end
  35. @interface ThingsDetailViewController () <UITableViewDataSource, UITableViewDelegate> {
  36. DeviceDetailModel *_deviceDetail;
  37. ThingsModifyViewController *_mvc;
  38. ThingsInfoViewController *_ivc;
  39. CGFloat _containerBottom;
  40. BOOL _isNotFirstLoading;
  41. CustomTextField2 *_txtDeviceName;
  42. CustomImageView *_imgvDevice;
  43. ModifySecureKeyPopupView *_kpopup;
  44. }
  45. @end
  46. #pragma mark - Class Definition
  47. @implementation ThingsDetailViewController
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. // Do any additional setup after loading the view.
  51. [self initUI];
  52. [self prepareViewDidLoad];
  53. }
  54. - (void)viewWillAppear:(BOOL)animated {
  55. [super viewWillAppear:animated];
  56. self.title = NSLocalizedString(@"내 장치 상세",nil);
  57. }
  58. - (void)initUI {
  59. [self generateOptionButton];
  60. //initialize tableView
  61. _tableView.dataSource = self;
  62. _tableView.delegate = self;
  63. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. _tableView.backgroundColor = [UIColor clearColor];
  65. _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  66. _txtDeviceName.keyboardType = UIKeyboardTypeDefault;
  67. _txtDeviceName.returnKeyType = UIReturnKeyDone;
  68. }
  69. - (void)setThingsDetailPopoverOptions {
  70. //set Popover Contents
  71. __weak typeof(self) weakSelf = self;
  72. _popooverOptionArray = [[NSMutableArray alloc] init];
  73. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
  74. @"iconName": @"tp_01_img_bg_morepopup_icon_refresh",
  75. @"target": weakSelf,
  76. @"selector": [NSValue valueWithPointer:@selector(requestDeviceDetails)]}];
  77. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"장치 정보 보기",nil),
  78. @"iconName": @"tp_01_img_bg_morepopup_icon_detail",
  79. @"target": weakSelf,
  80. @"selector": [NSValue valueWithPointer:@selector(showThingsDetailInfo)]}];
  81. if ([JDFacade facade].loginUser.level > 10) {
  82. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"이름/아이콘 변경",nil),
  83. @"iconName": @"tp_01_img_bg_morepopup_icon_edit",
  84. @"target": weakSelf,
  85. @"selector": [NSValue valueWithPointer:@selector(modifyThingsName)]}];
  86. if (_deviceDetail.activationCode && ![_deviceDetail.activationCode isEmptyString]){//device_type = controller_primary
  87. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"장치등록 보안키 변경", @"장치등록 보안키 변경"),
  88. @"iconName": @"tp_01_img_bg_morepopup_icon_edit",
  89. @"target": weakSelf,
  90. @"selector": [NSValue valueWithPointer:@selector(modifySecureKey)]}];
  91. }
  92. if ([_deviceDetail.deviceProfileId isEqualToString:ksDeviceProfileIdUnknown]) {//장치가 언노운일 경우,
  93. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"장치유형 선택", @"장치유형 선택"),
  94. @"iconName": @"tp_01_img_bg_morepopup_icon_dtype",
  95. @"target": weakSelf,
  96. @"selector": [NSValue valueWithPointer:@selector(modifyDeviceType)]}];
  97. }
  98. //FIXME : for demo
  99. // if ([_deviceDetail.removableYn boolValue]) {//삭제 가능일 경우,
  100. if ([_deviceDetail.deviceProfileId isEqualToString:@"20028"] || [_deviceDetail.deviceProfileId isEqualToString:@"20029"]) {
  101. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"장치 삭제",nil),
  102. @"iconName": @"tp_01_img_bg_morepopup_icon_del",
  103. @"target": weakSelf,
  104. @"selector": [NSValue valueWithPointer:@selector(removeThings)]}];
  105. }
  106. }
  107. }
  108. - (void)prepareViewDidLoad {
  109. [self performSelector:@selector(requestDeviceDetails) withObject:nil afterDelay:0.0f];
  110. }
  111. #pragma mark - Main Logic
  112. - (void)requestDeviceDetails {
  113. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_DETAIL, _device.deviceId];
  114. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[DeviceDetailModel class] completion:^(id responseObject) {
  115. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  116. return;
  117. }
  118. _deviceDetail = (DeviceDetailModel *)responseObject;
  119. if (_deviceDetail) {//API 성공 ,
  120. [self resetOptions]; //옵션 메뉴 초기화
  121. [self setThingsDetailPopoverOptions];
  122. [self setDeviceContents];
  123. }
  124. } failure:^(id errorObject) {
  125. JDErrorModel *error = (JDErrorModel *)errorObject;
  126. [[JDFacade facade] alert:error.errorMessage];
  127. }];
  128. }
  129. - (void)setDeviceContents {
  130. [_tableView reloadData];
  131. }
  132. - (void)requestDeviceUpdate {
  133. //parameters
  134. NSDictionary *parameter = @{@"image_sequence": _mvc && _mvc.selectedIcon ? _mvc.selectedIcon.imageSequence : ksEmptyString,
  135. @"device_name": _txtDeviceName.text};
  136. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_UPDATE, _deviceDetail.deviceId];
  137. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  138. _device.deviceName = _deviceDetail.deviceName = _txtDeviceName.text;
  139. _device.imageFileName = _deviceDetail.imageFileName = _mvc && _mvc.selectedIcon ? _mvc.selectedIcon.imageFileName : _device.imageFileName;
  140. [self closeChildViewController:_mvc completionHandler:nil];
  141. [_tableView reloadData];
  142. //리스트를 다시 로드함.
  143. // ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
  144. // [vc.tableView reloadData];
  145. } failure:^(id errorObject) {
  146. JDErrorModel *error = (JDErrorModel *)errorObject;
  147. [[JDFacade facade] alert:error.errorMessage];
  148. }];
  149. }
  150. - (void)requestDeleteDevice {
  151. //parameters
  152. NSString *path = [NSString stringWithFormat:API_DELETE_DEVICE, _deviceDetail.deviceId];
  153. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
  154. [[JDFacade facade] toast:NSLocalizedString(@"장치가 삭제되었습니다", @"장치가 삭제되었습니다")];
  155. // if ([JDFacade facade].loginHomeGroup.deviceId && ![[JDFacade facade].loginHomeGroup.deviceId isEmptyString]) {
  156. // if ([[JDFacade facade].loginHomeGroup.deviceId isEqualToString:_deviceDetail.deviceId]) {//현재 홈의 스마튼폰일 경우,
  157. // [JDFacade facade].loginHomeGroup.deviceId = nil;
  158. // [JDFacade facade].loginHomeGroup.deviceAuthorization = nil;
  159. // [JDFacade facade].loginHomeGroup.deviceKey = nil;
  160. // }
  161. // }
  162. //리스트를 다시 로드함.
  163. ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
  164. [vc prepareViewDidLoad];
  165. [self.navigationController popToRootViewControllerAnimated:YES];
  166. } failure:^(id errorObject) {
  167. JDErrorModel *error = (JDErrorModel *)errorObject;
  168. [[JDFacade facade] alert:error.errorMessage];
  169. }];
  170. }
  171. //장치등록 보안키 변경
  172. - (void)requestModifySecureKey {
  173. //parameters
  174. NSDictionary *parameter = @{@"device_id": _deviceDetail.deviceId,
  175. @"change_device_password": _kpopup.txtSecureCode.text};
  176. NSString *path = [NSString stringWithFormat:ksEmptyString];//API_POST_PARTNER_PASSWD];
  177. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  178. [[JDFacade facade] toast:NSLocalizedString(@"변경되었습니다", @"변경되었습니다")];
  179. } failure:^(id errorObject) {
  180. JDErrorModel *error = (JDErrorModel *)errorObject;
  181. [[JDFacade facade] alert:error.errorMessage];
  182. }];
  183. }
  184. #pragma mark - UITableView DataSource & Delegate
  185. - (ThingsDetailImageViewCell *)imageCell {
  186. return (ThingsDetailImageViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
  187. }
  188. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  189. return 1;
  190. }
  191. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  192. return _deviceDetail.nodes ? _deviceDetail.nodes.count + 1 : 0; //append for ImageCell
  193. }
  194. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  195. CGFloat height = 0.0f, titlePadding = 0.0f;
  196. if (indexPath.row == 0) {
  197. height = 152.0f;
  198. } else {
  199. NodeModel *node = _deviceDetail.nodes[indexPath.row-1];
  200. //다원플러그일 경우,
  201. BOOL isControlDAWONPlug = [_deviceDetail.deviceMfId isEqualToString:@"DAWON"] && [_deviceDetail.deviceProfileId isEqualToString:@"20004"];
  202. CommandClassControlView *controlView = nil;
  203. if (node.cmdclsType == CmdClsTypeMeterCurrent && isControlDAWONPlug) {
  204. controlView = [CommandClassControlDetailView viewForCommandClass:CmdClsTypeMeterCurrentForDAWON];
  205. } else if (node.cmdclsType == CmdClsTypeMeterTotal && isControlDAWONPlug) {
  206. controlView = [CommandClassControlDetailView viewForCommandClass:CmdClsTypeMeterTotalForDAWON];
  207. titlePadding = indexPath.row < _deviceDetail.nodes.count ? 25 : 50;
  208. } else {
  209. controlView = [CommandClassControlDetailView viewForCommandClass:node.cmdclsType];
  210. titlePadding = 50.0f;
  211. }
  212. controlView.node = node;
  213. height = titlePadding + [controlView sizeForIntrinsic].height; //title label + margin
  214. }
  215. return height;
  216. }
  217. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  218. NSString *cellIdentifier = indexPath.row == 0 ? @"ImageCellIdentifier" : @"CellIdentifier";
  219. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  220. if (cell == nil) {
  221. if (indexPath.row == 0) {
  222. ThingsDetailImageViewCell *icell = [[ThingsDetailImageViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  223. cell = icell;
  224. } else {
  225. ThingsDetailControlViewCell *cCell = [[ThingsDetailControlViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  226. cell = cCell;
  227. }
  228. }
  229. if (indexPath.row == 0) {//디바이스 이미지 및 네임.
  230. ThingsDetailImageViewCell *icell = (ThingsDetailImageViewCell *)cell;
  231. icell.lblDeviceName.text = _deviceDetail.deviceName;
  232. icell.txtDeviceName.text = _deviceDetail.deviceName;
  233. [icell.imgvDevice sd_setImageWithURL:[NSURL URLWithString:_deviceDetail.imageFileName] placeholderImage:nil];
  234. if (_deviceDetail.networkYn && ![_deviceDetail.networkYn isEqualToString:@"none"] && ![_deviceDetail.networkYn boolValue]) {
  235. if (!icell.imgvDevice.subviews.count) {
  236. UIImageView *imgvOffline = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tp_01_img_things_offline_cover"]];
  237. CGRect ir = icell.imgvDevice.frame;
  238. ir.origin = (CGPoint){.x=0, .y=0};
  239. imgvOffline.frame = ir;
  240. [icell.imgvDevice addSubview:imgvOffline];
  241. } else {
  242. [icell.imgvDevice bringSubviewToFront:icell.imgvDevice.subviews.firstObject];
  243. }
  244. } else {
  245. if (icell.imgvDevice.subviews.count) {
  246. [icell.imgvDevice.subviews.firstObject removeFromSuperview];
  247. }
  248. }
  249. if (!_txtDeviceName) {
  250. _txtDeviceName = icell.txtDeviceName;
  251. }
  252. if (!_imgvDevice) {
  253. _imgvDevice = icell.imgvDevice;
  254. }
  255. icell.txtDeviceName.alpha = 0.0f;
  256. } else {
  257. NodeModel *node = _deviceDetail.nodes[indexPath.row-1];
  258. ThingsDetailControlViewCell *cCell = (ThingsDetailControlViewCell *)cell;
  259. //뷰를 초기화함.
  260. [[cCell.controlContainerView subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  261. UIView *subview = (UIView *)obj;
  262. [subview removeFromSuperview];
  263. }];
  264. cCell.lblNodeTitle.text = node.nodeName;
  265. //다원플러그일 경우,
  266. BOOL isControlDAWONPlug = [_deviceDetail.deviceMfId isEqualToString:@"DAWON"] && [_deviceDetail.deviceProfileId isEqualToString:@"20004"];
  267. CommandClassControlView *controlView = nil;
  268. if (node.cmdclsType == CmdClsTypeSensorBinary) {//미터 커렌트 - 그래프
  269. controlView = [CommandClassControlDetailView viewForCommandClass:CmdClsTypeMeterCurrentForDAWON];
  270. cCell.constraintContainerTop.constant = 0;
  271. cCell.constraintNodeTitleLeft.constant = 0;
  272. cCell.constraintNodeTitleTop.constant = ([controlView sizeForIntrinsic].height / 2) - (25/2) - 15;
  273. cCell.lblNodeTitle.textAlignment = NSTextAlignmentCenter;
  274. } else if (node.cmdclsType == CmdClsTypeMeterTotal && isControlDAWONPlug) {//미터 토탈 - 아이콘
  275. controlView = [CommandClassControlDetailView viewForCommandClass:CmdClsTypeMeterTotalForDAWON];
  276. cCell.constraintContainerTop.constant = 25;
  277. cCell.constraintNodeTitleLeft.constant = 120;
  278. cCell.constraintNodeTitleTop.constant = 28;
  279. cCell.lblNodeTitle.textAlignment = NSTextAlignmentLeft;
  280. } else {
  281. controlView = [CommandClassControlDetailView viewForCommandClass:node.cmdclsType];
  282. cCell.constraintContainerTop.constant = 25;
  283. cCell.constraintNodeTitleLeft.constant = 0;
  284. cCell.constraintNodeTitleTop.constant = 0;
  285. cCell.lblNodeTitle.textAlignment = NSTextAlignmentCenter;
  286. }
  287. node.deviceId = _deviceDetail.deviceId;
  288. controlView.node = node;
  289. cCell.controlContainerView.hidden = !controlView;
  290. if (!cCell.controlContainerView.hidden) {
  291. UIView *superview = cCell.controlContainerView;
  292. cCell.constraintContainerHeight.constant = [controlView sizeForIntrinsic].height;
  293. [superview addSubview:controlView];
  294. [controlView mas_makeConstraints:^(MASConstraintMaker *make) {
  295. make.size.mas_equalTo(controlView.frame.size);
  296. make.center.equalTo(superview);
  297. }];
  298. // NSLog(@"%s\n %@", __PRETTY_FUNCTION__, cCell.controlContainerView);
  299. }
  300. }
  301. return cell;
  302. }
  303. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  304. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  305. }
  306. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  307. // Remove seperator inset
  308. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  309. [cell setSeparatorInset:UIEdgeInsetsZero];
  310. }
  311. // Prevent the cell from inheriting the Table View's margin settings
  312. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  313. [cell setPreservesSuperviewLayoutMargins:NO];
  314. }
  315. // Explictly set your cell's layout margins
  316. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  317. [cell setLayoutMargins:UIEdgeInsetsZero];
  318. }
  319. }
  320. #pragma mark - UI Events
  321. //상세 보기
  322. - (void)showThingsDetailInfo {
  323. if ([_mvc.view superview]) {
  324. [self closeChildViewController:_mvc completionHandler:^{
  325. [self showThingsDetailInfo];
  326. }];
  327. return;
  328. }
  329. _tableView.scrollEnabled = NO;
  330. if (!_ivc) {
  331. _ivc = (ThingsInfoViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsInfoViewController" storyboardName:@"Things"];
  332. _ivc.deviceDetail = _deviceDetail;
  333. [self addChildViewController:_ivc];
  334. [_ivc didMoveToParentViewController:self];
  335. }
  336. [_containerView addSubview:_ivc.view];
  337. if (![_ivc.btnClose actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  338. __weak typeof(self) weakSelf = self;
  339. [_ivc.btnClose addTarget:weakSelf action:@selector(btnCloseTouched:) forControlEvents:UIControlEventTouchUpInside];
  340. }
  341. _containerBottom = _constraintContainerBottom.constant;
  342. _constraintContainerBottom.constant = 0.0f;
  343. [UIView animateWithDuration:kfAnimationDur animations:^{
  344. [_containerView layoutIfNeeded];
  345. }];
  346. }
  347. //장치명 변경
  348. - (void)modifyThingsName {
  349. if ([_ivc.view superview]) {
  350. [self closeChildViewController:_ivc completionHandler:^{
  351. [self modifyThingsName];
  352. }];
  353. return;
  354. }
  355. _tableView.scrollEnabled = NO;
  356. if (!_mvc) {
  357. _mvc = (ThingsModifyViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsModifyViewController" storyboardName:@"Things"];
  358. _mvc.device = _deviceDetail;
  359. [self addChildViewController:_mvc];
  360. [_mvc didMoveToParentViewController:self];
  361. }
  362. [_containerView addSubview:_mvc.view];
  363. if (![_mvc.btnSave actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  364. __weak typeof(self) weakSelf = self;
  365. [_mvc.btnSave addTarget:weakSelf action:@selector(btnSaveTouched:) forControlEvents:UIControlEventTouchUpInside];
  366. [_mvc.btnCancel addTarget:weakSelf action:@selector(btnCancelTouched:) forControlEvents:UIControlEventTouchUpInside];
  367. }
  368. _containerBottom = _constraintContainerBottom.constant;
  369. _constraintContainerBottom.constant = 0.0f;
  370. [UIView animateWithDuration:kfAnimationDur animations:^{
  371. [self imageCell].txtDeviceName.alpha = 1.0f;
  372. [self imageCell].lblDeviceName.alpha = 0.0f;
  373. [_containerView layoutIfNeeded];
  374. }];
  375. }
  376. //장치등록 보안키 변경
  377. - (void)modifySecureKey {
  378. if (!_kpopup) {
  379. _kpopup = [[ModifySecureKeyPopupView alloc] initFromNib];
  380. }
  381. [_kpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  382. if (buttonIndex == 0) {//OK
  383. [self requestModifySecureKey];
  384. }
  385. }];
  386. }
  387. //장치 유형 변경
  388. - (void)modifyDeviceType {
  389. //goto choose device type
  390. }
  391. //디바이스 삭제
  392. - (void)removeThings {
  393. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") message:NSLocalizedString(@"장치를 삭제하시겠습니까?\n이 장치에 속한 하위 장치가 있을 경우 함께 삭제됩니다\n\n이 장치를 사용중인 홈 규칙과\n멀티 제어가 비활성 상태로 변경됩니다\n\n신중하게 결정하세요", @"장치를 삭제하시겠습니까?\n이 장치에 속한 하위 장치가 있을 경우 함께 삭제됩니다\n\n이 장치를 사용중인 홈 규칙과\n멀티 제어가 비활성 상태로 변경됩니다\n\n신중하게 결정하세요") delegate:nil OKButtonTitle:NSLocalizedString(@"삭제", @"삭제") cancelButtonTitle:NSLocalizedString(@"취소", @"취소")];
  394. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  395. if (buttonIndex == 0) {//OK
  396. //삭제 후 장치목록으로 이동요
  397. [self requestDeleteDevice];
  398. }
  399. }];
  400. }
  401. - (void)btnSaveTouched:(id)sender {
  402. //validate
  403. if (!_txtDeviceName || ![ValidateUtil validateTextfiled:_txtDeviceName type:ValidateTypeNull title:NSLocalizedString(@"장치명", @"장치명")]) {
  404. return;
  405. }
  406. //TOOD : request
  407. [self requestDeviceUpdate];
  408. }
  409. - (void)btnCancelTouched:(id)sender {
  410. [self closeChildViewController:_mvc completionHandler:nil];
  411. }
  412. - (void)closeChildViewController:(UIViewController *)vc completionHandler:(JDFacadeCompletionCallBackHandler)completionHander {
  413. _constraintContainerBottom.constant = _containerBottom;
  414. [UIView animateWithDuration:kfAnimationDur animations:^{
  415. [self imageCell].txtDeviceName.alpha = 0.0f;
  416. [self imageCell].lblDeviceName.alpha = 1.0f;
  417. [self.view layoutIfNeeded];
  418. } completion:^(BOOL finished) {
  419. _tableView.scrollEnabled = YES;
  420. [vc.view removeFromSuperview];
  421. if (completionHander) {
  422. completionHander();
  423. }
  424. }];
  425. }
  426. - (void)btnCloseTouched:(id)sender {
  427. [self closeChildViewController:_ivc completionHandler:nil];
  428. }
  429. #pragma mark - MemoryWarning
  430. - (void)didReceiveMemoryWarning
  431. {
  432. [super didReceiveMemoryWarning];
  433. // Dispose of any resources that can be recreated.
  434. }
  435. @end