SKWatchViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. //
  2. // WatchViewController.m
  3. // SikeyComm
  4. //
  5. // Created by 振兴 刘 on 2017/11/28.
  6. // Copyright © 2017年 BaH Cy. All rights reserved.
  7. //
  8. #import "SKWatchViewController.h"
  9. #import "SKWatchViewCell.h"
  10. #import "WatchHeaderReusableView.h"
  11. #import "EDefines.h"
  12. #import <UMMobClick/MobClick.h>
  13. #import "WatchSMSViewController.h"
  14. #import "SKStrangerInterceptViewController.h"
  15. #import "SKFlowControlViewController.h"
  16. #import "SKElectricityModeViewController.h"
  17. #import "SKOnOffSettingViewController.h"
  18. #import "SKFactoryInfoViewController.h"
  19. #import "SKEyeCareViewController.h"
  20. #import "SKPushFlagViewController.h"
  21. #import "SKMessageCenterViewController.h"
  22. #import "WatchUpdateViewController.h"
  23. #import "SKChildListView.h"
  24. #define CELL_MARGIN 12
  25. @interface SKWatchViewController ()<UICollectionViewDelegateFlowLayout> {
  26. NSMutableDictionary* mFunctionDic;
  27. }
  28. @end
  29. @implementation SKWatchViewController
  30. static NSString * const CellReuseIdentifier = @"WatchCellID";
  31. static NSString * const HeaderReuseIdentifier = @"WatchHeaderID";
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. [self.navigationController setNavigationBarHidden:YES];
  35. [self addNavigationView];
  36. [self.mNavigationView refreshChildView];
  37. self.mCollectionView.alwaysBounceVertical = YES;
  38. [self.mCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([WatchHeaderReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderReuseIdentifier];
  39. [self refreshPermissionsMask];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated {
  42. [super viewWillAppear:animated];
  43. [self.navigationController setNavigationBarHidden:YES];
  44. [self initView];
  45. }
  46. - (void)onChangeChild:(NSInteger)index {
  47. [self.mNavigationView refreshChildView];
  48. [self initView];
  49. }
  50. - (void)initView {
  51. [mFunctionDic removeAllObjects];
  52. mFunctionDic = [NSMutableDictionary new];
  53. [self initFunction];
  54. [self.mCollectionView reloadData];
  55. }
  56. - (void)initFunction {
  57. ChildModel* childModel = [DataManager shared].mSelectChildModel;
  58. DeviceModel* model = childModel.device;
  59. BOOL isRole = childModel.role <= ROLE_ADMIN;
  60. if (!isRole) {
  61. NSMutableArray* firstArray = NSMutableArray.new;
  62. if (model.match.magicAcademy)
  63. [firstArray addObject:@(0)];
  64. if (model.match.redFlower)
  65. [firstArray addObject:@(1)];
  66. //[firstArray addObject:@(2)]; //此界面不显示计步
  67. mFunctionDic[@"0"] = firstArray;
  68. NSMutableArray* secondArray = NSMutableArray.new;
  69. [secondArray addObject:@(0)];
  70. if (model.match.callCharge) //国外版本不支持//
  71. [secondArray addObject:@(1)];
  72. [secondArray addObject:@(2)];
  73. [secondArray addObject:@(3)];
  74. if (model.match.wifi)
  75. [secondArray addObject:@(4)];
  76. mFunctionDic[@"1"] = secondArray;
  77. } else {
  78. NSMutableArray* firstArray = NSMutableArray.new;
  79. if (model.match.magicAcademy)
  80. [firstArray addObject:@(0)];
  81. if (model.match.redFlower)
  82. [firstArray addObject:@(1)];
  83. //[firstArray addObject:@(2)]; //此界面不显示计步
  84. mFunctionDic[@"0"] = firstArray;
  85. NSMutableArray* thirdArray = NSMutableArray.new;
  86. [thirdArray addObject:@(0)];
  87. [thirdArray addObject:@(1)];
  88. [thirdArray addObject:@(2)];
  89. if (model.match.clock)
  90. [thirdArray addObject:@(3)];
  91. if (model.match.eventReminder)
  92. [thirdArray addObject:@(4)];
  93. mFunctionDic[@"1"] = thirdArray;
  94. NSMutableArray* fourArray = NSMutableArray.new;
  95. if (model.match.wifi)
  96. [fourArray addObject:@(0)];
  97. if ([model isBind])
  98. [fourArray addObject:@(1)];
  99. if (model.match.electricityMode)
  100. [fourArray addObject:@(2)];
  101. if (model.match.eyeCare)
  102. [fourArray addObject:@(3)];
  103. if (model.match.flowControl)
  104. [fourArray addObject:@(4)];
  105. if ([model isBind] && model.match.update)
  106. [fourArray addObject:@(5)];
  107. if ([model isBind])
  108. [fourArray addObject:@(6)];
  109. //[fourArray addObject:@(7)];
  110. if([model isBind] && (model.match.autoLocation || model.match.apn))
  111. [fourArray addObject:@(8)];
  112. if ([model isBind] && model.match.function)
  113. [fourArray addObject:@(9)];
  114. mFunctionDic[@"2"] = fourArray;
  115. NSMutableArray* secondArray = NSMutableArray.new;
  116. [secondArray addObject:@(0)];
  117. if (model.match.callCharge) //国外版本不支持//
  118. [secondArray addObject:@(1)];
  119. if (model.match.watchSMS)
  120. [secondArray addObject:@(2)];
  121. if (model.match.strangerIntercept)
  122. [secondArray addObject:@(3)];
  123. if (model.match.callRecord)
  124. [secondArray addObject:@(4)];
  125. mFunctionDic[@"3"] = secondArray;
  126. }
  127. }
  128. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  129. ChildModel* model = [DataManager shared].mSelectChildModel;
  130. BOOL isRole = model.role <= ROLE_ADMIN;
  131. return isRole ? ([model.device isBind] ? 4:3) : 2;
  132. }
  133. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  134. NSString* key = [NSString stringWithFormat:@"%ld", section];
  135. NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
  136. NSArray* dataArray = array[0];
  137. return (dataArray.count-1)/4 * 4 + 4;
  138. }
  139. // 表头尺寸
  140. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  141. if (section == 0) {
  142. return CGSizeMake(SCREEN_WIDTH, 10);
  143. }
  144. else {
  145. BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
  146. if (isRole)
  147. return CGSizeMake(SCREEN_WIDTH, 34);
  148. else
  149. return CGSizeMake(SCREEN_WIDTH, 15);
  150. }
  151. }
  152. // 显示表头的数据
  153. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  154. if (kind == UICollectionElementKindSectionHeader) {
  155. BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
  156. if (isRole) {
  157. WatchHeaderReusableView *reusableView = [self.mCollectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
  158. if(reusableView == nil)
  159. reusableView = [[WatchHeaderReusableView alloc] init];
  160. NSString* key = [NSString stringWithFormat:@"%@.%ld", @"Watch.Admin.Section", (long)indexPath.section];
  161. reusableView.mHeaderTitle.text = NSLocalizedString(key, nil);
  162. if (indexPath.section == 0) {
  163. [reusableView.mHeaderView setHidden:YES];
  164. [reusableView.mWhiteView setHidden:YES];
  165. }
  166. else {
  167. [reusableView.mHeaderView setHidden:indexPath.section == 0];
  168. [reusableView.mWhiteView setHidden:indexPath.section != 0];
  169. }
  170. return reusableView;
  171. }
  172. else {
  173. WatchHeaderReusableView *reusableView = [self.mCollectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
  174. if(reusableView == nil)
  175. reusableView = [[WatchHeaderReusableView alloc] init];
  176. [reusableView.mHeaderView setHidden:YES];
  177. [reusableView.mWhiteView setHidden:YES];
  178. return reusableView;
  179. }
  180. }
  181. return nil;
  182. }
  183. //设置每个子视图的缩进
  184. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  185. return UIEdgeInsetsMake(0, 0, 0, 0);
  186. }
  187. //设置子视图上下之间的距离
  188. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  189. return 0;
  190. }
  191. //设置子视图左右之间的距离
  192. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  193. return 0;
  194. }
  195. //返回每个子视图的大小
  196. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  197. CGFloat itemWidth = SCREEN_WIDTH / 4 ;
  198. return CGSizeMake(itemWidth, 110);
  199. }
  200. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  201. SKWatchViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
  202. BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
  203. NSString* titleName = @"";
  204. NSString* imageName = @"";
  205. NSString* titleKey = isRole ? @"Watch.Admin" : @"Watch.NotAdmin";
  206. NSString* imageKey = isRole ? @"watch_icon" : @"watch_icon_notadmin";
  207. NSString* key = [NSString stringWithFormat:@"%ld", indexPath.section];
  208. NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
  209. NSArray* dataArray = array[0];
  210. if (indexPath.row >= dataArray.count) {
  211. [cell setUserInteractionEnabled:NO];
  212. titleName = @"";
  213. imageName = @"";
  214. } else {
  215. [cell setUserInteractionEnabled:YES];
  216. NSInteger cellTag = [dataArray[indexPath.row] integerValue];
  217. titleName = [NSString stringWithFormat:@"%@.%ld.%ld", titleKey, (long)indexPath.section, (long)cellTag];
  218. NSString* temp = indexPath.section == 0 ? @"watch_banner" : imageKey;
  219. imageName = [NSString stringWithFormat:@"%@_%ld_%ld",temp, (long)indexPath.section, (long)cellTag];
  220. }
  221. [cell.mIconImage setImage:imageName.length > 0 ? [UIImage imageNamed:imageName] : nil];
  222. [cell.mIconLabel setText:NSLocalizedString(titleName, nil)];
  223. [cell.mIconView setHidden:NO];
  224. return cell;
  225. }
  226. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  227. //获取CellTag
  228. NSString* key = [NSString stringWithFormat:@"%ld", indexPath.section];
  229. NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
  230. NSArray* dataArray = array[0];
  231. NSInteger cellTag = [dataArray[indexPath.row] integerValue];
  232. HDNormalLog(([NSString stringWithFormat:@"WatchViewController click %ld-%ld", (long)indexPath.section, (long)cellTag]));
  233. BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
  234. if (isRole) {
  235. switch (indexPath.section) {
  236. case 0: {
  237. switch (cellTag) {
  238. case 0:
  239. [self showMagicAcademy];
  240. break;
  241. case 1:
  242. [self showFlowerTask];
  243. break;
  244. case 2:
  245. [self showStepCount];
  246. break;
  247. case 3:
  248. break;
  249. default:
  250. break;
  251. }
  252. break;
  253. }
  254. case 1: {
  255. switch (cellTag) {
  256. case 0:
  257. [self showHistoryPath];
  258. break;
  259. case 1:
  260. [self showFence];
  261. break;
  262. case 2:
  263. [self showSchoolTime];
  264. break;
  265. case 3:
  266. [self showAlarmClock];
  267. break;
  268. case 4:
  269. [self showEventReminder];
  270. break;
  271. default:
  272. break;
  273. }
  274. break;
  275. }
  276. case 2: {
  277. switch (cellTag) {
  278. case 0:
  279. [self showWifi];
  280. break;
  281. case 1:
  282. [self showOnOffSetting];
  283. break;
  284. case 2:
  285. [self showElectricityMode];
  286. break;
  287. case 3:
  288. [self showEyeCare];
  289. break;
  290. case 4:
  291. [self showFlowControl];
  292. break;
  293. case 5:
  294. [self showWatchUpdate];
  295. break;
  296. case 6:
  297. [self showFactoryInfo];
  298. break;
  299. case 7:
  300. [self showMessageCenter];
  301. break;
  302. case 8:
  303. [self showWatchFlag];
  304. break;
  305. case 9:
  306. [self showFunction];
  307. break;
  308. default:
  309. break;
  310. }
  311. break;
  312. }
  313. case 3: {
  314. switch (cellTag) {
  315. case 0:
  316. [self showContact];
  317. break;
  318. case 1:
  319. [self showCallCharge];
  320. break;
  321. case 2:
  322. [self showCollectSMS];
  323. break;
  324. case 3:
  325. [self showStranger];
  326. break;
  327. case 4:
  328. [self showCallRecord];
  329. break;
  330. default:
  331. break;
  332. }
  333. break;
  334. }
  335. default:
  336. break;
  337. }
  338. }
  339. else {
  340. switch (indexPath.section) {
  341. case 0: {
  342. switch (cellTag) {
  343. case 0:
  344. [self showMagicAcademy];
  345. break;
  346. case 1:
  347. [self showFlowerTask];
  348. break;
  349. case 2:
  350. [self showStepCount];
  351. break;
  352. case 3:
  353. break;
  354. default:
  355. break;
  356. }
  357. break;
  358. }
  359. case 1: {
  360. switch (cellTag) {
  361. case 0:
  362. [self showContact];
  363. break;
  364. case 1:
  365. [self showCallCharge];
  366. break;
  367. case 2:
  368. [self showHistoryPath];
  369. break;
  370. case 3:
  371. [self showFactoryInfo];
  372. break;
  373. case 4:
  374. [self showWifi];
  375. break;
  376. default:
  377. break;
  378. }
  379. break;
  380. }
  381. default:
  382. break;
  383. }
  384. }
  385. }
  386. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
  387. viewController.hidesBottomBarWhenPushed = YES;
  388. [self.navigationController pushViewController:viewController animated:animated];
  389. }
  390. - (void)showMagicAcademy {
  391. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"MagicAcademyVC"];
  392. [self pushViewController:controller animated:YES];
  393. }
  394. - (void)showStepCount {
  395. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"HealthWalkVC"];
  396. [self pushViewController:controller animated:YES];
  397. }
  398. - (void)showFlowerTask {
  399. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"RedFlowerTaskVC"];
  400. [self pushViewController:controller animated:YES];
  401. }
  402. - (void)showContact {
  403. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ContactListViewID"];
  404. [self pushViewController:controller animated:YES];
  405. }
  406. - (void)showCollectSMS {
  407. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchSMSVC"];
  408. [self pushViewController:controller animated:YES];
  409. }
  410. - (void)showStranger {
  411. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"StrangerInterceptVC"];
  412. [self pushViewController:controller animated:YES];
  413. }
  414. - (void)showCallCharge {
  415. // [MobClick event:@"ClickCallCharge"];
  416. // UIViewController *controller = [[CallChargeViewController alloc]init];
  417. // [self pushViewController:controller animated:YES];
  418. }
  419. - (void)showCallRecord {
  420. [MobClick event:@"ClickCallRecordFromHistory"];
  421. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ZSCallRecordVC"];
  422. [self pushViewController:controller animated:YES];
  423. }
  424. - (void)showHistoryPath {
  425. UIViewController *mHistoryPathView = [[self storyboard] instantiateViewControllerWithIdentifier:@"HistoryPathVC"];
  426. [self pushViewController:mHistoryPathView animated:YES];
  427. }
  428. - (void)showFence {
  429. SKFenceListViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FenceListVC"];
  430. controller.refreshType = [NSNumber numberWithInt:0];
  431. [self pushViewController:controller animated:YES];
  432. }
  433. - (void)showSchoolTime {
  434. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"SchoolTimeListVC"];
  435. [self pushViewController:controller animated:YES];
  436. }
  437. - (void)showAlarmClock {
  438. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"AlarmClockListVC"];
  439. [self pushViewController:controller animated:YES];
  440. }
  441. - (void)showEventReminder {
  442. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"EventReminderVC"];
  443. [self pushViewController:controller animated:YES];
  444. }
  445. - (void)showWifi {
  446. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WifiListVC"];
  447. [self pushViewController:controller animated:YES];
  448. }
  449. - (void)showFlowControl {
  450. SKFlowControlViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FlowControlVC"];
  451. [self pushViewController:controller animated:YES];
  452. }
  453. - (void)showEyeCare {
  454. SKEyeCareViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"EyeCareVC"];
  455. //controller.delegate = self;
  456. controller.mSwitchFlag = 0;
  457. controller.mStartTime = @"20:00";
  458. controller.mEndTime = @"05:00";
  459. [self pushViewController:controller animated:YES];
  460. }
  461. - (void)showElectricityMode {
  462. SKElectricityModeViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ZSElectricityModeVC"];
  463. controller.m_iElectricityMode = 0;
  464. //controller.modeDelegate = self;
  465. [self pushViewController:controller animated:YES];
  466. }
  467. - (void)showOnOffSetting {
  468. SKOnOffSettingViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"OnOffSettingVC"];
  469. //controller.delegate = self;
  470. controller.mSwitchFlag = 0;
  471. controller.mOnTime = @"";
  472. controller.mOffTime = @"";
  473. [self pushViewController:controller animated:YES];
  474. }
  475. - (void)showWatchUpdate {
  476. WatchUpdateViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchUpdateVC"];
  477. controller.mAotuUpdate = 0;
  478. [self pushViewController:controller animated:YES];
  479. }
  480. - (void)showFactoryInfo {
  481. SKFactoryInfoViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FactoryInfoVC"];
  482. controller.mIMEI = @"";
  483. controller.mVersion = @"";
  484. [self pushViewController:controller animated:YES];
  485. }
  486. - (void)showPushFlag {
  487. SKPushFlagViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"PushFlagVC"];
  488. controller.mFlag = 0;
  489. [self pushViewController:controller animated:YES];
  490. }
  491. - (void)showMessageCenter {
  492. SKMessageCenterViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"MessageCenterVC"];
  493. controller.mFlag = 0;
  494. [self pushViewController:controller animated:YES];
  495. }
  496. - (void)showWatchFlag {
  497. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchFlagVC"];
  498. [self pushViewController:controller animated:YES];
  499. }
  500. - (void)showFunction {
  501. UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FunctionVC"];
  502. [self pushViewController:controller animated:YES];
  503. }
  504. @end