Browse Source

- 버튼 액션 연결

KaRam Kim 8 years ago
parent
commit
8bbd577754

+ 14 - 5
OneCable/Base.lproj/Things.storyboard

@@ -142,6 +142,9 @@
                                                             <color key="titleColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                                         </state>
                                                         <state key="highlighted" backgroundImage="common_head_btn_close_press"/>
+                                                        <connections>
+                                                            <action selector="btnCloseTouched:" destination="G75-Hx-lyG" eventType="touchUpInside" id="zjW-yc-9Lk"/>
+                                                        </connections>
                                                     </button>
                                                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wjr-YQ-CK1" customClass="CustomButton">
                                                         <rect key="frame" x="50" y="0.0" width="50" height="50"/>
@@ -152,6 +155,9 @@
                                                             <color key="titleColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                                         </state>
                                                         <state key="highlighted" backgroundImage="common_head_btn_save_press"/>
+                                                        <connections>
+                                                            <action selector="btnConfirmTouched:" destination="G75-Hx-lyG" eventType="touchUpInside" id="AkV-Ne-yVZ"/>
+                                                        </connections>
                                                     </button>
                                                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RRy-5K-Lvr" customClass="CustomButton">
                                                         <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
@@ -162,6 +168,9 @@
                                                             <color key="titleColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                                         </state>
                                                         <state key="highlighted" backgroundImage="common_head_btn_refresh_press"/>
+                                                        <connections>
+                                                            <action selector="btnReFreshTouched:" destination="G75-Hx-lyG" eventType="touchUpInside" id="bI6-On-y6v"/>
+                                                        </connections>
                                                     </button>
                                                 </subviews>
                                                 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@@ -1046,7 +1055,7 @@
                                                 <rect key="frame" x="0.0" y="28" width="320" height="365"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="8am-9B-OVU" id="3z1-RY-sUu">
-                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="364"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="365"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Q6u-Ql-uvI">
@@ -1291,7 +1300,7 @@
                                                 <rect key="frame" x="0.0" y="393" width="320" height="375"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="h1h-oK-SGQ" id="PcJ-j1-AEV">
-                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="374"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="375"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <subviews>
                                                         <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="bu5-Tt-H5r">
@@ -1397,7 +1406,7 @@
                                                 <rect key="frame" x="0.0" y="768" width="320" height="63"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="4Vp-TW-mCg" id="Gxj-Z0-xe2">
-                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="62"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="62.5"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="SpF-Bb-9qN" userLabel="View - container">
@@ -1507,7 +1516,7 @@
                                                 <rect key="frame" x="0.0" y="831" width="320" height="31"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="O2N-bm-Hvc" id="k2Z-gW-HLc">
-                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="30"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="30.5"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="k8h-3L-ehd">
@@ -1774,7 +1783,7 @@
                                                 <rect key="frame" x="0.0" y="28" width="320" height="154"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="eAC-dN-TM9" id="wmw-7q-Ee8">
-                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="153.5"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="320" height="154"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="afL-97-7bS">

+ 64 - 19
OneCable/Classes/ViewControllers/ThingsScreens/ThingsViewController.m

@@ -93,6 +93,7 @@
 
 @interface ThingsViewController () <UICollectionViewDataSource, UICollectionViewDelegate> {
     NSMutableArray<DeviceModel> *_deviceList;
+    NSMutableArray<DeviceModel> *_deviceReOrderList;
     NSString *_pagingId, *_pagingType;
     BOOL _isNotFirstLoading, _isReOrderMode, _isDeleteMode;
     
@@ -142,6 +143,8 @@
     _collectionView.backgroundColor = [UIColor clearColor];
     _collectionView.alwaysBounceVertical = YES;
     
+    _lblEditMode.hidden = YES;
+    
     [self viewOfflineSetHidden:YES];
     
     [_btnClose setHidden:YES];
@@ -412,7 +415,7 @@
         NodeListModel *deviceList = (NodeListModel *)responseObject;
 
         if (deviceList && deviceList.nodes && deviceList.nodes.count) {
-            _deviceList = deviceList.nodes;
+            _deviceReOrderList = _deviceList = deviceList.nodes;
             [self updateTitle];
         } else {
             if (!_deviceList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
@@ -592,11 +595,14 @@
         cell.btnDelete.hidden = !_isDeleteMode;
         cell.btnChangeOrder.hidden = !_isReOrderMode;
         
+        if(_isDeleteMode || _isReOrderMode)
+        {
+            cell.btnDevice.enabled = NO;
+            cell.btnDeviceControl.hidden = YES;
+        }
+        
         [cell.btnChangeOrder addGestureRecognizer:drag];
-//        [cell.btnChangeOrder setTag:indexPath.row];
         cell.btnChangeOrder.value = indexPath;
-        [cell.btnChangeOrder addTarget:self action:@selector(btnChangeOrderTouched:) forControlEvents:UIControlEventTouchUpInside];
-        [cell.btnChangeOrder addTarget:self action:@selector(btnChangeOrderTouchDown:) forControlEvents:UIControlEventTouchDown];
         
         
         if (!cell.controlContainer.hidden) {//커맨드 클래스 타입별 컨트롤 호출
@@ -821,7 +827,15 @@
 -(void)updateDataSource:(NSIndexPath *)atIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
     NSLog(@"Update Data");
+    NSLog(@"From Index : %li", (long)atIndexPath.item);
+    NSLog(@"To Index : %li", (long)toIndexPath.item);
     
+//    DeviceModel *device =_deviceList[atIndexPath.item];
+    
+//    [_deviceList removeObject:device];
+//    [_deviceList insertObject:device atIndex:toIndexPath.item];
+//    
+//    [_collectionView reloadData];
 //    UIImage *image = [_photosArray objectAtIndex:fromIndexPath.item];
 //    [_photosArray removeObjectAtIndex:fromIndexPath.item];
 //    [_photosArray insertObject:image atIndex:toIndexPath.item];
@@ -848,6 +862,49 @@
    [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
 }
 
+- (IBAction)btnReFreshTouched:(id)sender {
+    [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록의 순서를\n장치가 등록된 순으로 초괴화합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
+        if (buttonIndex == 0) {
+            // TODO : 서버에서 장치 목록 순서 다시 가져오기
+            [self enterReOrderMode:NO];
+        }
+    }];
+}
+
+- (IBAction)btnConfirmTouched:(id)sender {
+    [[JDFacade facade] confirmTitle:@"알림" message:@"현재 편집된 장치 목록 순서를\n저장하시겠습니까?" btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
+        if (buttonIndex == 0) {
+            // TODO : 데이터 업데이트 하기
+            [self enterReOrderMode:NO];
+        }
+    }];
+    
+//    _deviceList = _deviceReOrderList;
+//    [self enterReOrderMode:NO];
+}
+
+- (IBAction)btnCloseTouched:(id)sender {
+    [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록 순서를 저장하지 않고\n이전화면으로 이동합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
+        if (buttonIndex == 0) {
+            [self enterReOrderMode:NO];
+        }
+    }];
+//    [self enterReOrderMode:NO];
+}
+
+-(void)enterReOrderMode:(Boolean)isReOrder
+{
+    _isReOrderMode = isReOrder;
+    _viewEditMode.hidden = !isReOrder;
+    _btnOption.hidden = isReOrder;
+    [_collectionView reloadData];
+    
+    _viewTitle.hidden = isReOrder;
+    _lblEditMode.hidden = !isReOrder;
+    
+    _lblEditMode.text = @"장치 목록 순서 편집";
+}
+
 #pragma mark - SocketService
 - (void) socketDidReceiveMessage:(id)message info:(NSDictionary *)info
 {
@@ -889,10 +946,7 @@
     switch (tag) {
         case ReOrder:
         {
-            // TODO : 순서 변경 모드로 진입
-            _isReOrderMode = YES;
-            [_collectionView reloadData];
-            _viewEditMode.hidden = NO;
+            [self enterReOrderMode:YES];
         }
             break;
         case Add:
@@ -935,19 +989,10 @@
     // Dispose of any resources that can be recreated.
 }
 
-- (void)btnDeviceTouched:(id)sender {
-    CustomButton *btn = (CustomButton *)sender;
-    
-//    [_collectionView selectItemAtIndexPath:btn.value animated:YES scrollPosition:UICollectionViewScrollPositionNone];
-    [self collectionView:_collectionView didSelectItemAtIndexPath:btn.value];
-}
-
 
+-(void)btnDeviceTouched:(id)sender
+{
 
--(void)btnChangeOrderTouchDown:(id)sender {
-    CustomButton *info = (CustomButton *)sender;
-    NSLog(@"%@", info.value);
-    _dragIndexPath = info.value;
 }
 
 @end