ThingsAddWallpadSubViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // ThingsAddWallpadSubViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 6/30/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "RequestHandler.h"
  9. #import "JDObject.h"
  10. #import "SelectButton.h"
  11. #import "DeviceModel.h"
  12. #import "ThingsAddWallpadSubViewController.h"
  13. #import "CustomLabel.h"
  14. #import "CustomButton.h"
  15. #import "WallpadSubDevicePopupView.h"
  16. #import "ThingsAddWallPadSubTypeViewController.h"
  17. @interface ThingsAddWallpadSubViewController () {
  18. UIImage *_bgCellImage1, *_bgCellImage2;
  19. }
  20. @end
  21. #pragma mark - Class Definition
  22. @implementation ThingsAddWallpadSubViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self initUI];
  27. [self prepareViewDidLoad];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. self.title = NSLocalizedString(@"새 장치 추가",nil);
  32. }
  33. - (void)initUI {
  34. //set tableview option
  35. self.tableView.delegate = self;
  36. self.tableView.dataSource = self;
  37. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  38. self.tableView.backgroundColor = [UIColor clearColor];
  39. self.tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  40. UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
  41. _bgCellImage1 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
  42. _bgCellImage2 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_01"]];
  43. //Localization
  44. _lblTitle.text = NSLocalizedString(@"현재 등록된 COMMAX 월패드에\n더 많은 장치를 연결해보세요", @"현재 등록된 COMMAX 월패드에\n더 많은 장치를 연결해보세요");
  45. [_btnAddSubDevice setTitle:NSLocalizedString(@"장치추가", @"장치추가") forState:UIControlStateNormal];
  46. _lblManualDesc.text = NSLocalizedString(@"장치 종류별 연결방법은\n매뉴얼을 참고해주세요", @"장치 종류별 연결방법은\n매뉴얼을 참고해주세요");
  47. [_btnManual setTitle:NSLocalizedString(@"매뉴얼 보기", @"매뉴얼 보기") forState:UIControlStateNormal];
  48. }
  49. - (void)prepareViewDidLoad {
  50. _btnWallpads.dataDict = [[SortDictionary alloc] initWithDictionary:_wallpads];
  51. _btnWallpads.selectedValue = [_wallpads allKeys].firstObject;
  52. }
  53. #pragma mark - Main Logic
  54. #pragma mark - UITableView DataSource & Delegate
  55. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  56. return 1;
  57. }
  58. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  59. return 3;
  60. }
  61. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  62. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  63. return cell;
  64. }
  65. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  66. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  67. if (indexPath.row == 1) {
  68. [self btnAddSubDeviceTouched:nil];
  69. }
  70. }
  71. #pragma mark - UI Events
  72. - (IBAction)btnAddSubDeviceTouched:(id)sender {
  73. WallpadSubDevicePopupView *popup = [[WallpadSubDevicePopupView alloc] initFromNib];
  74. popup.wallpadId = _btnWallpads.selectedValue;
  75. [popup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  76. if (popup.foundedDevice) {
  77. if (![popup.foundedDevice.deviceProfileId isEqualToString:ksDeviceProfileIdUnknown]) {//장치 타입이 있을 경우,
  78. //goto complete
  79. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddCompleteViewController" storyboardName:@"Things"];
  80. [[JDFacade facade] presentViewControllerByPush:vc pvc:self];
  81. } else {//UNJDOWN 타입일 경우,
  82. //goto choose device type
  83. ThingsAddWallPadSubTypeViewController *wvc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddWallPadSubTypeViewController" storyboardName:@"Things"];
  84. wvc.device = popup.foundedDevice;
  85. [[JDFacade facade] presentViewControllerByPush:wvc pvc:self];
  86. }
  87. }
  88. }];
  89. }
  90. - (IBAction)btnManualTouched:(id)sender {
  91. }
  92. #pragma mark - MemoryWarning
  93. - (void)didReceiveMemoryWarning
  94. {
  95. [super didReceiveMemoryWarning];
  96. // Dispose of any resources that can be recreated.
  97. }
  98. @end