HomeModeUpdateViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // HomeModeUpdateViewController.m
  3. //
  4. //
  5. // Created by Jason Lee on 10/30/15.
  6. //
  7. //
  8. #import "JDObject.h"
  9. #import "CustomButton.h"
  10. #import "CustomLabel.h"
  11. #import "CustomImageView.h"
  12. #import "RequestHandler.h"
  13. #import "JDJSONModel.h"
  14. #import "HomeModeUpdateViewController.h"
  15. #import "ModeModel.h"
  16. #import "DeviceSelectPopupView.h"
  17. #import "HomeModeSettingsViewController.h"
  18. @interface HomeModeUpdateViewController () {
  19. }
  20. @end
  21. #pragma mark - Class Definition
  22. @implementation HomeModeUpdateViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self initUI];
  27. [self prepareViewDidLoad];
  28. }
  29. - (void)initUI {
  30. NSString *message = nil, *highlightMessage = nil;
  31. NSString *btnTitle = nil;
  32. if ([_mode.basicModeCode isEqualToString:HOME_MODE_HOME]) {
  33. btnTitle = @"귀가";
  34. highlightMessage = @"잘 돌아왔어요!";
  35. message = @"쾌적한 귀가모드를 \r실행할까요?";
  36. } else if ([_mode.basicModeCode isEqualToString:HOME_MODE_AWAY]) {
  37. btnTitle = @"외출";
  38. highlightMessage = @"안녕히 다녀오세요!";
  39. message = @"안전한 외출모드를 \r실행할까요?";
  40. } else if ([_mode.basicModeCode isEqualToString:HOME_MODE_MORNING]) {
  41. btnTitle = @"기상";
  42. highlightMessage = @"좋은 아침!";
  43. message = @"상쾌한 기상모드를\r실행할까요?";
  44. } else if ([_mode.basicModeCode isEqualToString:HOME_MODE_NIGHT]) {
  45. btnTitle = @"취침";
  46. highlightMessage = @"잘 자요!";
  47. message = @"편안한 취침모드를 \r실행할까요?";
  48. }
  49. [_btnExecute setTitle:btnTitle forState:UIControlStateNormal];
  50. _lblMessage.text = [NSString stringWithFormat:@"%@\n\n%@", highlightMessage, message];
  51. [_lblMessage setColor:kUITextColor02 text:highlightMessage];
  52. _btnSetting.hidden = [JDFacade facade].loginUser.level < 90;
  53. //TODO : set icon;
  54. }
  55. - (void)prepareViewDidLoad {
  56. }
  57. #pragma mark - Main Logic
  58. - (void)requestChangeHomeMode {
  59. NSString *modeTitle = [NSString stringWithFormat:@"%@ 모드", _mode.modeName];
  60. _lblMessage.text = [NSString stringWithFormat:@"%@\r\r실행 중입니다.", modeTitle];
  61. [_lblMessage setColor:kUITextColor02 text:modeTitle];
  62. NSString *path = [NSString stringWithFormat:API_POST_DASHBOARD_MODE_CHANGE, _mode.modeId];
  63. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:nil modelClass:[JDJSONModel class] completion:^(id responseObject) {
  64. if ([[JDFacade facade].currentViewController isEqual:self]) {
  65. [self setContentsForComplete];
  66. }
  67. [[JDFacade facade] toast:[NSString stringWithFormat:@"%@ 상태가 되었습니다", _mode.modeName]];
  68. } failure:^(id errorObject) {
  69. JDErrorModel *error = (JDErrorModel *)errorObject;
  70. [[JDFacade facade] alert:error.errorMessage];
  71. }];
  72. }
  73. - (void)setContentsForComplete {
  74. NSString *highlightMessage = nil;
  75. highlightMessage = [NSString stringWithFormat:@"%@ 상태가 되었습니다.", _mode.modeName];
  76. //TODO : chagne button image
  77. }
  78. #pragma mark - UI Events
  79. - (IBAction)btnExecuteTouched:(id)sender {
  80. [self requestChangeHomeMode];
  81. }
  82. - (IBAction)btnSettingTouched:(id)sender {
  83. HomeModeSettingsViewController *vc = (HomeModeSettingsViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeModeSettingsViewController" storyboardName:@"Main"];
  84. vc.mode = _mode;
  85. [self presentViewController:vc animated:YES completion:nil];
  86. }
  87. - (IBAction)btnCloseTouched:(id)sender {
  88. [self dismissViewControllerAnimated:YES completion:nil];
  89. }
  90. #pragma mark - MemoryWarning
  91. - (void)didReceiveMemoryWarning
  92. {
  93. [super didReceiveMemoryWarning];
  94. // Dispose of any resources that can be recreated.
  95. }
  96. @end