|
|
@@ -94,17 +94,21 @@
|
|
|
@interface ThingsViewController () <UICollectionViewDataSource, UICollectionViewDelegate> {
|
|
|
NSMutableArray<DeviceModel> *_deviceList;
|
|
|
NSString *_pagingId, *_pagingType;
|
|
|
- BOOL _isNotFirstLoading;
|
|
|
+ BOOL _isNotFirstLoading, _isReOrderMode, _isDeleteMode;
|
|
|
|
|
|
NSMutableArray<DeviceModel> *_commandArray;
|
|
|
NSTimer *_devicesBackgroundTimer;
|
|
|
NSTimer *_deviceCommandsBackgroundTimer;
|
|
|
|
|
|
NSInteger _deviceFlag;
|
|
|
+ UIPanGestureRecognizer *_moveCellGesture;
|
|
|
|
|
|
+ NSIndexPath *_dragIndexPath;
|
|
|
+ ThingsCollectionViewCell *_moveCell;
|
|
|
}
|
|
|
|
|
|
@property (strong, nonatomic) JYPullToRefreshController *refreshController;
|
|
|
+@property (nonatomic, strong) UIView *cellFakeView;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@@ -144,8 +148,8 @@
|
|
|
[_btnOption setHidden:NO];
|
|
|
[_viewEditMode setHidden:YES];
|
|
|
|
|
|
- [self setThingsPopoverOptions];
|
|
|
-
|
|
|
+// [self setThingsPopoverOptions];
|
|
|
+ [self setMoreBtnArray];
|
|
|
[self initRefreshController];
|
|
|
}
|
|
|
|
|
|
@@ -165,27 +169,68 @@
|
|
|
|
|
|
|
|
|
- (void)setThingsPopoverOptions {
|
|
|
+//
|
|
|
+// //set Popover Contents
|
|
|
+// __weak typeof(self) weakSelf = self;
|
|
|
+// _popooverOptionArray = [[NSMutableArray alloc] init];
|
|
|
+//
|
|
|
+// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침", @"새로고침"),
|
|
|
+// @"iconName": @"img_bg_morepopup_icon_refresh",
|
|
|
+// @"target": weakSelf,
|
|
|
+// @"selector": [NSValue valueWithPointer:@selector(refreshDeviceList)]}];
|
|
|
+//
|
|
|
+//// if ([JDFacade facade].loginUser.level == 90) {//권한
|
|
|
+//// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"추가", @"추가"),
|
|
|
+//// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
|
|
|
+//// @"target": weakSelf,
|
|
|
+//// @"selector": [NSValue valueWithPointer:@selector(addNewDevice)]}];
|
|
|
+////
|
|
|
+//// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
|
|
|
+//// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
|
|
|
+//// @"target": weakSelf,
|
|
|
+//// @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
|
|
|
+//// }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setMoreBtnArray {
|
|
|
+ _moreBtnArray = [NSMutableArray array];
|
|
|
+
|
|
|
+ if (![[JDFacade facade].loginUser hasHomeHub]) {
|
|
|
+ [_btnOption setHidden:YES];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if([[JDFacade facade].loginUser.gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ MoreBtnModel *btnModel;
|
|
|
+ switch (i) {
|
|
|
+ case 0:{
|
|
|
+ btnModel = [[MoreBtnModel alloc] initWithTyep:ReOrder isEnable:YES];
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ btnModel = [[MoreBtnModel alloc] initWithTyep:Add isEnable:YES];
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ btnModel = [[MoreBtnModel alloc] initWithTyep:Del isEnable:YES];
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ [_moreBtnArray addObject:btnModel];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ MoreBtnModel *btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
|
|
|
+ [_moreBtnArray addObject:btnModel];
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- //set Popover Contents
|
|
|
- __weak typeof(self) weakSelf = self;
|
|
|
- _popooverOptionArray = [[NSMutableArray alloc] init];
|
|
|
-
|
|
|
- [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침", @"새로고침"),
|
|
|
- @"iconName": @"img_bg_morepopup_icon_refresh",
|
|
|
- @"target": weakSelf,
|
|
|
- @"selector": [NSValue valueWithPointer:@selector(refreshDeviceList)]}];
|
|
|
-
|
|
|
-// if ([JDFacade facade].loginUser.level == 90) {//권한
|
|
|
-// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"추가", @"추가"),
|
|
|
-// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
|
|
|
-// @"target": weakSelf,
|
|
|
-// @"selector": [NSValue valueWithPointer:@selector(addNewDevice)]}];
|
|
|
-//
|
|
|
-// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
|
|
|
-// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
|
|
|
-// @"target": weakSelf,
|
|
|
-// @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -232,14 +277,14 @@
|
|
|
NSString *path = [NSString stringWithFormat:API_GET_DEVICE_NODE_STATUS, pathParams];
|
|
|
|
|
|
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
|
|
|
- DeviceListModel *fdevices = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil
|
|
|
- modelClass:[DeviceListModel class] showLoadingView:YES];
|
|
|
+ NodeListModel *fdevices = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil
|
|
|
+ modelClass:[NodeListModel class] showLoadingView:YES];
|
|
|
|
|
|
- if (fdevices && fdevices.list && fdevices.list.count) {
|
|
|
+ if (fdevices && fdevices.nodes && fdevices.nodes.count) {
|
|
|
|
|
|
[_commandArray enumerateObjectsUsingBlock:^(DeviceModel *rdevice, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
|
|
- DeviceModel *matchedDevice = (DeviceModel *)[fdevices.list objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId];
|
|
|
+ DeviceModel *matchedDevice = (DeviceModel *)[fdevices.nodes objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId];
|
|
|
|
|
|
//실행 여부 및 10초 경과 확인
|
|
|
BOOL isOverTimeLimit = [self elapsedSecondsFromNow:rdevice] > 10;
|
|
|
@@ -359,15 +404,15 @@
|
|
|
NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DEVICE_LIST aditional:@""];
|
|
|
|
|
|
[[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestGET parameters:parameter
|
|
|
- modelClass:[DeviceListModel class] showLoadingView:showLoadingView completion:^(id responseObject) {
|
|
|
+ modelClass:[NodeListModel class] showLoadingView:showLoadingView completion:^(id responseObject) {
|
|
|
if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- DeviceListModel *deviceList = (DeviceListModel *)responseObject;
|
|
|
+ NodeListModel *deviceList = (NodeListModel *)responseObject;
|
|
|
|
|
|
- if (deviceList && deviceList.list && deviceList.list.count) {
|
|
|
- _deviceList = deviceList.list;
|
|
|
+ if (deviceList && deviceList.nodes && deviceList.nodes.count) {
|
|
|
+ _deviceList = deviceList.nodes;
|
|
|
[self updateTitle];
|
|
|
} else {
|
|
|
if (!_deviceList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
|
|
|
@@ -382,9 +427,9 @@
|
|
|
// [self requestPollingDevicesStatusInBackground];
|
|
|
|
|
|
//refresh controller
|
|
|
-// if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
|
|
|
-// [self.refreshController stopRefreshWithAnimated:YES completion:nil];
|
|
|
-// }
|
|
|
+ if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
|
|
|
+ [self.refreshController stopRefreshWithAnimated:YES completion:nil];
|
|
|
+ }
|
|
|
|
|
|
} failure:^(id errorObject) {
|
|
|
// [self releaseDevicesTimer];
|
|
|
@@ -506,16 +551,16 @@
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
UICollectionViewCell *rcell = nil;
|
|
|
-
|
|
|
+ UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
|
|
|
if (indexPath.row < _deviceList.count) {
|
|
|
ThingsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsCellIdentifier" forIndexPath:indexPath];
|
|
|
- [cell.btnDelete setHidden:YES];
|
|
|
- [cell.btnChangeOrder setHidden:YES];
|
|
|
+// [cell.btnDelete setHidden:YES];
|
|
|
+// [cell.btnChangeOrder setHidden:YES];
|
|
|
|
|
|
DeviceModel *device =_deviceList[indexPath.row];
|
|
|
cell.indexPath = indexPath;
|
|
|
|
|
|
- cell.lblDeviceName.text = device.deviceName;
|
|
|
+ cell.lblDeviceName.text = device.prdName;
|
|
|
|
|
|
[cell.btnDevice sd_setImageWithURL:[NSURL URLWithString:device.imageFileName] forState:UIControlStateNormal
|
|
|
placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
|
@@ -543,7 +588,17 @@
|
|
|
//허브 On-Off line check
|
|
|
cell.lblDeviceStatus.hidden = !([[JDFacade facade].loginUser.homehubOnlineState isEqualToString:@"OFF"] || [device.onlineState isEqualToString:@"OFF"]);
|
|
|
cell.controlContainer.hidden = !cell.lblDeviceStatus.hidden;
|
|
|
-
|
|
|
+
|
|
|
+ cell.btnDelete.hidden = !_isDeleteMode;
|
|
|
+ cell.btnChangeOrder.hidden = !_isReOrderMode;
|
|
|
+
|
|
|
+ [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) {//커맨드 클래스 타입별 컨트롤 호출
|
|
|
|
|
|
[cell.btnDevice setBackgroundImage:[device backgroundImageForMandatary:device.contentValue] forState:UIControlStateNormal];
|
|
|
@@ -569,7 +624,6 @@
|
|
|
|
|
|
[cell.btnDevice setBackgroundImage:[UIImage imageNamed:@"img_thing_icon_bg_default"] forState:UIControlStateNormal];
|
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
rcell = cell;
|
|
|
@@ -613,6 +667,11 @@
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
|
|
|
|
|
|
+ if (_isReOrderMode) {
|
|
|
+ [collectionView beginInteractiveMovementForItemAtIndexPath:indexPath];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (indexPath.row < _deviceList.count) {//디바이스인 경우,
|
|
|
DeviceModel *device = _deviceList[indexPath.row];
|
|
|
|
|
|
@@ -622,6 +681,151 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+-(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+ return _isReOrderMode;
|
|
|
+}
|
|
|
+
|
|
|
+-(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)toIndexPath
|
|
|
+{
|
|
|
+ return _isReOrderMode;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+- (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+ return _isReOrderMode;
|
|
|
+}
|
|
|
+- (void)updateInteractiveMovementTargetPosition:(CGPoint)targetPosition
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+- (void)endInteractiveMovement
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+- (void)cancelInteractiveMovement
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(void)panGestureHandler:(UIGestureRecognizer *)sender
|
|
|
+{
|
|
|
+ CGPoint locationPoint = [self getCellCenter:[sender locationInView:_collectionView]];
|
|
|
+
|
|
|
+
|
|
|
+ switch (sender.state) {
|
|
|
+ case UIGestureRecognizerStateBegan:
|
|
|
+ {
|
|
|
+
|
|
|
+ NSIndexPath *indexPathOfPoint = [self.collectionView indexPathForItemAtPoint:locationPoint];
|
|
|
+ _moveCell = [self.collectionView cellForItemAtIndexPath:indexPathOfPoint];
|
|
|
+ UIGraphicsBeginImageContext(_moveCell.bounds.size);
|
|
|
+ [_moveCell.layer renderInContext:UIGraphicsGetCurrentContext()];
|
|
|
+ UIImage *cellImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
+ UIGraphicsEndImageContext();
|
|
|
+
|
|
|
+
|
|
|
+ _cellFakeView = [[UIImageView alloc] initWithImage:cellImage];
|
|
|
+ [_cellFakeView setCenter:locationPoint];
|
|
|
+ [_collectionView addSubview:_cellFakeView];
|
|
|
+
|
|
|
+ _dragIndexPath = indexPathOfPoint;
|
|
|
+ _moveCell.hidden = YES;
|
|
|
+
|
|
|
+ }
|
|
|
+ case UIGestureRecognizerStateChanged:
|
|
|
+ {
|
|
|
+ [_cellFakeView setCenter:locationPoint];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case UIGestureRecognizerStateCancelled:
|
|
|
+ case UIGestureRecognizerStateEnded:
|
|
|
+// [self.collectionView performBatchUpdates:^{
|
|
|
+// //update cell indexPath
|
|
|
+// _reorderingCellIndexPath = toIndexPath;
|
|
|
+// [self.collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
|
|
|
+// //did move
|
|
|
+// if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) {
|
|
|
+// [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath];
|
|
|
+// }
|
|
|
+// } completion:nil];
|
|
|
+
|
|
|
+//
|
|
|
+// _dragIndexPath= nil;
|
|
|
+// [_cellFakeView removeFromSuperview];
|
|
|
+
|
|
|
+//
|
|
|
+ [self moveItemIfNeeded];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)moveItemIfNeeded
|
|
|
+{
|
|
|
+ NSIndexPath *atIndexPath = _dragIndexPath;
|
|
|
+ NSIndexPath *toIndexPath = [_collectionView indexPathForItemAtPoint:_cellFakeView.center];
|
|
|
+
|
|
|
+ if (toIndexPath == nil || [atIndexPath isEqual:toIndexPath]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //can move
|
|
|
+// if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:canMoveToIndexPath:)]) {
|
|
|
+// if (![self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath canMoveToIndexPath:toIndexPath]) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //will move
|
|
|
+// if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:willMoveToIndexPath:)]) {
|
|
|
+// [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath willMoveToIndexPath:toIndexPath];
|
|
|
+// }
|
|
|
+
|
|
|
+ //move
|
|
|
+
|
|
|
+ [_collectionView performBatchUpdates:^{
|
|
|
+ //update cell indexPath
|
|
|
+// _dragIndexPath = toIndexPath;
|
|
|
+ [_collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
|
|
|
+ _moveCell.hidden = NO;
|
|
|
+ //did move
|
|
|
+// if ([_collectionView.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) {
|
|
|
+// [_collectionView.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath];
|
|
|
+// }
|
|
|
+ [self updateDataSource:atIndexPath toIndexPath:toIndexPath];
|
|
|
+
|
|
|
+ } completion:nil];
|
|
|
+
|
|
|
+
|
|
|
+ [_cellFakeView removeFromSuperview];
|
|
|
+ _dragIndexPath = nil;
|
|
|
+// [_cellInfo]
|
|
|
+}
|
|
|
+
|
|
|
+-(CGPoint)getCellCenter:(CGPoint)point
|
|
|
+{
|
|
|
+ CGPoint btnCenter = _moveCell.btnChangeOrder.center;
|
|
|
+ CGPoint cellCenter = _moveCell.contentView.center;
|
|
|
+
|
|
|
+ CGPoint result = CGPointMake(point.x-(btnCenter.x-cellCenter.x), point.y-(btnCenter.y-cellCenter.y));
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+-(void)updateDataSource:(NSIndexPath *)atIndexPath toIndexPath:(NSIndexPath *)toIndexPath
|
|
|
+{
|
|
|
+ NSLog(@"Update Data");
|
|
|
+
|
|
|
+// UIImage *image = [_photosArray objectAtIndex:fromIndexPath.item];
|
|
|
+// [_photosArray removeObjectAtIndex:fromIndexPath.item];
|
|
|
+// [_photosArray insertObject:image atIndex:toIndexPath.item];
|
|
|
+}
|
|
|
|
|
|
#pragma mark - UI Events
|
|
|
|
|
|
@@ -641,7 +845,7 @@
|
|
|
**/
|
|
|
|
|
|
- (IBAction)btnOptionTouched:(id)sender {
|
|
|
- [self toggleOptions:sender];
|
|
|
+ [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
|
|
|
}
|
|
|
|
|
|
#pragma mark - SocketService
|
|
|
@@ -677,6 +881,41 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
+#pragma mark - MoreButtonDelegate
|
|
|
+-(void)moreBtnAction:(id)sender
|
|
|
+{
|
|
|
+ NSInteger tag = [(UIButton *)sender tag];
|
|
|
+ NSLog(@"MoreBtn Action : %li", (long)tag);
|
|
|
+ switch (tag) {
|
|
|
+ case ReOrder:
|
|
|
+ {
|
|
|
+ // TODO : 순서 변경 모드로 진입
|
|
|
+ _isReOrderMode = YES;
|
|
|
+ [_collectionView reloadData];
|
|
|
+ _viewEditMode.hidden = NO;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Add:
|
|
|
+ {
|
|
|
+ // TODO : 장치 추가 화면 듸우기
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Del:
|
|
|
+ {
|
|
|
+ // TODO : 장치 삭제 모드로 진입
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Refresh:
|
|
|
+ {
|
|
|
+ // TODO : 리프레시
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
#pragma mark - MemoryWarning
|
|
|
|
|
|
@@ -703,4 +942,12 @@
|
|
|
[self collectionView:_collectionView didSelectItemAtIndexPath:btn.value];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+-(void)btnChangeOrderTouchDown:(id)sender {
|
|
|
+ CustomButton *info = (CustomButton *)sender;
|
|
|
+ NSLog(@"%@", info.value);
|
|
|
+ _dragIndexPath = info.value;
|
|
|
+}
|
|
|
+
|
|
|
@end
|