CommandClassControlDetailView.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 275.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. _lblContentValueMsg.text = _node.contentValueMsg;
  82. _btnNode.userInteractionEnabled = NO;
  83. [_btnOn setImage:[_btnOn imageForState:_btnOn.state] forState:_btnOn.state];
  84. [_btnOff setImage:[_btnOff imageForState:_btnOff.state] forState:_btnOff.state];
  85. }
  86. - (void)startProgressAni {
  87. //chagne button image
  88. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  89. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  90. } completion:nil];
  91. }
  92. - (void)stopProgressAni {
  93. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  94. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  95. } completion:^(BOOL finished) {
  96. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  97. _btnNode.selected = _btnNode.enabled && _isON;
  98. [self checkOffline];
  99. }];
  100. }
  101. - (void)checkOffline {
  102. if (!_btnNode.enabled) {//online?
  103. self.lblContentValueMsg.text = @"OFFLINE";
  104. [self.lblContentValueMsg setColor:kUITextColor01 text:self.lblContentValueMsg.text];
  105. }
  106. }
  107. @end
  108. @implementation CommandClassValveDetailView
  109. - (void)setLayoutUI {
  110. [super setLayoutUI];
  111. self.height = 347.0f;
  112. NSString *stmp = @"잠그기";
  113. CGFloat width = [CommonUtil getSizeFromString:stmp font:_btnClose.titleLabel.font width:FLT_MAX].width;// + kfSwitchLabelPadding;
  114. CGFloat eWidth = width + kfControlDetailSwtchLeftPadding + kfControlDetailSwtchRightPadding;
  115. _constraintBtnWidth.constant = eWidth;
  116. _btnClose.titleEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 28);
  117. [self checkOffline];
  118. }
  119. - (IBAction)btnCloseTouched:(id)sender {
  120. if (!_isOpened) {
  121. [[JDFacade facade] toast:@"이미 잠긴 상태입니다"];
  122. return;
  123. }
  124. [self requestNodeCommand:self.parameterForNodeCommand requestValue:_requestValueForClose completionHandler:nil failureHandler:nil];
  125. }
  126. - (void)setSwitchBinary {
  127. _pcontainer.hidden = !_node.isRequesting;
  128. if (!_pcontainer.hidden) {
  129. [self startProgressAni];
  130. } else {
  131. [self stopProgressAni];
  132. }
  133. _btnClose.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  134. _lblContentValueMsg.text = _node.contentValueMsg;
  135. [_btnClose setImage:[_btnClose imageForState:_btnClose.state] forState:_btnClose.state];
  136. }
  137. - (void)startProgressAni {
  138. //chagne button image
  139. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  140. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  141. } completion:nil];
  142. }
  143. - (void)stopProgressAni {
  144. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  145. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  146. } completion:^(BOOL finished) {
  147. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  148. _btnNode.selected = _btnNode.enabled && _isOpened;
  149. [self checkOffline];
  150. }];
  151. }
  152. - (void)checkOffline {
  153. if (!_btnNode.enabled) {//online?
  154. self.lblContentValueMsg.text = @"OFFLINE";
  155. [self.lblContentValueMsg setColor:kUITextColor01 text:self.lblContentValueMsg.text];
  156. }
  157. }
  158. @end
  159. #pragma mark - Sensors View
  160. @implementation CommandClassSensorBinaryDetailView
  161. - (void)setLayoutUI {
  162. [super setLayoutUI];
  163. _lblNodeName.hidden = !_isMandatoryNode;
  164. if (!_lblNodeName.hidden) {
  165. _lblNodeName.text = _device.nodeName;
  166. }
  167. _btnNode.userInteractionEnabled = NO;
  168. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateNormal] forState:UIControlStateNormal];
  169. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateSelected] forState:UIControlStateSelected];
  170. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateDisabled] forState:UIControlStateDisabled];
  171. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  172. _btnNode.selected = _btnNode.enabled && [_node.contentValue isEqualToString:@"TRUE"];
  173. if (_btnNode.enabled) {//online?
  174. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  175. if ([_device.contentValue isEqualToString:@"TRUE"]) {
  176. [self.lblControl setColor:kUITextColor02 text:self.lblControl.text];
  177. }
  178. } else {
  179. self.lblControl.text = @"OFFLINE";
  180. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  181. }
  182. }
  183. @end
  184. @implementation CommandClassSensorMultiLevelDetailView
  185. - (void)setLayoutUI {
  186. [super setLayoutUI];
  187. _btnNode.userInteractionEnabled = NO;
  188. _lblNodeName.hidden = !_isMandatoryNode;
  189. if (!_lblNodeName.hidden) {
  190. _lblNodeName.text = _device.nodeName;
  191. }
  192. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateNormal] forState:UIControlStateNormal];
  193. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateSelected] forState:UIControlStateSelected];
  194. [_btnNode setImage:[_node imageForMandataryForState:UIControlStateDisabled] forState:UIControlStateDisabled];
  195. _btnNode.enabled = _node.isDeviceOnline && [JDFacade facade].loginUser.isHomehubOnline;
  196. _btnNode.selected = _btnNode.enabled && [_node.contentValue isEqualToString:@"TRUE"];
  197. _lblCondition.hidden = !_node.isDeviceOnline || ![JDFacade facade].loginUser.isHomehubOnline;
  198. _lblCondition.text = [_node conditionForMandatary];
  199. if (_btnNode.enabled) {//online?
  200. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  201. } else {
  202. self.lblControl.text = @"OFFLINE";
  203. [self.lblControl setColor:kUITextColor01 text:self.lblControl.text];
  204. }
  205. }
  206. @end