ManagementViewController.m 12 KB

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