Browse Source

- 장치 추가후 이름변경 적용

TaeHyun 8 years ago
parent
commit
3d3dbf4e39

+ 0 - 4
OneCable/Classes/ViewControllers/ThingsScreens/ChangeDeviceNamePopupView.m

@@ -36,9 +36,6 @@
             self.frame = [UIScreen mainScreen].bounds;
             self.lblTitle.text = NSLocalizedString(@"이름 변경", @"이름 변경");
 
-            NSLog(@"deviceDetailModel.prdName : %@",deviceDetailModel.prdName);
-            NSLog(@"deviceDetailModel.prdUserName : %@",deviceDetailModel.prdUserName);
-            
             NSString * prdName = [deviceDetailModel.prdName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
             NSString * prdUserName = [deviceDetailModel.prdUserName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
             
@@ -92,7 +89,6 @@
     NSDictionary *parameter = @{@"device_id": deviceDetailModel.deviceId,
                                 @"node_id" : deviceDetailModel.nodeId,
                                 @"prd_user_name" : [_txtInputDeviceName.text isEqualToString:@""] ? deviceDetailModel.prdName : _txtInputDeviceName.text};
-    NSLog(@"1111deviceDetailModel.prdName  : %@",deviceDetailModel.prdName);
     
     NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DEVICE_LIST arguments:nil];
     

+ 1 - 0
OneCable/Classes/ViewControllers/ThingsScreens/ThingsAddCompleteViewController.h

@@ -12,6 +12,7 @@
 
 
 #pragma mark - Properties
+@property (strong , nonatomic) DeviceDetailModel *deviceDetailModel;
 @property (assign, nonatomic) BOOL isDeleteMode;
 
 @property (weak, nonatomic) IBOutlet UIView *maskView;

+ 11 - 4
OneCable/Classes/ViewControllers/ThingsScreens/ThingsAddCompleteViewController.m

@@ -7,7 +7,7 @@
 //
 
 #import "ThingsAddCompleteViewController.h"
-
+#import "ChangeDeviceNamePopupView.h"
 
 @interface ThingsAddCompleteViewController () {
 
@@ -18,7 +18,7 @@
 #pragma mark - Class Definition
 
 @implementation ThingsAddCompleteViewController
-
+@synthesize deviceDetailModel;
 
 - (void)viewDidLoad {
     [super viewDidLoad];
@@ -38,7 +38,6 @@
 
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-    
     [UIView animateWithDuration:kfAnimationDur animations:^{
         _maskView.alpha = 0.7;
     } completion:^(BOOL finished) {
@@ -71,7 +70,15 @@
 
 // 이름 변경
 - (IBAction)btnChangeTouched:(id)sender {
-    
+
+    ChangeDeviceNamePopupView *popup = [[ChangeDeviceNamePopupView alloc]initFromNib:deviceDetailModel];
+    popup.deviceDetailModel = deviceDetailModel;
+    [popup show];
+}
+
+-(void)receiveSocketData:(NSNotification *)notification
+{
+    deviceDetailModel = [[DeviceDetailModel alloc] initWithDictionary:notification.object error:nil];
 }
 
 #pragma mark - MemoryWarning

+ 52 - 52
OneCable/Classes/ViewControllers/ThingsScreens/ThingsDetailViewController.m

@@ -84,7 +84,7 @@
 @interface ThingsDetailViewController () <UITableViewDataSource, UITableViewDelegate ,changeDeviceNameDelegate> {
     
     DeviceDetailModel *_deviceDetail;
-    ModifyDeviceNamePopupView *_mpopup;
+//    ModifyDeviceNamePopupView *_mpopup;
     NSArray<NodeModel> *_mandatoryNodes, *_optionalNodes;
     UIPageControl *_pageControl;
     
@@ -114,7 +114,7 @@
     [self initTableViewAsDefaultStyle:_tableView];
     _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)];
     
-    [self setThingsDetailPopoverOptions];
+//    [self setThingsDetailPopoverOptions];
     
     [self initRefreshController];
     [self setMoreBtnArray];
@@ -130,41 +130,41 @@
 }
 
 
-- (void)setThingsDetailPopoverOptions {
-    //set Popover Contents
-    __weak typeof(self) weakSelf = self;
-    _popooverOptionArray = [[NSMutableArray alloc] init];
-
-    [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
-                                      @"iconName": @"img_bg_morepopup_icon_refresh",
-                                      @"target": weakSelf,
-                                      @"selector": [NSValue valueWithPointer:@selector(requestDeviceDetail:)]}];
-    
-    if ([JDFacade facade].loginUser.level > 10) {
-        [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"이름 변경", @"이름 변경"),
-                                          @"iconName": @"img_bg_morepopup_icon_edit",
-                                          @"target": weakSelf,
-                                          @"selector": [NSValue valueWithPointer:@selector(modifyDeviceName)]}];
-
-    }
-}
+//- (void)setThingsDetailPopoverOptions {
+//    //set Popover Contents
+//    __weak typeof(self) weakSelf = self;
+//    _popooverOptionArray = [[NSMutableArray alloc] init];
+//
+//    [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
+//                                      @"iconName": @"img_bg_morepopup_icon_refresh",
+//                                      @"target": weakSelf,
+//                                      @"selector": [NSValue valueWithPointer:@selector(requestDeviceDetail:)]}];
+//    
+//    if ([JDFacade facade].loginUser.level > 10) {
+//        [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"이름 변경", @"이름 변경"),
+//                                          @"iconName": @"img_bg_morepopup_icon_edit",
+//                                          @"target": weakSelf,
+//                                          @"selector": [NSValue valueWithPointer:@selector(modifyDeviceName)]}];
+//
+//    }
+//}
 
 - (void)prepareViewDidLoad {
     
     [self requestDeviceDetail:@YES];
 }
 
-- (void)modifyDeviceName {
-    
-    _mpopup = [[ModifyDeviceNamePopupView alloc] initFromNib];
-    _mpopup.txtDeviceName.text = _deviceDetail.deviceName;
-    
-    [_mpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
-        if (buttonIndex == 0) {//OK
-            [self requestDeviceUpdate];
-        }
-    }];
-}
+//- (void)modifyDeviceName {
+//    
+//    _mpopup = [[ModifyDeviceNamePopupView alloc] initFromNib];
+//    _mpopup.txtDeviceName.text = _deviceDetail.deviceName;
+//    
+//    [_mpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
+//        if (buttonIndex == 0) {//OK
+//            [self requestDeviceUpdate];
+//        }
+//    }];
+//}
 
 - (void)changeDeviceName:(NSString *)deviceName {
     [self requestDeviceDetail:@YES];
@@ -179,7 +179,7 @@
     } else {
         _lblTitle.text = _deviceDetail.prdUserName;
     }
-//    _lblTitle.text = ![_deviceDetail.prdName isEqualToString:_deviceDetail.prdUserName] ? _deviceDetail.prdName : _deviceDetail.prdUserName;
+
     
     if (![JDFacade facade].loginUser.isHomehubOnline) {
         _lblTitle.text = @"홈허브 오프라인";
@@ -257,26 +257,26 @@
     [_tableView reloadData];
 }
 
-- (void)requestDeviceUpdate {
-    //parameters
-    NSDictionary *parameter = @{@"device_name": _mpopup.txtDeviceName.text};
-
-    NSString *path = [NSString stringWithFormat:API_GET_DEVICE_UPDATE, _deviceDetail.deviceId];
-
-    [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
-
-        _refDevice.deviceName = _deviceDetail.deviceName = _mpopup.txtDeviceName.text;
-        [_tableView reloadData];
-
-        //리스트를 다시 로드함.
-        ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
-        [vc.collectionView reloadData];
-
-    } failure:^(id errorObject) {
-        JDErrorModel *error = (JDErrorModel *)errorObject;
-        [[JDFacade facade] alert:error.errorMessage];
-    }];
-}
+//- (void)requestDeviceUpdate {
+//    //parameters
+//    NSDictionary *parameter = @{@"device_name": _mpopup.txtDeviceName.text};
+//
+//    NSString *path = [NSString stringWithFormat:API_GET_DEVICE_UPDATE, _deviceDetail.deviceId];
+//
+//    [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
+//
+//        _refDevice.deviceName = _deviceDetail.deviceName = _mpopup.txtDeviceName.text;
+//        [_tableView reloadData];
+//
+//        //리스트를 다시 로드함.
+//        ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
+//        [vc.collectionView reloadData];
+//
+//    } failure:^(id errorObject) {
+//        JDErrorModel *error = (JDErrorModel *)errorObject;
+//        [[JDFacade facade] alert:error.errorMessage];
+//    }];
+//}
 
 - (void)requestDeleteDevice {
     //parameters

+ 7 - 2
OneCable/Classes/ViewControllers/ThingsScreens/ThingsViewController.m

@@ -20,6 +20,7 @@
 #import "JYRefreshController.h"
 #import "WYPopoverController.h"
 #import "ImageUtil.h"
+#import "ThingsAddCompleteViewController.h"
 
 #import "UIImageView+WebCache.h"
 #import "UIButton+WebCache.h"
@@ -652,8 +653,12 @@
         DeviceModel *device =_deviceList[indexPath.row];
         cell.indexPath = indexPath;
         
-        cell.lblDeviceName.text = device.prdName;
-        
+        if([device.prdName isEqualToString:device.prdUserName] || [device.prdUserName isEqualToString:@""]) {
+            cell.lblDeviceName.text = device.prdName;
+        } else {
+            cell.lblDeviceName.text = device.prdUserName;
+        }
+            
 //        [cell.btnDevice sd_setImageWithURL:[NSURL URLWithString:device.imageFileName] forState:UIControlStateNormal
 //                          placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
 //            [cell layoutIfNeeded];