123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- //
- // WatchViewController.m
- // SikeyComm
- //
- // Created by 振兴 刘 on 2017/11/28.
- // Copyright © 2017年 BaH Cy. All rights reserved.
- //
- #import "SKWatchViewController.h"
- #import "SKWatchViewCell.h"
- #import "WatchHeaderReusableView.h"
- #import "EDefines.h"
- #import <UMMobClick/MobClick.h>
- #import "WatchSMSViewController.h"
- #import "SKStrangerInterceptViewController.h"
- #import "SKFlowControlViewController.h"
- #import "SKElectricityModeViewController.h"
- #import "SKOnOffSettingViewController.h"
- #import "SKFactoryInfoViewController.h"
- #import "SKEyeCareViewController.h"
- #import "SKPushFlagViewController.h"
- #import "SKMessageCenterViewController.h"
- #import "WatchUpdateViewController.h"
- #import "SKChildListView.h"
- #define CELL_MARGIN 12
- @interface SKWatchViewController ()<UICollectionViewDelegateFlowLayout> {
- NSMutableDictionary* mFunctionDic;
- }
- @end
- @implementation SKWatchViewController
- static NSString * const CellReuseIdentifier = @"WatchCellID";
- static NSString * const HeaderReuseIdentifier = @"WatchHeaderID";
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self.navigationController setNavigationBarHidden:YES];
- [self addNavigationView];
- [self.mNavigationView refreshChildView];
-
- self.mCollectionView.alwaysBounceVertical = YES;
- [self.mCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([WatchHeaderReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderReuseIdentifier];
-
- [self refreshPermissionsMask];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES];
- [self initView];
- }
- - (void)onChangeChild:(NSInteger)index {
- [self.mNavigationView refreshChildView];
- [self initView];
- }
- - (void)initView {
- [mFunctionDic removeAllObjects];
- mFunctionDic = [NSMutableDictionary new];
- [self initFunction];
- [self.mCollectionView reloadData];
- }
- - (void)initFunction {
- ChildModel* childModel = [DataManager shared].mSelectChildModel;
- DeviceModel* model = childModel.device;
- BOOL isRole = childModel.role <= ROLE_ADMIN;
- if (!isRole) {
- NSMutableArray* firstArray = NSMutableArray.new;
- if (model.match.magicAcademy)
- [firstArray addObject:@(0)];
- if (model.match.redFlower)
- [firstArray addObject:@(1)];
- //[firstArray addObject:@(2)]; //此界面不显示计步
- mFunctionDic[@"0"] = firstArray;
-
- NSMutableArray* secondArray = NSMutableArray.new;
- [secondArray addObject:@(0)];
- if (model.match.callCharge) //国外版本不支持//
- [secondArray addObject:@(1)];
- [secondArray addObject:@(2)];
- [secondArray addObject:@(3)];
- if (model.match.wifi)
- [secondArray addObject:@(4)];
- mFunctionDic[@"1"] = secondArray;
- } else {
- NSMutableArray* firstArray = NSMutableArray.new;
- if (model.match.magicAcademy)
- [firstArray addObject:@(0)];
- if (model.match.redFlower)
- [firstArray addObject:@(1)];
- //[firstArray addObject:@(2)]; //此界面不显示计步
- mFunctionDic[@"0"] = firstArray;
-
- NSMutableArray* thirdArray = NSMutableArray.new;
- [thirdArray addObject:@(0)];
- [thirdArray addObject:@(1)];
- [thirdArray addObject:@(2)];
- if (model.match.clock)
- [thirdArray addObject:@(3)];
- if (model.match.eventReminder)
- [thirdArray addObject:@(4)];
- mFunctionDic[@"1"] = thirdArray;
-
- NSMutableArray* fourArray = NSMutableArray.new;
- if (model.match.wifi)
- [fourArray addObject:@(0)];
- if ([model isBind])
- [fourArray addObject:@(1)];
- if (model.match.electricityMode)
- [fourArray addObject:@(2)];
- if (model.match.eyeCare)
- [fourArray addObject:@(3)];
- if (model.match.flowControl)
- [fourArray addObject:@(4)];
- if ([model isBind] && model.match.update)
- [fourArray addObject:@(5)];
- if ([model isBind])
- [fourArray addObject:@(6)];
- //[fourArray addObject:@(7)];
- if([model isBind] && (model.match.autoLocation || model.match.apn))
- [fourArray addObject:@(8)];
- if ([model isBind] && model.match.function)
- [fourArray addObject:@(9)];
- mFunctionDic[@"2"] = fourArray;
-
- NSMutableArray* secondArray = NSMutableArray.new;
- [secondArray addObject:@(0)];
- if (model.match.callCharge) //国外版本不支持//
- [secondArray addObject:@(1)];
- if (model.match.watchSMS)
- [secondArray addObject:@(2)];
- if (model.match.strangerIntercept)
- [secondArray addObject:@(3)];
- if (model.match.callRecord)
- [secondArray addObject:@(4)];
- mFunctionDic[@"3"] = secondArray;
- }
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- ChildModel* model = [DataManager shared].mSelectChildModel;
- BOOL isRole = model.role <= ROLE_ADMIN;
- return isRole ? ([model.device isBind] ? 4:3) : 2;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- NSString* key = [NSString stringWithFormat:@"%ld", section];
- NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
- NSArray* dataArray = array[0];
- return (dataArray.count-1)/4 * 4 + 4;
- }
- // 表头尺寸
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return CGSizeMake(SCREEN_WIDTH, 10);
- }
- else {
- BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
- if (isRole)
- return CGSizeMake(SCREEN_WIDTH, 34);
- else
- return CGSizeMake(SCREEN_WIDTH, 15);
- }
- }
- // 显示表头的数据
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- if (kind == UICollectionElementKindSectionHeader) {
- BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
- if (isRole) {
- WatchHeaderReusableView *reusableView = [self.mCollectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
- if(reusableView == nil)
- reusableView = [[WatchHeaderReusableView alloc] init];
- NSString* key = [NSString stringWithFormat:@"%@.%ld", @"Watch.Admin.Section", (long)indexPath.section];
- reusableView.mHeaderTitle.text = NSLocalizedString(key, nil);
-
- if (indexPath.section == 0) {
- [reusableView.mHeaderView setHidden:YES];
- [reusableView.mWhiteView setHidden:YES];
- }
- else {
- [reusableView.mHeaderView setHidden:indexPath.section == 0];
- [reusableView.mWhiteView setHidden:indexPath.section != 0];
- }
-
- return reusableView;
- }
- else {
- WatchHeaderReusableView *reusableView = [self.mCollectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderReuseIdentifier forIndexPath:indexPath];
- if(reusableView == nil)
- reusableView = [[WatchHeaderReusableView alloc] init];
- [reusableView.mHeaderView setHidden:YES];
- [reusableView.mWhiteView setHidden:YES];
- return reusableView;
- }
- }
- return nil;
- }
- //设置每个子视图的缩进
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- //设置子视图上下之间的距离
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
- return 0;
- }
- //设置子视图左右之间的距离
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
- return 0;
- }
- //返回每个子视图的大小
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
- CGFloat itemWidth = SCREEN_WIDTH / 4 ;
- return CGSizeMake(itemWidth, 110);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- SKWatchViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
- BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
-
- NSString* titleName = @"";
- NSString* imageName = @"";
- NSString* titleKey = isRole ? @"Watch.Admin" : @"Watch.NotAdmin";
- NSString* imageKey = isRole ? @"watch_icon" : @"watch_icon_notadmin";
-
- NSString* key = [NSString stringWithFormat:@"%ld", indexPath.section];
- NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
- NSArray* dataArray = array[0];
- if (indexPath.row >= dataArray.count) {
- [cell setUserInteractionEnabled:NO];
- titleName = @"";
- imageName = @"";
- } else {
- [cell setUserInteractionEnabled:YES];
- NSInteger cellTag = [dataArray[indexPath.row] integerValue];
- titleName = [NSString stringWithFormat:@"%@.%ld.%ld", titleKey, (long)indexPath.section, (long)cellTag];
- NSString* temp = indexPath.section == 0 ? @"watch_banner" : imageKey;
- imageName = [NSString stringWithFormat:@"%@_%ld_%ld",temp, (long)indexPath.section, (long)cellTag];
- }
- [cell.mIconImage setImage:imageName.length > 0 ? [UIImage imageNamed:imageName] : nil];
- [cell.mIconLabel setText:NSLocalizedString(titleName, nil)];
- [cell.mIconView setHidden:NO];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- //获取CellTag
- NSString* key = [NSString stringWithFormat:@"%ld", indexPath.section];
- NSArray* array = [NSArray arrayWithObject:mFunctionDic[key]];
- NSArray* dataArray = array[0];
- NSInteger cellTag = [dataArray[indexPath.row] integerValue];
- HDNormalLog(([NSString stringWithFormat:@"WatchViewController click %ld-%ld", (long)indexPath.section, (long)cellTag]));
-
- BOOL isRole = [DataManager shared].mSelectChildModel.role <= ROLE_ADMIN;
- if (isRole) {
- switch (indexPath.section) {
- case 0: {
- switch (cellTag) {
- case 0:
- [self showMagicAcademy];
- break;
- case 1:
- [self showFlowerTask];
- break;
- case 2:
- [self showStepCount];
- break;
- case 3:
- break;
- default:
- break;
- }
- break;
- }
- case 1: {
-
- switch (cellTag) {
- case 0:
- [self showHistoryPath];
- break;
- case 1:
- [self showFence];
- break;
- case 2:
- [self showSchoolTime];
- break;
- case 3:
- [self showAlarmClock];
- break;
- case 4:
- [self showEventReminder];
- break;
- default:
- break;
- }
- break;
- }
- case 2: {
- switch (cellTag) {
- case 0:
- [self showWifi];
- break;
- case 1:
- [self showOnOffSetting];
- break;
- case 2:
- [self showElectricityMode];
- break;
- case 3:
- [self showEyeCare];
- break;
- case 4:
- [self showFlowControl];
- break;
- case 5:
- [self showWatchUpdate];
- break;
- case 6:
- [self showFactoryInfo];
- break;
- case 7:
- [self showMessageCenter];
- break;
- case 8:
- [self showWatchFlag];
- break;
- case 9:
- [self showFunction];
- break;
- default:
- break;
- }
- break;
- }
- case 3: {
- switch (cellTag) {
- case 0:
- [self showContact];
- break;
- case 1:
- [self showCallCharge];
- break;
- case 2:
- [self showCollectSMS];
- break;
- case 3:
- [self showStranger];
- break;
- case 4:
- [self showCallRecord];
- break;
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- else {
- switch (indexPath.section) {
- case 0: {
- switch (cellTag) {
- case 0:
- [self showMagicAcademy];
- break;
- case 1:
- [self showFlowerTask];
- break;
- case 2:
- [self showStepCount];
- break;
- case 3:
- break;
- default:
- break;
- }
- break;
- }
- case 1: {
- switch (cellTag) {
- case 0:
- [self showContact];
- break;
- case 1:
- [self showCallCharge];
- break;
- case 2:
- [self showHistoryPath];
- break;
- case 3:
- [self showFactoryInfo];
- break;
- case 4:
- [self showWifi];
- break;
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- }
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
- viewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:viewController animated:animated];
- }
- - (void)showMagicAcademy {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"MagicAcademyVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showStepCount {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"HealthWalkVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showFlowerTask {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"RedFlowerTaskVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showContact {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ContactListViewID"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showCollectSMS {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchSMSVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showStranger {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"StrangerInterceptVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showCallCharge {
- // [MobClick event:@"ClickCallCharge"];
- // UIViewController *controller = [[CallChargeViewController alloc]init];
- // [self pushViewController:controller animated:YES];
- }
- - (void)showCallRecord {
- [MobClick event:@"ClickCallRecordFromHistory"];
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ZSCallRecordVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showHistoryPath {
- UIViewController *mHistoryPathView = [[self storyboard] instantiateViewControllerWithIdentifier:@"HistoryPathVC"];
- [self pushViewController:mHistoryPathView animated:YES];
- }
- - (void)showFence {
- SKFenceListViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FenceListVC"];
- controller.refreshType = [NSNumber numberWithInt:0];
- [self pushViewController:controller animated:YES];
- }
- - (void)showSchoolTime {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"SchoolTimeListVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showAlarmClock {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"AlarmClockListVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showEventReminder {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"EventReminderVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showWifi {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WifiListVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showFlowControl {
- SKFlowControlViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FlowControlVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showEyeCare {
- SKEyeCareViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"EyeCareVC"];
- //controller.delegate = self;
- controller.mSwitchFlag = 0;
- controller.mStartTime = @"20:00";
- controller.mEndTime = @"05:00";
- [self pushViewController:controller animated:YES];
- }
- - (void)showElectricityMode {
- SKElectricityModeViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"ZSElectricityModeVC"];
- controller.m_iElectricityMode = 0;
- //controller.modeDelegate = self;
- [self pushViewController:controller animated:YES];
- }
- - (void)showOnOffSetting {
- SKOnOffSettingViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"OnOffSettingVC"];
- //controller.delegate = self;
- controller.mSwitchFlag = 0;
- controller.mOnTime = @"";
- controller.mOffTime = @"";
- [self pushViewController:controller animated:YES];
- }
- - (void)showWatchUpdate {
- WatchUpdateViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchUpdateVC"];
- controller.mAotuUpdate = 0;
- [self pushViewController:controller animated:YES];
- }
- - (void)showFactoryInfo {
- SKFactoryInfoViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FactoryInfoVC"];
- controller.mIMEI = @"";
- controller.mVersion = @"";
- [self pushViewController:controller animated:YES];
- }
- - (void)showPushFlag {
- SKPushFlagViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"PushFlagVC"];
- controller.mFlag = 0;
- [self pushViewController:controller animated:YES];
- }
- - (void)showMessageCenter {
- SKMessageCenterViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"MessageCenterVC"];
- controller.mFlag = 0;
- [self pushViewController:controller animated:YES];
- }
- - (void)showWatchFlag {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"WatchFlagVC"];
- [self pushViewController:controller animated:YES];
- }
- - (void)showFunction {
- UIViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FunctionVC"];
- [self pushViewController:controller animated:YES];
- }
- @end
|