CommandClassControlDetailView.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. //
  2. // CommandClassControlDetailView.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/16/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "CustomLabel.h"
  13. #import "CommonUtil.h"
  14. #import "CustomButton.h"
  15. #import "CustomRadioGroup.h"
  16. #import "UIImageView+WebCache.h"
  17. #import "CommandClassControlDetailView.h"
  18. #import "CommandClassControlView.h"
  19. #import "CustomImageView.h"
  20. #define GRAPH_ANI_DUR 0.5f
  21. #define kfControlDetailSwtchLeftPadding 45.0f
  22. #define kfControlDetailSwtchRightPadding 28.0f
  23. #define kfControlDetailDefaultWidth 320.0f
  24. #define kfControlDetailDefaultHeight 285.0f
  25. typedef void(^NodeCommandCompletionBlock)(id result);
  26. typedef void(^NodeCommandFailureBlock)(id error);
  27. @implementation CommandClassControlDetailView
  28. + (CommandClassControlView *)viewForCommandClass:(CmdClsType)cmdClsType
  29. {
  30. CommandClassControlView *controlView = nil;
  31. for (UIView *view in [CommonUtil nibViews:@"CommandClassControlDetailView"]) {
  32. if (view.tag == cmdClsType) {
  33. controlView = (CommandClassControlView *)view;
  34. controlView.width = IPHONE_WIDTH;
  35. controlView.height = kfControlDetailDefaultHeight;
  36. break;
  37. }
  38. }
  39. if (!controlView) {//상위 부모에서 가져옴.
  40. controlView = [CommandClassControlView viewForCommandClass:cmdClsType];
  41. }
  42. return controlView;
  43. }
  44. @end
  45. @implementation CommandClassSwitchDetailView
  46. - (void)setLayoutUI {
  47. [super setLayoutUI];
  48. // self.height = 347.0f;
  49. // NSString *stmp = @"켜기";
  50. // CGFloat width = [CommonUtil getSizeFromString:stmp font:_btnOff.titleLabel.font width:FLT_MAX].width;// + kfSwitchLabelPadding;
  51. // CGFloat eWidth = width + kfControlDetailSwtchLeftPadding + kfControlDetailSwtchRightPadding;
  52. // _constraintBtnSwitchWidth.constant = eWidth;
  53. // _btnOn.titleEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 28);
  54. // _btnOff.titleEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 28);
  55. _btnNode.enabled = _node.isDeviceOnline;
  56. _btnNode.selected = _btnNode.enabled && _isON;
  57. [self checkOffline];
  58. }
  59. - (IBAction)btnOnTouched:(id)sender {
  60. if (_isON) {
  61. [[JDFacade facade] toast:@"이미 켜진 상태입니다"];
  62. return;
  63. }
  64. [self requestNodeCommand:self.parameterForNodeCommand requestValue:_requestValueForOn completionHandler:nil failureHandler:nil];
  65. }
  66. - (IBAction)btnOffTouched:(id)sender {
  67. if (!_isON) {
  68. [[JDFacade facade] toast:@"이미 꺼진 상태입니다"];
  69. return;
  70. }
  71. [self requestNodeCommand:self.parameterForNodeCommand requestValue:_requestValueForOff completionHandler:nil failureHandler:nil];
  72. }
  73. - (void)setSwitchBinary {
  74. _pcontainer.hidden = !_node.isRequesting;
  75. if (!_pcontainer.hidden) {
  76. [self startProgressAni];
  77. } else {
  78. [self stopProgressAni];
  79. }
  80. // _btnOn.enabled = _btnOff.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  81. _btnOn.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  82. _lblContentValueMsg.text = _node.contentValueMsg;
  83. _btnNode.userInteractionEnabled = NO;
  84. [_btnOn setImage:[_btnOn imageForState:_btnOn.state] forState:_btnOn.state];
  85. // [_btnOff setImage:[_btnOff imageForState:_btnOff.state] forState:_btnOff.state];
  86. }
  87. - (void)startProgressAni {
  88. //chagne button image
  89. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  90. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  91. } completion:nil];
  92. }
  93. - (void)stopProgressAni {
  94. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  95. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  96. } completion:^(BOOL finished) {
  97. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  98. _btnNode.selected = _btnNode.enabled && _isON;
  99. [self checkOffline];
  100. }];
  101. }
  102. - (void)checkOffline {
  103. if (!_btnNode.enabled) {//online?
  104. self.lblContentValueMsg.text = @"OFFLINE";
  105. [self.lblContentValueMsg setColor:kUITextColor01 text:self.lblContentValueMsg.text];
  106. }
  107. }
  108. @end
  109. @implementation CommandClassValveDetailView
  110. - (void)setLayoutUI {
  111. [super setLayoutUI];
  112. // self.height = 347.0f;
  113. NSString *stmp = @"잠그기";
  114. CGFloat width = [CommonUtil getSizeFromString:stmp font:_btnClose.titleLabel.font width:FLT_MAX].width;// + kfSwitchLabelPadding;
  115. CGFloat eWidth = width + kfControlDetailSwtchLeftPadding + kfControlDetailSwtchRightPadding;
  116. _constraintBtnWidth.constant = eWidth;
  117. // _btnClose.titleEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 28);
  118. [self checkOffline];
  119. }
  120. - (IBAction)btnCloseTouched:(id)sender {
  121. if (!_isOpened) {
  122. [[JDFacade facade] toast:@"이미 잠긴 상태입니다"];
  123. return;
  124. }
  125. [self requestNodeCommand:self.parameterForNodeCommand requestValue:_requestValueForClose completionHandler:nil failureHandler:nil];
  126. }
  127. - (void)setSwitchBinary {
  128. _pcontainer.hidden = !_node.isRequesting;
  129. if (!_pcontainer.hidden) {
  130. [self startProgressAni];
  131. } else {
  132. [self stopProgressAni];
  133. }
  134. _btnClose.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  135. _lblContentValueMsg.text = _node.contentValueMsg;
  136. [_btnClose setImage:[_btnClose imageForState:_btnClose.state] forState:_btnClose.state];
  137. }
  138. - (void)startProgressAni {
  139. //chagne button image
  140. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  141. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  142. } completion:nil];
  143. }
  144. - (void)stopProgressAni {
  145. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  146. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  147. } completion:^(BOOL finished) {
  148. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  149. _btnNode.selected = _btnNode.enabled && _isOpened;
  150. [self checkOffline];
  151. }];
  152. }
  153. - (void)checkOffline {
  154. if (!_btnNode.enabled) {//online?
  155. self.lblContentValueMsg.text = @"OFFLINE";
  156. [self.lblContentValueMsg setColor:kUITextColor01 text:self.lblContentValueMsg.text];
  157. }
  158. }
  159. @end
  160. #pragma mark - Sensors View
  161. @implementation CommandClassSensorBinaryDetailView
  162. - (void)setLayoutUI {
  163. [super setLayoutUI];
  164. _lblNodeName.hidden = !_isMandatoryNode;
  165. if (!_lblNodeName.hidden) {
  166. _lblNodeName.text = _device.nodeName;
  167. }
  168. _btnNode.userInteractionEnabled = NO;
  169. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateNormal] forState:UIControlStateNormal];
  170. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateSelected] forState:UIControlStateSelected];
  171. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateDisabled] forState:UIControlStateDisabled];
  172. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  173. _btnNode.selected = _btnNode.enabled && [_node.contentValue isEqualToString:@"TRUE"];
  174. if (_btnNode.enabled) {//online?
  175. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  176. if ([_device.contentValue isEqualToString:@"TRUE"]) {
  177. [self.lblControl setColor:kUITextColor02 text:self.lblControl.text];
  178. }
  179. } else {
  180. self.lblControl.text = @"OFFLINE";
  181. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  182. }
  183. }
  184. @end
  185. @implementation CommandClassSensorMultiLevelDetailView
  186. - (void)setLayoutUI {
  187. [super setLayoutUI];
  188. _btnNode.userInteractionEnabled = NO;
  189. _lblNodeName.hidden = !_isMandatoryNode;
  190. if (!_lblNodeName.hidden) {
  191. _lblNodeName.text = _device.nodeName;
  192. }
  193. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateNormal] forState:UIControlStateNormal];
  194. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateSelected] forState:UIControlStateSelected];
  195. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateDisabled] forState:UIControlStateDisabled];
  196. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  197. _btnNode.selected = _btnNode.enabled && [_node.contentValue isEqualToString:@"TRUE"];
  198. _lblCondition.hidden = !_node.isDeviceOnline || ![JDFacade facade].loginUser.isHomehubOnline;
  199. _lblCondition.text = [_node conditionForMandatary];
  200. if (_btnNode.enabled) {//online?
  201. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  202. } else {
  203. self.lblControl.text = @"OFFLINE";
  204. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  205. }
  206. }
  207. @end