ThingsForcedDelViewController.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // ThingsDelPlugViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 3. 21..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "ThingsForcedDelViewController.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "CustomImageView.h"
  12. #import "ThingsForcedDelCompleteViewController.h"
  13. // 오프라인 장치 강제 삭제
  14. @interface ThingsForcedDelViewController () {
  15. NSTimer *_timer;
  16. NSInteger _elapsedSeconds;
  17. CommandModel *_startCommand;
  18. CommandModel *_stopCommand;
  19. }
  20. @end
  21. @implementation ThingsForcedDelViewController
  22. // 가스 밸브 타이틀 : 가스 밸브 삭제
  23. // 가스 밸브 삭제 코멘트 : 동일
  24. // 가스 밸브 이미지명 : img_things_product_addimg_01_smartgasvalve
  25. // 도어센서 타이틀 : 도어 센서 삭제
  26. // 도어센서 삭제 코멘트 : 동일
  27. // 도어센서 이미지 명 : img_things_product_addimg_02_mutisensor_door
  28. // 스마트플러그 타이틀 : 스마트 플러그 삭제
  29. // 스마트플러그 삭제 코멘트 : 동일
  30. // 스마트플러그 이미지 명 : img_things_product_addimg_03_smartplug
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self initUI];
  34. [self prepareViewDidLoad];
  35. }
  36. - (void)viewDidAppear:(BOOL)animated {
  37. [super viewDidAppear:animated];
  38. [UIView animateWithDuration:kfAnimationDur animations:^{
  39. _maskView.alpha = 0.7;
  40. } completion:^(BOOL finished) {
  41. // _constraintPopViewTop.constant = (IPHONE_HEIGHT - _popView.height) / 2;
  42. [UIView animateWithDuration:kfAnimationDur animations:^{
  43. [self.view layoutIfNeeded];
  44. }];
  45. }];
  46. }
  47. - (void)initUI {
  48. // [self initTableViewAsDefaultStyle:_tableView];
  49. [self startLoading:NO];
  50. }
  51. - (void)prepareViewDidLoad {
  52. // [self startLoading:NO];
  53. _imgThings.image = [_delDevice imgaeForAddDel];
  54. _lblManufacturer.text = [_delDevice manufacturerName];
  55. _lblTitle.text = [NSString stringWithFormat:@"%@ 삭제", _delDevice.prdName];
  56. }
  57. #pragma mark - Main Logic
  58. - (void)requestForceDelDevice:(BOOL)isStart {
  59. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_DEVICE_COMMAND];
  60. NSDictionary *param = @{@"device_id": _delDevice.deviceId,
  61. @"command_type":isStart? CMD_TYPE_FORCE_NODE_DEL:CMD_TYPE_PAIRING_STOP,
  62. @"request_value":@{@"failed_node": _delDevice.nodeId},
  63. @"cust_id": [[JDFacade facade].loginUser custId],
  64. @"ctrt_grp_id": [[JDFacade facade].loginUser ctrtGrpId]};
  65. [request setRequestMsg:param];
  66. NSLog(@"Request : %@", request);
  67. [self sendDataToSocket:request modelClass:[CommandModel class]];
  68. }
  69. -(void)startLoading:(BOOL)isStart {
  70. _imgLoading.hidden = !isStart;
  71. if (isStart) {
  72. _elapsedSeconds = kMaxTimeOut;
  73. NSLog(@"ElapsedSecond : %zd", _elapsedSeconds);
  74. if (!_timer) {
  75. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateInclusionStatus) userInfo:nil repeats:YES];
  76. }
  77. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  78. if ([_imgLoading.layer animationForKey:@"SpinAnimation"] == nil) {
  79. CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  80. animation.fromValue = [NSNumber numberWithFloat:0.0f];
  81. animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
  82. animation.duration = 2.0f;
  83. animation.repeatCount = INFINITY;
  84. [_imgLoading.layer addAnimation:animation forKey:@"SpinAnimation"];
  85. }
  86. });
  87. }
  88. else {
  89. _elapsedSeconds = kMaxTimeOut;
  90. if (_timer) {
  91. [_timer invalidate];
  92. _timer = nil;
  93. }
  94. if ([_imgLoading.layer animationForKey:@"SpinAnimation"] != nil) {
  95. [_imgLoading.layer removeAnimationForKey:@"SpinAnimation"];
  96. }
  97. }
  98. }
  99. - (void)updateInclusionStatus {
  100. // dispatch_async(dispatch_get_main_queue(), ^(void) {
  101. //
  102. // _elapsedSeconds--;
  103. //
  104. // if (_elapsedSeconds == 0) {
  105. // [self finishDeviceDel:NO];
  106. // }
  107. // });
  108. }
  109. - (void)finishDeviceDel:(BOOL)isSuccess {
  110. [self startLoading:NO];
  111. ThingsForcedDelCompleteViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsForcedDelCompleteViewController" storyboardName:@"Things"];
  112. vc.delDevice = _delDevice;
  113. vc.isSuccess = isSuccess;
  114. // vc.addableDevice = _addableDevice;
  115. [self showTransparencyModalView:vc];
  116. }
  117. - (IBAction)btnCancelTouched:(id)sender {
  118. [self startLoading:NO];
  119. [self dismissViewControllerAnimated:YES completion:nil];
  120. }
  121. - (IBAction)btnStartTouched:(id)sender {
  122. if (![[JDFacade facade].loginUser onlineHomeHubFromSelectedHub:_delDevice]) {
  123. [[JDFacade facade] alert:@"허브가 오프라인 상태입니다. 허브 상태 확인 후 다시 시도해주세요." completionHander:^{
  124. [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  125. }];
  126. return;
  127. }
  128. [self requestForceDelDevice:YES];
  129. }
  130. #pragma mark - SocketService
  131. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result
  132. {
  133. // NSLog(@"Result Info : %@", result);
  134. // NSLog(@"Result Info : %@", message);
  135. //
  136. // if (result.messageType) {
  137. // <#statements#>
  138. // }
  139. // NSLog(@"Message Type : %@", result.messageType);
  140. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_DEVICE_COMMAND]) {
  141. CommandModel *response = (CommandModel *)message;
  142. if (result.isSuccess) {
  143. if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_FORCE_NODE_DEL]) {
  144. [self startLoading:YES];
  145. _startCommand = response;
  146. }
  147. }
  148. else {
  149. [self finishDeviceDel:NO];
  150. }
  151. }
  152. }
  153. - (void) socketDidFailWithError:(NSError *)error {
  154. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  155. }
  156. -(void) receiveSocketData:(NSNotification *)notification {
  157. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  158. CommandModel *response = [[CommandModel alloc] initWithDictionary:notification.object error:nil];
  159. //NSLog(@"Result : %@", result);
  160. //NSLog(@"Response : %@", response);
  161. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_DEVICE_COMMAND_RES]) {
  162. //NSLog(@"Response : %@", response);
  163. if (result.isSuccess) {
  164. if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_FORCE_NODE_DEL]) {
  165. // if ([response.commandId isEqualToString:_startCommand.commandId]) {
  166. // [self startLoading:YES];
  167. // }
  168. if (![response.commandStatus isEquestToIgnoreCase:@"SUCCESS"]) {
  169. [self finishDeviceDel:NO];
  170. }
  171. }
  172. }
  173. else {
  174. [self finishDeviceDel:NO];
  175. }
  176. }
  177. else if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_DELETE_RES]) {
  178. // [self requestIncludeDevice:NO];
  179. SoKNodeModel *result = [[SoKNodeModel alloc] initWithDictionary:notification.object error:nil];
  180. // if ([result.nodeId]) {
  181. // <#statements#>
  182. // }
  183. [self finishDeviceDel:[result.delYn isEquestToIgnoreCase:@"Y"]];
  184. }
  185. }
  186. - (void)didReceiveMemoryWarning {
  187. [super didReceiveMemoryWarning];
  188. }
  189. @end