// // settingListController.m // ThePaperHD // // Created by scar1900 on 15/3/24. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "settingListController.h" #import "settingListCell.h" #import "AppDelegate.h" #import "feedbackController.h" #import "aboutPaperController.h" #import "MLNavigationController.h" #import "Util.h" #include #include #import "KGModal.h" @interface settingListController (){ BOOL isOpen; } @property(nonatomic, strong)UIButton *closeBtn; @property(nonatomic, strong)UILabel *titleLabel; @end @implementation settingListController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor clearColor]; [self.view addSubview:self.closeBtn]; [self.view addSubview:self.titleLabel]; self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.scrollEnabled = NO; //【需求】iOS推送设置优化iPad(bug:5937) if(isIOS8 || isIOS9){ UIUserNotificationSettings *set = [[UIApplication sharedApplication] currentUserNotificationSettings]; if (UIUserNotificationTypeNone == set.types) { isOpen = NO; }else{ isOpen = YES; } }else{ isOpen = YES; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = YES; [KGModal sharedInstance].tapOutsideToDismiss = YES; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.closeBtn.frame = CGRectMake(0, 0, 50, 80); self.titleLabel.frame = CGRectMake(50, 0, CGRectGetWidth(self.view.bounds)-100, 80); self.tableView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), CGRectGetWidth(self.view.bounds), settingPopSize.height-80); [self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; } - (UIButton*)closeBtn { if (!_closeBtn) { _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setImage:Image(@"login/popUpCloseBtn.png") forState:UIControlStateNormal]; [_closeBtn setImage:Image(@"login/popUpCloseBtn_s.png") forState:UIControlStateHighlighted]; [_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.text = @"设置"; _titleLabel.textColor = [UIColor whiteColor]; _titleLabel.font = appFont(30, NO); } return _titleLabel; } - (void)closeEvent:(UIButton*)btn { [self dismissControllerAnimated:YES completion:nil]; } #pragma mark - tableview deleagte and datasource #pragma mark UITableViewDelegate and UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (0 == section) { return 1; }else{ return 4; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if(0==indexPath.section){ if (isOpen) {//【需求】iOS推送设置优化iPad(bug:5937) return 55; }else{ return 120; } }else{ return 55; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (0 == section) { return 0; }else{ return 30; } } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *footView = [[UIView alloc]init]; if (1 == section) { UILabel *versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 -50, 20, 100, 20)]; versionLabel.textColor = [UIColor colorWithHexString:TextLightGray]; versionLabel.font = appFont(14, NO); versionLabel.backgroundColor = [UIColor clearColor]; versionLabel.text = [NSString stringWithFormat:@"当前版本%@",[TPUserDefault instance].appVersion]; [footView addSubview:versionLabel]; } return footView; } - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* settingListID = @"settingListCellID"; settingListCell* cell = (settingListCell*)[table dequeueReusableCellWithIdentifier:settingListID]; if (nil == cell) { cell = [[settingListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settingListID]; } cell.indexPath = indexPath; cell.settingListCellDelegate = self; if (indexPath.section == 1&& indexPath.row == 3) { if ([[TPUserDefault instance].clearStatus intValue] == 1) { cell.isShowClearStatus = YES; }else { cell.isShowClearStatus = NO; } } cell.isPushOpen = isOpen; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if(1== indexPath.section){ if (0 == indexPath.row) { [MobClick event:@"45"];//【需求】统计-iPad(BUG:4358) NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8",@"986646876" ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; }else if (1== indexPath.row) { feedbackController *feedVC = feedbackController.new; [(MLNavigationController*)self.navigationController pushViewControllerWithAnimateFlip:feedVC]; }else if (2 == indexPath.row){ aboutPaperController *aboutVC = [[aboutPaperController alloc] init]; [(MLNavigationController*)self.navigationController pushViewControllerWithAnimateFlip:aboutVC]; }else if (3 == indexPath.row){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"确定要清除所有缓存文件吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; [alert show]; } } }); } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != 0) { [[TPUserDefault instance] clearCache:self]; [MobClick event:@"18"]; } } - (void)updateCacheText:(NSString*)clearStatus { // [self.tableView reloadData]; settingListCell *cell = (settingListCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:1]]; if ([clearStatus intValue] == 1) { cell.isShowClearStatus = YES; }else { cell.isShowClearStatus = NO; dispatch_async(dispatch_get_main_queue(), ^{ ShowMessage(@"清理成功", YES); }); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (float) folderSizeAtPath:(NSString*) folderPath { long long folderSize = [Util folderSizeAtPath3:folderPath]; float folderMBSize = folderSize/(1024.0*1024.0); return folderMBSize; } -(void)gotoNightMode:(BOOL)isGoto{//夜间模式 if (isGoto) { [TPUserDefault instance].isNightMode = @"1"; [UIView animateWithDuration:0.3 animations:^{ [self.tableView reloadData]; TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow]; [window setMaskAfterOpenNightMode]; } completion:^(BOOL finished) { [MobClick event:@"44"]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERNIGHTMODE object:nil]; }]; }else { [TPUserDefault instance].isNightMode = @"0"; [UIView animateWithDuration:0.3 animations:^{ [self.tableView reloadData]; TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow]; [window setNoNightModeMask]; } completion:^(BOOL finished) { [MobClick event:@"44"]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERNIGHTMODE object:nil]; }]; } self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end