ThingsViewController.m 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. //
  2. // ThingsViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/10/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "CustomLabel.h"
  13. #import "CustomImageView.h"
  14. #import "CustomTextField.h"
  15. #import "CustomLabelButton.h"
  16. #import "CustomButton.h"
  17. #import "JYRefreshController.h"
  18. #import "WYPopoverController.h"
  19. #import "ImageUtil.h"
  20. #import "UIImageView+WebCache.h"
  21. #import "UIButton+WebCache.h"
  22. #import "CommandClassControlView.h"
  23. #import "ThingsDetailViewController.h"
  24. #import "ThingsViewController.h"
  25. #import "ThingsAddViewController.h"
  26. #import "ThingsAddStartViewController.h"
  27. #import "CustomTableView.h"
  28. #import "JYPullToRefreshController.h"
  29. #import "HomeMemberViewController.h"
  30. #define kfThingsTableViewCellHeight 100.0f
  31. #define kiCellInset 5
  32. #define kiCellItem 2
  33. #define kiCellRatio 74
  34. #define kiCellDivision 3
  35. /**
  36. Head Text Color : kUITextColor01
  37. Device 명 Text Color : kUITextColor01
  38. Device 상태표시 Text Color
  39. - 열림 : kUITextColor02
  40. - 닫힘 : kUITextColor01
  41. 장치 추가 Text Color : kUITextColor01
  42. (이미지 명)
  43. 디바이스 아이콘 bg
  44. - Default : img_thing_icon_bg_default
  45. - Active : img_thing_icon_bg_active
  46. 도어 컨텍트 센서 : 40102
  47. 가스 밸브 : 40108
  48. 다윈 플러그 : 40402
  49. **/
  50. @interface ThingsCollectionViewCell () {
  51. NSInteger _commandStatusElapsedTime;
  52. }
  53. @property (weak, nonatomic) NSIndexPath *indexPath;
  54. @end
  55. @implementation ThingsCollectionViewCell
  56. - (void)awakeFromNib {
  57. _pcontainerView.hidden = NO;
  58. }
  59. - (void)startProgressAni {
  60. //chagne button image
  61. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  62. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  63. } completion:nil];
  64. }
  65. - (void)stopProgressAni {
  66. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  67. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  68. } completion:nil];
  69. }
  70. @end
  71. @implementation ThingsAddCollectionCell
  72. @end
  73. @interface ThingsViewController () <UICollectionViewDataSource, UICollectionViewDelegate> {
  74. NSMutableArray *_deviceList;
  75. NSMutableArray *_deviceReOrderList;
  76. NSString *_pagingId, *_pagingType;
  77. BOOL _isNotFirstLoading, _isReOrderMode, _isDeleteMode;
  78. NSMutableArray<DeviceModel> *_commandArray;
  79. NSTimer *_devicesBackgroundTimer;
  80. NSTimer *_deviceCommandsBackgroundTimer;
  81. NSInteger _deviceFlag;
  82. UIPanGestureRecognizer *_moveCellGesture;
  83. NSIndexPath *_dragIndexPath;
  84. ThingsCollectionViewCell *_moveCell;
  85. NodeListModel *_nodeListData;
  86. DeviceModel *_selectHub;
  87. }
  88. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  89. @property (nonatomic, strong) UIView *cellFakeView;
  90. @end
  91. #pragma mark - Class Definition
  92. @implementation ThingsViewController
  93. - (void)viewDidLoad {
  94. [super viewDidLoad];
  95. [self initProperties];
  96. [self initUI];
  97. }
  98. - (void)viewWillAppear:(BOOL)animated {
  99. [super viewWillAppear:animated];
  100. [self prepareViewDidLoad];
  101. }
  102. - (void)initProperties {
  103. _deviceFlag = IS_IPHONE_6P ? 2 : 2;
  104. }
  105. - (void)initUI {
  106. //set tableview option
  107. _collectionView.delegate = self;
  108. _collectionView.dataSource = self;
  109. _collectionView.backgroundColor = [UIColor clearColor];
  110. _collectionView.alwaysBounceVertical = YES;
  111. _lblEditMode.hidden = YES;
  112. [self viewOfflineSetHidden:YES];
  113. [_btnClose setHidden:YES];
  114. [_btnOption setHidden:NO];
  115. [_viewEditMode setHidden:YES];
  116. // [self setThingsPopoverOptions];
  117. [self setMoreBtnArray];
  118. [self initRefreshController];
  119. }
  120. - (void)viewOfflineSetHidden:(BOOL)hidden{
  121. _viewHeight.constant = hidden ? 0 : 54;
  122. }
  123. - (void)initRefreshController {
  124. //set refresh controls
  125. __weak typeof(self) weakSelf = self;
  126. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.collectionView];
  127. self.refreshController.pullToRefreshHandleAction = ^{
  128. [weakSelf requestDeviceList:@YES];
  129. };
  130. }
  131. - (void)setThingsPopoverOptions {
  132. //
  133. // //set Popover Contents
  134. // __weak typeof(self) weakSelf = self;
  135. // _popooverOptionArray = [[NSMutableArray alloc] init];
  136. //
  137. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침", @"새로고침"),
  138. // @"iconName": @"img_bg_morepopup_icon_refresh",
  139. // @"target": weakSelf,
  140. // @"selector": [NSValue valueWithPointer:@selector(refreshDeviceList)]}];
  141. //
  142. //// if ([JDFacade facade].loginUser.level == 90) {//권한
  143. //// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"추가", @"추가"),
  144. //// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  145. //// @"target": weakSelf,
  146. //// @"selector": [NSValue valueWithPointer:@selector(addNewDevice)]}];
  147. ////
  148. //// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  149. //// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  150. //// @"target": weakSelf,
  151. //// @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
  152. //// }
  153. }
  154. - (void)setMoreBtnArray {
  155. _moreBtnArray = [NSMutableArray array];
  156. if (![[JDFacade facade].loginUser hasHomeHub]) {
  157. [_btnOption setHidden:YES];
  158. }
  159. if([[JDFacade facade].loginUser.gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  160. for (int i = 0; i < 4; i++) {
  161. MoreBtnModel *btnModel;
  162. switch (i) {
  163. case 0:{
  164. btnModel = [[MoreBtnModel alloc] initWithTyep:ReOrder isEnable:YES];
  165. btnModel.enable = [_nodeListData isCanReOrder];
  166. }
  167. break;
  168. case 1:{
  169. btnModel = [[MoreBtnModel alloc] initWithTyep:Add isEnable:YES];
  170. btnModel.enable = [_nodeListData isCanAddNode];
  171. }
  172. break;
  173. case 2:{
  174. btnModel = [[MoreBtnModel alloc] initWithTyep:Del isEnable:YES];
  175. btnModel.enable = [_nodeListData isCanDelNode];
  176. }
  177. break;
  178. case 3:
  179. btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  180. break;
  181. default:
  182. break;
  183. }
  184. [_moreBtnArray addObject:btnModel];
  185. }
  186. }
  187. else {
  188. MoreBtnModel *btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  189. [_moreBtnArray addObject:btnModel];
  190. }
  191. }
  192. - (void)prepareViewDidLoad {
  193. //fetch devices from server
  194. [self updateTitle];
  195. [self performSelector:@selector(requestHomeHubList) withObject:nil afterDelay:0.0f];
  196. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  197. }
  198. - (void)updateHomeHubStatusToDevices {
  199. [self updateTitle];
  200. for (DeviceModel *device in _deviceList) {
  201. device.onlineState = [JDFacade facade].loginUser.homehubOnlineState;
  202. }
  203. [_collectionView reloadData];
  204. }
  205. //제어를 요청한 장치상태를 조회함.
  206. - (void)requestPollingCommandStatusOfDeviceInBackground:(DeviceModel *)device {
  207. if (!_commandArray) {
  208. _commandArray = (NSMutableArray<DeviceModel> *)[[NSMutableArray alloc] init];
  209. }
  210. __block BOOL isStatusChanged = NO;
  211. if (device && [device isKindOfClass:[DeviceModel class]]) {//validate, aleady have,
  212. if (![_commandArray objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", device.deviceId, device.nodeId]) {//일치하는 디바이스가 있을 경우, 추가하지 않음.
  213. [_commandArray addObject:device];
  214. isStatusChanged = YES;
  215. }
  216. }
  217. if (_commandArray.count) {
  218. NSMutableString *pathParams = [[NSMutableString alloc] init];
  219. for (DeviceModel *pDevice in _commandArray) {
  220. NSString *prefix = [pathParams isEmptyString] ? ksEmptyString : @",";
  221. [pathParams appendFormat:@"%@%@_%@", prefix, pDevice.deviceId, pDevice.nodeId];
  222. }
  223. //20
  224. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_NODE_STATUS, pathParams];
  225. dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  226. NodeListModel *fdevices = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil
  227. modelClass:[NodeListModel class] showLoadingView:YES];
  228. if (fdevices && fdevices.nodes && fdevices.nodes.count) {
  229. [_commandArray enumerateObjectsUsingBlock:^(DeviceModel *rdevice, NSUInteger idx, BOOL * _Nonnull stop) {
  230. DeviceModel *matchedDevice = (DeviceModel *)[fdevices.nodes objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId];
  231. //실행 여부 및 10초 경과 확인
  232. BOOL isOverTimeLimit = [self elapsedSecondsFromNow:rdevice] > 10;
  233. //실행 여부 확인
  234. NSInteger elapsedTime = [self elapsedSecondsFrom:rdevice to:matchedDevice];
  235. BOOL hasChangedStatus = elapsedTime > 0;
  236. rdevice.isRequesting = [rdevice.contentValue isEqualToString:matchedDevice.contentValue] && !hasChangedStatus && !isOverTimeLimit;
  237. //TODO - home hub check
  238. // rdevice.requestTime = matchedDevice.requestTime;
  239. // rdevice.collectTime = matchedDevice.collectTime;
  240. rdevice.onlineState = matchedDevice.onlineState;
  241. if (!rdevice.isRequesting || !rdevice.isOnline || ![JDFacade facade].loginUser.isHomehubOnline) {//정상적으로 변경됨.
  242. rdevice.contentValue = matchedDevice.contentValue;
  243. [_commandArray removeObject:rdevice];
  244. isStatusChanged = YES;
  245. }
  246. #ifdef DEBUG_MODE
  247. NSLogInfo(@"==########== device command status = %@, elapsedTime = %zd ==########==", [JDFacade facade].loginUser.homehubOnlineState, elapsedTime);
  248. #endif
  249. }];
  250. } else {//
  251. NSLog(@"no devices");
  252. }
  253. if (_commandArray.count) {//커맨드 실행 중인 디바이스가 있을 경우,
  254. //schedul timer.
  255. if (!_deviceCommandsBackgroundTimer) {
  256. _deviceCommandsBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestPollingCommandStatusOfDeviceInBackground:) userInfo:nil repeats:YES];
  257. }
  258. } else {
  259. [_deviceCommandsBackgroundTimer invalidate];
  260. _deviceCommandsBackgroundTimer = nil;
  261. }
  262. //리스트와 상세의 상태를 계속 매핑해줌.
  263. [self matchDeviceListWithOnCommandsDevices];
  264. //변화가 있을 경우, 컬렉션뷰를 리로드
  265. if (isStatusChanged) {
  266. [_collectionView reloadData];
  267. ThingsDetailViewController *vc = (ThingsDetailViewController *)[JDFacade facade].currentViewController;
  268. if ([vc isKindOfClass:[ThingsDetailViewController class]]) {
  269. [vc.tableView reloadData];
  270. }
  271. }
  272. });
  273. }
  274. }
  275. - (NSInteger)elapsedSecondsFromNow:(DeviceModel *)runningDevice {
  276. NSInteger seconds = 0;
  277. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString]) {
  278. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  279. NSTimeInterval elapsed = [[NSDate systemDate] timeIntervalSinceDate:rdate];
  280. seconds = elapsed;
  281. }
  282. return seconds;
  283. }
  284. - (NSInteger)elapsedSecondsFrom:(DeviceModel *)runningDevice to:(DeviceModel *)fetchedDevice {
  285. NSInteger seconds = 0;
  286. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString] && fetchedDevice.collectTime && ![fetchedDevice.collectTime isEmptyString]) {
  287. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  288. NSDate *fdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:fetchedDevice.collectTime]];
  289. seconds = [fdate secondsAfterDate:rdate];
  290. }
  291. return seconds;
  292. }
  293. - (void)addNewDevice {
  294. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddViewController" storyboardName:@"Things"];
  295. [self presentViewController:vc animated:YES completion:nil];
  296. }
  297. - (void)refreshDeviceList {
  298. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  299. }
  300. #pragma mark - Main Logic
  301. - (void)requestDeviceListRecently {
  302. DeviceModel *firstDevice = [_deviceList firstObject];
  303. _pagingType = ksListPagingTypeUpward;
  304. _pagingId = firstDevice.createDatetime;
  305. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  306. }
  307. - (void)requestDeviceListOlder {
  308. DeviceModel *lastDevice = [_deviceList lastObject];
  309. _pagingType = ksListPagingTypeDownward;
  310. _pagingId = lastDevice.createDatetime;
  311. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  312. }
  313. - (void)requestHomeHubList {
  314. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DEVICE_LIST aditional:@""];
  315. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestGET parameters:nil
  316. modelClass:[DeviceListModel class] showLoadingView:NO completion:^(id responseObject) {
  317. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  318. return;
  319. }
  320. DeviceListModel *deviceList = (DeviceListModel *)responseObject;
  321. NSMutableArray *list = [NSMutableArray array];
  322. for (DeviceModel *info in deviceList.list) {
  323. [list addObject:info];
  324. }
  325. [JDFacade facade].loginUser.deviceList = list;
  326. } failure:^(id errorObject) {
  327. // [self releaseDevicesTimer];
  328. JDErrorModel *error = (JDErrorModel *)errorObject;
  329. [[JDFacade facade] alert:error.errorMessage];
  330. }];
  331. }
  332. - (void)requestDeviceList:(id)arg {
  333. if (![JDFacade facade].loginUser.hasHomeHub) {
  334. return;
  335. }
  336. // BOOL showLoadingView = [arg isKindOfClass:[NSTimer class]] ? [((NSTimer *)arg).userInfo boolValue] : [arg boolValue];
  337. BOOL showLoadingView = YES;
  338. //parameters
  339. NSDictionary *parameter = @{@"device_id": _selectHub ? _selectHub.deviceId : ksEmptyString};
  340. // NSString *path = [NSString stringWithFormat:API_GET_DEVICE_LIST];
  341. // 멀티 홈허브 환경에서 선택된 홈허브 아이디가 있을경우 적용하기
  342. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_NODE_LIST aditional:@""];
  343. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestPOST parameters:parameter
  344. modelClass:[NodeListModel class] showLoadingView:showLoadingView completion:^(id responseObject) {
  345. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  346. return;
  347. }
  348. _nodeListData = (NodeListModel *)responseObject;
  349. [self setMoreBtnArray];
  350. if (_nodeListData && _nodeListData.nodes && _nodeListData.nodes.count) {
  351. _deviceList = _nodeListData.nodes;
  352. _deviceReOrderList = [[NSMutableArray alloc] initWithArray:_deviceList];
  353. [self updateTitle];
  354. } else {
  355. if (!_deviceList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
  356. _lblConnectHub.text = @"등록된 장치가 없습니다";
  357. _imgvHubAlert.hidden = YES;
  358. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_nodevice"];
  359. }
  360. }
  361. [_collectionView reloadData];
  362. // [self requestPollingDevicesStatusInBackground];
  363. //refresh controller
  364. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  365. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  366. }
  367. } failure:^(id errorObject) {
  368. // [self releaseDevicesTimer];
  369. JDErrorModel *error = (JDErrorModel *)errorObject;
  370. [[JDFacade facade] alert:error.errorMessage];
  371. }];
  372. }
  373. - (void)requestDeviceOrderReset {
  374. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_NODE_ORDER_RESET aditional:nil];
  375. NSDictionary *parameter = @{@"type": @"node"};
  376. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  377. NSLog(@"Reset Result : %@", responseObject);
  378. [self refreshDeviceList];
  379. } failure:^(id errorObject) {
  380. JDErrorModel *error = (JDErrorModel *)errorObject;
  381. [[JDFacade facade] alert:error.errorMessage];
  382. }];
  383. }
  384. - (void)requestDeviceOrderChange {
  385. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_NODE_ORDER_CHANGE aditional:nil];
  386. NSMutableArray *nodeOrder = [NSMutableArray array];
  387. for (DeviceModel *info in _deviceReOrderList) {
  388. NSDictionary *orderInfo = @{
  389. @"device_id": info.deviceId,
  390. @"node_id": info.nodeId};
  391. [nodeOrder addObject:orderInfo];
  392. }
  393. NSDictionary *parameter = @{@"nodes": nodeOrder};
  394. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  395. NSLog(@"ReOrder Result : %@", responseObject);
  396. // [self refreshDeviceList];
  397. } failure:^(id errorObject) {
  398. JDErrorModel *error = (JDErrorModel *)errorObject;
  399. [[JDFacade facade] alert:error.errorMessage];
  400. }];
  401. }
  402. //디바이스 상태를 3초마다 갱신함.
  403. - (void)requestPollingDevicesStatusInBackground {
  404. return;
  405. //schedul timer.
  406. if (!_devicesBackgroundTimer) {
  407. _devicesBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestDeviceList:) userInfo:@NO repeats:YES];
  408. }
  409. }
  410. - (void)updateTitle {
  411. // _lblTitle.text = [NSString stringWithFormat:@"장치 전체 %zd", _deviceList.count];
  412. _lblCount.text = [NSString stringWithFormat:@"%zd", _deviceList.count];
  413. NSLog(@"HomeHubID : %@", [JDFacade facade].loginUser.homehubDeviceId);
  414. if (![JDFacade facade].loginUser.hasHomeHub) {//홈허브 아이디가 없는 경우,
  415. [_mainView bringSubviewToFront:_addHubContainerView];
  416. _addHubContainerView.hidden = NO;
  417. _collectionView.hidden = YES;
  418. _btnOption.hidden = NO;
  419. _btnClose.hidden = YES;
  420. if (![JDFacade facade].loginUser.homegrpId) {//연결한 적이 없음
  421. _lblConnectHub.text = @"초대를 받아서\n시작해 보세요";
  422. _imgvHubAlert.hidden = YES;
  423. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_invitation"];
  424. _lblLeaveAccount.hidden = YES;
  425. _lblSimpleMemberInfo.hidden = YES;
  426. } else {//홈허브가 삭제됨.
  427. _lblTitle.text = @"홈허브 삭제됨";
  428. _imgvHubAlert.hidden = NO;
  429. _lblConnectHub.text = @"홈허브를 다시 연결하려면\n고객센터에 문의해주세요";
  430. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_cscenter"];
  431. if ([JDFacade facade].loginUser.level < 90) {//일반 유저일 경우,
  432. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_wait"];
  433. _lblLeaveAccount.hidden = NO;
  434. _lblSimpleMemberInfo.hidden = NO;
  435. [_lblLeaveAccount setUnderLine:_lblLeaveAccount.text];
  436. if (!_lblLeaveAccount.touchHandler) {
  437. [_lblLeaveAccount addTouchEventHandler:^(id label) {
  438. [self leaveHomegroup];
  439. }];
  440. }
  441. }
  442. }
  443. } else {
  444. NSLog(@"이쪽으로 빠짐2");
  445. if (![JDFacade facade].loginUser.isHomehubOnline) {
  446. _imgvHubAlert.hidden = NO;
  447. _lblTitle.text = @"홈허브 오프라인";
  448. [_lblTitle setColor:kUITextColor01 text:_lblTitle.text];
  449. } else {
  450. _imgvHubAlert.hidden = YES;
  451. }
  452. [_mainView bringSubviewToFront:_collectionView];
  453. _addHubContainerView.hidden = YES;
  454. _collectionView.hidden = NO;
  455. _btnOption.hidden = NO;
  456. }
  457. if ([_lblTitle.text rangeOfString:@"장치 전체"].location != NSNotFound) {
  458. [_lblTitle setColor:kUITextColor03 text:[NSString stringWithFormat:@"%zd", _deviceList.count]];
  459. }
  460. }
  461. - (void)leaveHomegroup {
  462. HomeMemberViewController *vc = [[HomeMemberViewController alloc] init];
  463. [vc leaveHomegroup];
  464. }
  465. - (void)matchDeviceListWithOnCommandsDevices {
  466. for (DeviceModel *rdevice in _commandArray) {
  467. DeviceModel *matchedDevice = [_deviceList objectByUsingPredicateFormat:@"deviceId == %@", rdevice.deviceId]; //일치하는 디바이스가 있을 경우, 추가하지 않음.
  468. // DeviceModel *matchedDevice = [_deviceList objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId]; //일치하는 디바이스가 있을 경우, 추가하지 않음.
  469. if (matchedDevice) {
  470. matchedDevice.isRequesting = rdevice.isRequesting;
  471. matchedDevice.requestTime = rdevice.requestTime;
  472. }
  473. }
  474. // [_collectionView reloadData];
  475. }
  476. - (void)releaseDevicesTimer {
  477. if (_devicesBackgroundTimer) {
  478. [_devicesBackgroundTimer invalidate];
  479. _devicesBackgroundTimer = nil;
  480. }
  481. }
  482. #pragma mark - UICollectionView Delegate
  483. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  484. NSInteger auth = [JDFacade facade].loginUser.level == 90 && !_isDeleteMode && [_nodeListData isCanAddNode]; //마스터 권한일 경우,
  485. NSInteger count = _deviceList.count % _deviceFlag == 0 ? _deviceList.count + auth : _deviceList.count + auth; //홀수일 경우, 멤버 초대 버튼을 추가해줌.
  486. // NSInteger count = _deviceList.count;
  487. return count;
  488. }
  489. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  490. UICollectionViewCell *rcell = nil;
  491. UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
  492. if (indexPath.row < _deviceList.count) {
  493. ThingsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsCellIdentifier" forIndexPath:indexPath];
  494. // [cell.btnDelete setHidden:YES];
  495. // [cell.btnChangeOrder setHidden:YES];
  496. DeviceModel *device =_deviceList[indexPath.row];
  497. cell.indexPath = indexPath;
  498. cell.lblDeviceName.text = device.prdName;
  499. // [cell.btnDevice sd_setImageWithURL:[NSURL URLWithString:device.imageFileName] forState:UIControlStateNormal
  500. // placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  501. // [cell layoutIfNeeded];
  502. // }];
  503. [cell.imgDevice setImage:[UIImage imageNamed:device.deviceclassTypeId]];
  504. [cell.btnDevice addTarget:self action:@selector(btnDeviceTouched:) forControlEvents:UIControlEventTouchUpInside];
  505. cell.btnDevice.value = indexPath;
  506. //커맨드 클래스 뷰를 초기화함.
  507. [[cell.controlContainer subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  508. UIView *subview = (UIView *)obj;
  509. [subview removeFromSuperview];
  510. }];
  511. NSLog(@"Is Requesting : %@", BOOLToString(device.isRequesting));
  512. // TODO : 어떤 부분인지 내용 확인 필요
  513. cell.pcontainerView.hidden = !device.isRequesting;
  514. if (!cell.pcontainerView.hidden) {
  515. [cell startProgressAni];
  516. } else {
  517. [cell stopProgressAni];
  518. }
  519. //허브 On-Off line check
  520. // cell.lblDeviceStatus.hidden = !([[JDFacade facade].loginUser.homehubOnlineState isEqualToString:@"OFF"] || [device.onlineState isEqualToString:@"OFF"]);
  521. // cell.controlContainer.hidden = !cell.lblDeviceStatus.hidden;
  522. cell.btnDelete.hidden = !_isDeleteMode;
  523. cell.btnChangeOrder.hidden = !_isReOrderMode;
  524. if(_isDeleteMode || _isReOrderMode)
  525. {
  526. cell.btnDevice.enabled = NO;
  527. cell.btnDeviceControl.hidden = YES;
  528. }
  529. else
  530. {
  531. cell.btnDevice.enabled = YES;
  532. cell.btnDeviceControl.hidden = NO;
  533. }
  534. [cell.btnChangeOrder addGestureRecognizer:drag];
  535. cell.btnChangeOrder.value = indexPath;
  536. // 이부분 확인해 볼것
  537. if (!cell.controlContainer.hidden) {//커맨드 클래스 타입별 컨트롤 호출
  538. [cell.btnDevice setBackgroundImage:[device backgroundImageForMandatary:device.contentValue] forState:UIControlStateNormal];
  539. CommandClassControlView *controlView = [CommandClassControlView viewForCommandClass:device.cmdclsType];
  540. controlView.device = device;
  541. if(_isDeleteMode || _isReOrderMode)
  542. {
  543. controlView.isReOrderMode = YES;
  544. }
  545. else {
  546. controlView.isReOrderMode = NO;
  547. }
  548. cell.controlContainer.hidden = !controlView;
  549. if (!cell.controlContainer.hidden) {
  550. UIView *superview = cell.controlContainer;
  551. [superview addSubview:controlView];
  552. // controlView.width = IS_IPHONE_6P ? 98.0f : 120;
  553. // NSLog(@"Controll View : %f", ViewWidth(superview));
  554. // controlView.width = ViewWidth(superview);
  555. [controlView mas_makeConstraints:^(MASConstraintMaker *make) {
  556. // make.size.mas_equalTo(superview.frame.size);
  557. // make.center.equalTo(superview);
  558. make.top.equalTo(superview.mas_top).with.offset(0); //with is an optional semantic filler
  559. make.left.equalTo(superview.mas_left).with.offset(0);
  560. make.bottom.equalTo(superview.mas_bottom).with.offset(0);
  561. make.right.equalTo(superview.mas_right).with.offset(0);
  562. }];
  563. }
  564. } else {
  565. cell.lblDeviceStatus.text = @"OFFLINE";
  566. cell.lblDeviceStatus.textColor = kUITextColor01;
  567. [cell.btnDevice setBackgroundImage:[UIImage imageNamed:@"img_thing_icon_bg_default"] forState:UIControlStateNormal];
  568. }
  569. rcell = cell;
  570. } else {
  571. ThingsAddCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsAddCellIdentifier" forIndexPath:indexPath];
  572. //
  573. if (![cell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  574. [cell.btnAdd addTarget:self action:@selector(addNewDevice) forControlEvents:UIControlEventTouchUpInside];
  575. }
  576. rcell = cell;
  577. }
  578. return rcell;
  579. }
  580. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  581. // return CGSizeZero;
  582. //
  583. // //FIXME : 권한 추가
  584. //// if (_memberList.count % 2 == 1 || [JDFacade facade].loginUser.level < 90 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  585. // if (_deviceList.count % 2 == 1 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  586. // }
  587. //
  588. // return CGSizeMake(IPHONE_WIDTH, 160.0f);
  589. //}
  590. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  591. {
  592. return CGSizeMake(ViewWidth(_collectionView), (((ViewWidth(_collectionView)-kiCellInset)+kiCellRatio) / kiCellItem) / kiCellDivision+(kiCellItem*kiCellItem));
  593. }
  594. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  595. return CGSizeMake((ViewWidth(_collectionView)-kiCellInset) / kiCellItem, ((ViewWidth(_collectionView)-kiCellInset)+kiCellRatio) / kiCellItem);
  596. }
  597. // Cell 사이 최소 간격
  598. - (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  599. return kiCellInset;
  600. }
  601. // Line 별 최소 간격
  602. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  603. {
  604. return kiCellInset;
  605. }
  606. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  607. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  608. if (_isReOrderMode) {
  609. [collectionView beginInteractiveMovementForItemAtIndexPath:indexPath];
  610. return;
  611. }
  612. if (indexPath.row < _deviceList.count) {//디바이스인 경우,
  613. DeviceModel *device = _deviceList[indexPath.row];
  614. ThingsDetailViewController *vc = (ThingsDetailViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsDetailViewController" storyboardName:@"Things"];
  615. vc.refDevice = device;
  616. [self presentViewController:vc animated:YES completion:nil];
  617. }
  618. }
  619. -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
  620. {
  621. return _isReOrderMode;
  622. }
  623. -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)toIndexPath
  624. {
  625. return _isReOrderMode;
  626. }
  627. - (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath
  628. {
  629. return _isReOrderMode;
  630. }
  631. - (void)updateInteractiveMovementTargetPosition:(CGPoint)targetPosition
  632. {
  633. }
  634. - (void)endInteractiveMovement
  635. {
  636. }
  637. - (void)cancelInteractiveMovement
  638. {
  639. }
  640. -(void)panGestureHandler:(UIGestureRecognizer *)sender
  641. {
  642. CGPoint locationPoint = [self getCellCenter:[sender locationInView:_collectionView]];
  643. switch (sender.state) {
  644. case UIGestureRecognizerStateBegan:
  645. {
  646. NSIndexPath *indexPathOfPoint = [self.collectionView indexPathForItemAtPoint:locationPoint];
  647. _moveCell = (ThingsCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPathOfPoint];
  648. UIGraphicsBeginImageContext(_moveCell.bounds.size);
  649. [_moveCell.layer renderInContext:UIGraphicsGetCurrentContext()];
  650. UIImage *cellImage = UIGraphicsGetImageFromCurrentImageContext();
  651. UIGraphicsEndImageContext();
  652. _cellFakeView = [[UIImageView alloc] initWithImage:cellImage];
  653. [_cellFakeView setCenter:locationPoint];
  654. [_collectionView addSubview:_cellFakeView];
  655. _dragIndexPath = indexPathOfPoint;
  656. _moveCell.hidden = YES;
  657. }
  658. case UIGestureRecognizerStateChanged:
  659. {
  660. [_cellFakeView setCenter:locationPoint];
  661. }
  662. break;
  663. case UIGestureRecognizerStateCancelled:
  664. case UIGestureRecognizerStateEnded:
  665. // [self.collectionView performBatchUpdates:^{
  666. // //update cell indexPath
  667. // _reorderingCellIndexPath = toIndexPath;
  668. // [self.collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
  669. // //did move
  670. // if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) {
  671. // [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath];
  672. // }
  673. // } completion:nil];
  674. //
  675. // _dragIndexPath= nil;
  676. // [_cellFakeView removeFromSuperview];
  677. //
  678. [self moveItemIfNeeded];
  679. break;
  680. default:
  681. break;
  682. }
  683. }
  684. - (void)moveItemIfNeeded
  685. {
  686. NSIndexPath *atIndexPath = _dragIndexPath;
  687. NSIndexPath *toIndexPath = [_collectionView indexPathForItemAtPoint:_cellFakeView.center];
  688. if (toIndexPath == nil || [atIndexPath isEqual:toIndexPath]) {
  689. return;
  690. }
  691. //can move
  692. // if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:canMoveToIndexPath:)]) {
  693. // if (![self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath canMoveToIndexPath:toIndexPath]) {
  694. // return;
  695. // }
  696. // }
  697. //
  698. // //will move
  699. // if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:willMoveToIndexPath:)]) {
  700. // [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath willMoveToIndexPath:toIndexPath];
  701. // }
  702. //move
  703. [_collectionView performBatchUpdates:^{
  704. //update cell indexPath
  705. // _dragIndexPath = toIndexPath;
  706. [_collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
  707. _moveCell.hidden = NO;
  708. //did move
  709. // if ([_collectionView.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) {
  710. // [_collectionView.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath];
  711. // }
  712. [self updateDataSource:atIndexPath toIndexPath:toIndexPath];
  713. } completion:nil];
  714. [_cellFakeView removeFromSuperview];
  715. _dragIndexPath = nil;
  716. // [_cellInfo]
  717. }
  718. -(CGPoint)getCellCenter:(CGPoint)point
  719. {
  720. CGPoint btnCenter = _moveCell.btnChangeOrder.center;
  721. CGPoint cellCenter = _moveCell.contentView.center;
  722. CGPoint result = CGPointMake(point.x-(btnCenter.x-cellCenter.x), point.y-(btnCenter.y-cellCenter.y));
  723. return result;
  724. }
  725. -(void)updateDataSource:(NSIndexPath *)atIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  726. {
  727. NSLog(@"Update Data");
  728. NSLog(@"From Index : %li", (long)atIndexPath.item);
  729. NSLog(@"To Index : %li", (long)toIndexPath.item);
  730. DeviceModel *device =_deviceReOrderList[atIndexPath.item];
  731. NSLog(@"DeviceModel : %@", device);
  732. [_deviceReOrderList removeObjectAtIndex:atIndexPath.item];
  733. [_deviceReOrderList insertObject:device atIndex:toIndexPath.item];
  734. }
  735. #pragma mark - UI Events
  736. /**
  737. 첫번째 이미지
  738. - img_bg_morepopup_icon_thingschange
  739. - img_bg_morepopup_icon_thingschange_press
  740. 두번째 이미지 :
  741. - img_bg_morepopup_icon_add
  742. - img_bg_morepopup_icon_add_press
  743. 세번째 이미지 :
  744. - img_bg_morepopup_icon_delete
  745. - img_bg_morepopup_icon_delete_press
  746. 네번째 이미지 :
  747. - img_bg_morepopup_icon_refresh
  748. - img_bg_morepopup_icon_refresh_press
  749. **/
  750. - (IBAction)btnOptionTouched:(id)sender {
  751. [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
  752. }
  753. - (IBAction)btnReFreshTouched:(id)sender {
  754. [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록의 순서를\n장치가 등록된 순으로 초괴화합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  755. if (buttonIndex == 0) {
  756. [self requestDeviceOrderReset];
  757. [self toggleReOrderMode:NO];
  758. }
  759. }];
  760. }
  761. - (IBAction)btnConfirmTouched:(id)sender {
  762. [[JDFacade facade] confirmTitle:@"알림" message:@"현재 편집된 장치 목록 순서를\n저장하시겠습니까?" btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  763. if (buttonIndex == 0) {
  764. // TODO : 데이터 업데이트 하기
  765. _deviceList = [[NSMutableArray alloc] initWithArray:_deviceReOrderList];
  766. [self requestDeviceOrderChange];
  767. [self toggleReOrderMode:NO];
  768. }
  769. }];
  770. // _deviceList = _deviceReOrderList;
  771. // [self toggleReOrderMode:NO];
  772. }
  773. - (IBAction)btnCloseTouched:(id)sender {
  774. if (_isReOrderMode) {
  775. [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록 순서를 저장하지 않고\n이전화면으로 이동합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  776. if (buttonIndex == 0) {
  777. [self toggleReOrderMode:NO];
  778. }
  779. }];
  780. }
  781. else {
  782. [self toggleEditMode:NO];
  783. }
  784. }
  785. -(void)toggleReOrderMode:(Boolean)isReOrder
  786. {
  787. _isReOrderMode = isReOrder;
  788. _viewEditMode.hidden = !isReOrder;
  789. _btnOption.hidden = isReOrder;
  790. [_collectionView reloadData];
  791. _viewTitle.hidden = isReOrder;
  792. _lblEditMode.hidden = !isReOrder;
  793. _lblEditMode.text = @"장치 목록 순서 편집";
  794. }
  795. -(void)toggleEditMode:(Boolean)isEdit
  796. {
  797. _isDeleteMode = isEdit;
  798. _viewEditMode.hidden = !isEdit;
  799. _btnOption.hidden = isEdit;
  800. [_collectionView reloadData];
  801. _viewTitle.hidden = isEdit;
  802. _lblEditMode.hidden = !isEdit;
  803. _lblEditMode.text = @"장치 삭제";
  804. _btnEditSave.hidden = !isEdit;
  805. _btnEditRefresh.hidden = !isEdit;
  806. }
  807. #pragma mark - SocketService
  808. - (void) socketDidReceiveMessage:(id)message info:(NSDictionary *)info
  809. {
  810. SocketModel *result = (SocketModel *)message;
  811. NSLog(@"Result Info : %@", result);
  812. SWITCH(result.messageType)
  813. {
  814. CASE (@"node.register")
  815. {
  816. }
  817. CASE (@"node.delete")
  818. {
  819. }
  820. CASE(@"nodes.reload")
  821. {
  822. }
  823. DEFAULT
  824. {
  825. break;
  826. }
  827. }
  828. }
  829. - (void) socketDidFailWithError:(NSError *)error {
  830. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  831. }
  832. -(void) receiveSocketData:(NSNotification *)notification {
  833. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  834. // CommandModel *response = [[CommandModel alloc] initWithDictionary:notification.object error:nil];
  835. NSLog(@"Result : %@", result);
  836. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_CONTENT]) {
  837. ContentModel *response = [[ContentModel alloc] initWithDictionary:notification.object error:nil];
  838. for (DeviceModel *info in _deviceList) {
  839. if ([info.deviceId isEqualToString:response.deviceId] && [info.nodeId isEqualToString:response.nodeId]) {
  840. info.collectTime = response.collectTime;
  841. id contentValue = [NSJSONSerialization JSONObjectWithData:[response.contentValue dataUsingEncoding:NSUTF8StringEncoding]
  842. options:NSJSONReadingAllowFragments
  843. error:nil];
  844. info.contentValue = contentValue[info.cmdclsId];
  845. if (info.isRequesting) {
  846. info.isRequesting = NO;
  847. }
  848. [_collectionView reloadData];
  849. break;
  850. // NSLog(@"Info : %@", contentValue[info.cmdclsId]);
  851. }
  852. }
  853. }
  854. else if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_COMMAND_RES]) {
  855. }
  856. }
  857. #pragma mark - MoreButtonDelegate
  858. -(void)moreBtnAction:(id)sender
  859. {
  860. NSInteger tag = [(UIButton *)sender tag];
  861. NSLog(@"MoreBtn Action : %li", (long)tag);
  862. switch (tag) {
  863. case ReOrder:
  864. {
  865. [self toggleReOrderMode:YES];
  866. }
  867. break;
  868. case Add:
  869. {
  870. [self addNewDevice];
  871. }
  872. break;
  873. case Del:
  874. {
  875. [self toggleEditMode:YES];
  876. }
  877. break;
  878. case Refresh:
  879. {
  880. [self refreshDeviceList];
  881. }
  882. break;
  883. default:
  884. break;
  885. }
  886. }
  887. #pragma mark - MemoryWarning
  888. - (void)viewWillDisappear:(BOOL)animated {
  889. if (_deviceCommandsBackgroundTimer) {
  890. [_deviceCommandsBackgroundTimer invalidate];
  891. _deviceCommandsBackgroundTimer = nil;
  892. }
  893. [self releaseDevicesTimer];
  894. }
  895. - (void)didReceiveMemoryWarning
  896. {
  897. [super didReceiveMemoryWarning];
  898. // Dispose of any resources that can be recreated.
  899. }
  900. -(void)btnDeviceTouched:(id)sender
  901. {
  902. }
  903. @end