ThingsAddStartViewController.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // ThingsAddStartViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/13/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "ThingsAddIncludeViewController.h"
  12. #import "ThingsAddStartViewController.h"
  13. #import "DeviceModel.h"
  14. @interface ThingsAddStartViewController () {
  15. }
  16. @end
  17. #pragma mark - Class Definition
  18. @implementation ThingsAddStartViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self initUI];
  23. [self prepareViewDidLoad];
  24. }
  25. - (void)initUI {
  26. if (_addableDevice) {
  27. [_btnDoStart setTitle:@"추가 시작" forState:UIControlStateNormal];
  28. _lblComment.text = @"장치 근처로 이동 후\n추가시작 버튼을 누르세요";
  29. } else if (_removableDevice) {
  30. [_btnDoStart setTitle:@"삭제 시작" forState:UIControlStateNormal];
  31. _lblComment.text = @"장치 근처로 이동 후\n삭제시작 버튼을 누르세요";
  32. }
  33. }
  34. - (void)viewDidAppear:(BOOL)animated {
  35. [super viewDidAppear:animated];
  36. [UIView animateWithDuration:kfAnimationDur animations:^{
  37. _maskView.alpha = 0.7;
  38. } completion:^(BOOL finished) {
  39. _constraintPopViewTop.constant = (IPHONE_HEIGHT - _popView.height) / 2;
  40. [UIView animateWithDuration:kfAnimationDur animations:^{
  41. [self.view layoutIfNeeded];
  42. }];
  43. }];
  44. }
  45. - (void)prepareViewDidLoad {
  46. if (_addableDevice) {//inclusion
  47. _lblSensorName.text = _addableDevice[@"nodeName"];
  48. _lblManufacturer.text = _addableDevice[@"manufacturer"];
  49. } else if (_removableDevice) {//exclusion
  50. _lblSensorName.text = _removableDevice.deviceName;
  51. if (_removableGroups) {
  52. NSMutableString *groups = [[NSMutableString alloc] init];
  53. for (DeviceModel *device in _removableGroups) {
  54. NSString *prefix = [groups isEmptyString] ? ksEmptyString : @",";
  55. [groups appendFormat:@"%@%@", prefix, device.deviceName];
  56. }
  57. _lblManufacturer.text = [NSString stringWithFormat:@"이 장치를 삭제하면 %@도 함께 삭제됩니다", groups];
  58. _lblManufacturer.backgroundColor = kUITextColor02;
  59. }
  60. }
  61. }
  62. #pragma mark - Main Logic
  63. #pragma mark - UI Events
  64. - (void)btnAddTouched:(id)sender {
  65. if ([[JDFacade facade].loginUser.homehubOnlineState isEqualToString:@"OFF"]) {
  66. [[JDFacade facade] toast:@"홈허브가 온라인 상태로\r연결되어 있을 때 시도해주세요"];
  67. return;
  68. }
  69. ThingsAddIncludeViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddIncludeViewController" storyboardName:@"Things"];
  70. vc.addableDevice = _addableDevice;
  71. vc.removableDevice = _removableDevice;
  72. vc.providesPresentationContextTransitionStyle = YES;
  73. vc.definesPresentationContext = YES;
  74. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  75. [self presentViewController:vc animated:nil completion:nil];
  76. }
  77. - (void)btnCancelTouched:(id)sender {
  78. [UIView animateWithDuration:kfAnimationDur animations:^{
  79. _maskView.alpha = 0.0;
  80. } completion:^(BOOL finished) {
  81. [self dismissViewControllerAnimated:YES completion:nil];
  82. }];
  83. }
  84. #pragma mark - MemoryWarning
  85. - (void)didReceiveMemoryWarning
  86. {
  87. [super didReceiveMemoryWarning];
  88. // Dispose of any resources that can be recreated.
  89. }
  90. @end