ManagementViewController.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // ManagementViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 12..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "CustomLabelButton.h"
  11. #import "ImageUtil.h"
  12. #import "HomeModeUpdateViewController.h"
  13. #import "HomeModeSettingsViewController.h"
  14. #import "PwdPopupView.h"
  15. #import "MainViewController.h"
  16. #import "ManagementViewController.h"
  17. /**
  18. 모드 버튼 Bg Image
  19. on : common_homemode_icon_bg_on
  20. off : common_homemode_icon_bg_off
  21. 모드 버튼 Icon Image
  22. 기상 : common_homemode_icon_wakeup_on , _off
  23. 외출 : common_homemode_icon_outing_on , _off
  24. 귀가 : common_homemode_icon_homecoming_on , _off
  25. 취침 : common_homemode_icon_sleep_on , _off
  26. **/
  27. @interface ManagementViewController ()
  28. {
  29. DashboardModel *_dashboard;
  30. BOOL _isNotFirstLoading;
  31. }
  32. @end
  33. @implementation ManagementViewController
  34. - (void)viewDidLoad {
  35. for (CustomImageView * imgvCheck in _imgvChecked) {
  36. imgvCheck.hidden = YES;
  37. }
  38. [self.navigationController.navigationBar setHidden:YES];
  39. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  40. [super viewDidLoad];
  41. }
  42. - (void)prepareViewDidLoad {
  43. [self setContents];
  44. [self performSelector:@selector(requestDashboard:) withObject:nil afterDelay:0.0f];
  45. }
  46. - (void)updateHomeHubStatusToManage {
  47. [self setContents];
  48. }
  49. - (void)viewWillAppear:(BOOL)animated {
  50. [self requestDashboard:nil];
  51. }
  52. // 공지사항 이동
  53. - (IBAction)btnNoticeTouched:(id)sender {
  54. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"NoticeViewController" storyboardName:@"Main"];
  55. [self presentViewController:vc animated:YES completion:nil];
  56. }
  57. // 자주 찾는 질문 이동
  58. - (IBAction)btnFaqTouched:(id)sender {
  59. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"FaqViewController" storyboardName:@"Main"];
  60. [self presentViewController:vc animated:YES completion:nil];
  61. }
  62. // 메시지 박스 이동
  63. - (IBAction)btnMessageBoxTouched:(id)sender {
  64. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"MessageBoxViewController" storyboardName:@"Main"];
  65. [self presentViewController:vc animated:YES completion:nil];
  66. }
  67. // 홈허브 이동
  68. - (IBAction)btnHomeHubTouched:(id)sender {
  69. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubViewController" storyboardName:@"Main"];
  70. [self presentViewController:vc animated:YES completion:nil];
  71. }
  72. // 설정 이동
  73. - (IBAction)btnSettingsTouched:(id)sender {
  74. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SettingsViewController" storyboardName:@"Settings"];
  75. UINavigationController *m_navi =[[UINavigationController alloc]initWithRootViewController:vc];
  76. [self presentViewController:m_navi animated:YES completion:nil];
  77. }
  78. - (IBAction)btnModeMorningTouched:(id)sender {
  79. [self doChangeHomeMode:HOME_MODE_MORNING];
  80. }
  81. - (IBAction)btnModeAwayTouched:(id)sender {
  82. [self doChangeHomeMode:HOME_MODE_AWAY];
  83. }
  84. - (IBAction)btnModeHomeTouched:(id)sender {
  85. [self doChangeHomeMode:HOME_MODE_HOME];
  86. }
  87. - (IBAction)btnModeNightTouched:(id)sender {
  88. [self doChangeHomeMode:HOME_MODE_NIGHT];
  89. }
  90. //- (void)modeBtnOn:(CustomImageView *)imgvOn {
  91. //
  92. // for (CustomImageView *imgvMode in _imgvModes) {
  93. // if ([imgvMode isEqual:imgvOn]) {
  94. // [imgvMode setHighlighted:YES];
  95. // } else {
  96. // [imgvMode setHighlighted:NO];
  97. // }
  98. // }
  99. //}
  100. //
  101. //- (void)modeBtnCheck:(CustomImageView *)imgvCheck {
  102. //
  103. // for (CustomImageView *imgvChecked in _imgvChecked) {
  104. // if ([imgvChecked isEqual:imgvCheck]) {
  105. // [imgvChecked setHidden:NO];
  106. // } else {
  107. // [imgvChecked setHidden:YES];
  108. // }
  109. // }
  110. //}
  111. //- (IBAction)btnDashboardRefresh:(id)sender {
  112. // [self requestDashboard:nil];
  113. //}
  114. - (void)requestDashboard:(JDFacadeCompletionCallBackHandler)completion {
  115. //parameters
  116. NSDictionary *parameter = @{@"member_id": [JDFacade facade].loginUser.memberId,
  117. @"notice_read_datetime": [JDFacade facade].loginUser.noticeReadTime ? [JDFacade facade].loginUser.noticeReadTime : ksEmptyString,
  118. @"message_read_datetime": [JDFacade facade].loginUser.personalNoticeReadTime ? [JDFacade facade].loginUser.personalNoticeReadTime : ksEmptyString};
  119. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DASHBOARD arguments:nil];
  120. // NSString *path = [NSString stringWithFormat:API_GET_DASHBOARD, [[JDFacade facade].loginUser custId], [[JDFacade facade].loginUser ctrtGrpId]];
  121. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[DashboardModel class] completion:^(id responseObject) {
  122. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  123. return;
  124. }
  125. DashboardModel *dashboard = (DashboardModel *) responseObject;
  126. // NSLog(@"DashBoard Info : %@", responseObject);
  127. NSLog(@"DashBoard Info : %@", dashboard);
  128. NSLog(@"DashBoard Info : %@", dashboard.modeList);
  129. if (dashboard) {//API 성공 ,
  130. _dashboard = dashboard;
  131. // if (!_isNotFirstLoading) {
  132. // _isNotFirstLoading = YES;
  133. // FIXME : 이부분이 어떤 내용인지 파악해야 한다.
  134. // [JDFacade facade].loginUser.homehubDeviceId = _dashboard.deviceId; //초대에서 넘어오는 경우,
  135. // when first loading this view.
  136. // [self initThingsViewController];
  137. //
  138. // self.currentChildViewController = _tvc;
  139. // [_btnThings setHighlighted:YES];
  140. // }
  141. [self setContents];
  142. }
  143. if (completion) {
  144. completion();
  145. }
  146. } failure:^(id errorObject) {
  147. JDErrorModel *error = (JDErrorModel *)errorObject;
  148. [[JDFacade facade] alert:error.errorMessage];
  149. }];
  150. }
  151. //extendView 컨텐츠 설정
  152. - (void)setContents {
  153. _lblNoticeCount.text = _dashboard.noticeCount;
  154. _lblPushCount.text = _dashboard.pushCount;
  155. // _imgvHomehubOff.hidden = [JDFacade facade].loginUser.isHomehubOnline;
  156. if ([_dashboard.deviceEventYn boolValue]) {
  157. _imgvHomehubOff.hidden = YES;
  158. } else {
  159. _imgvHomehubOff.hidden = NO;
  160. }
  161. if ([_dashboard.phoneAuthYn boolValue]) {
  162. _imgvSetAlert.hidden = YES;
  163. } else {
  164. _imgvSetAlert.hidden = NO;
  165. }
  166. // _btnHomeHub.enabled = [JDFacade facade].loginUser.hasHomeHub;
  167. // _btnHomeHub.alpha = _btnHomeHub.enabled ? 1.0f : 0.4f;
  168. //don't delete - FOR KNEET2.0
  169. // [_btnHomegrpImage sd_setImageWithURL:[NSURL URLWithString:_dashboard.imageFileName] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRefreshCached];
  170. NSInteger i = 0;
  171. for (ModeModel *mode in _dashboard.modeList) {//모드버튼 설정
  172. CustomLabelButton *btn = _btnModes[i];
  173. [btn setTitle:mode.modeName];
  174. if (![JDFacade facade].loginUser.hasHomeHub) {//비활성모드 : 홈허브가 없을 경우, 또는 삭제된 경우,
  175. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileDisableName] forState:UIControlStateNormal];
  176. // btn.label.textColor = kUITextColor04;
  177. // btn.label.alpha = 0.4f;
  178. btn.enabled = NO;
  179. btn.imgvMode.highlighted = NO;
  180. btn.imgvBtnBg.highlighted = NO;
  181. btn.imgvCheck.hidden = YES;
  182. } else {
  183. if ([mode.useYn boolValue]) {//활성모드
  184. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileActiveName] forState:UIControlStateNormal];
  185. // btn.label.textColor = kUITextColor01;
  186. // btn.label.alpha = 1.0f;
  187. btn.enabled = YES;
  188. btn.imgvMode.highlighted = YES;
  189. btn.imgvBtnBg.highlighted = YES;
  190. btn.imgvCheck.hidden = NO;
  191. } else {//일반모드
  192. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileName] forState:UIControlStateNormal];
  193. // btn.label.textColor = kUITextColor04;
  194. // btn.label.alpha = 1.0f;
  195. btn.enabled = YES;
  196. btn.imgvMode.highlighted = NO;
  197. btn.imgvBtnBg.highlighted = NO;
  198. btn.imgvCheck.hidden = YES;
  199. }
  200. }
  201. i++;
  202. }
  203. }
  204. - (void)doChangeHomeMode:(NSString *)modeCode {
  205. if (![JDFacade facade].loginUser.isHomehubOnline || ![JDFacade facade].loginUser.hasHomeHub) {
  206. [[JDFacade facade] toast:@"홈허브가 온라인 상태로\n연결되어 있을 때 시도해주세요"];
  207. return;
  208. }
  209. ModeModel *mode = [_dashboard.modeList objectKey:@"basicModeCode" eqaulToString:modeCode];
  210. // 로직 변경
  211. // if (!mode.homegrpSceneId || [mode.homegrpSceneId isEmptyString]) {
  212. //
  213. // if ([JDFacade facade].loginUser.level < 90) {//일반 멤버
  214. // [[JDFacade facade] toast:@"아직 선택된 장치가 없습니다.\r장치선택은 마스터만 할 수 있습니다."];
  215. // } else {
  216. // HomeModeSettingsViewController *vc = (HomeModeSettingsViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeModeSettingsViewController" storyboardName:@"Main"];
  217. // vc.mode = mode;
  218. //
  219. // [self presentViewController:vc animated:YES completion:nil];
  220. // }
  221. // return;
  222. // }
  223. HomeModeUpdateViewController *vc = (HomeModeUpdateViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeModeUpdateViewController" storyboardName:@"Main"];
  224. vc.mode = mode;
  225. [self presentViewController:vc animated:YES completion:nil];
  226. }
  227. - (void)didReceiveMemoryWarning {
  228. [super didReceiveMemoryWarning];
  229. }
  230. @end