ManagementViewController.m 12 KB

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