From 1d39caf7235522ae121db7a188ba41a706217407 Mon Sep 17 00:00:00 2001 From: 单军华 <WindShan@danjunhuas-MacBook-Pro.local> Date: Sat, 28 Apr 2018 09:39:49 +0800 Subject: [PATCH] 清理多余代码,优化 --- pregnancy_guard/BaseProject/Controller/Home/MinePage.m | 374 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 244 insertions(+), 130 deletions(-) diff --git a/pregnancy_guard/BaseProject/Controller/Home/MinePage.m b/pregnancy_guard/BaseProject/Controller/Home/MinePage.m index cb7771e..8bb5efd 100644 --- a/pregnancy_guard/BaseProject/Controller/Home/MinePage.m +++ b/pregnancy_guard/BaseProject/Controller/Home/MinePage.m @@ -7,7 +7,6 @@ // #import "MinePage.h" -#import "ChangeNamePage.h" #import "ChangePwdPage.h" #import "cameraHelper.h" #import "BaseNaviController.h" @@ -16,18 +15,170 @@ #import "MBProgressHUD+Add.h" #import "LoginPage.h" #import "GloriaLabel.h" +#import "XZPickView.h" +#import "MusicSetPage.h" -@interface MinePage () +@interface MinePage ()<XZPickViewDelegate, XZPickViewDataSource> { UISwitch *switchButton; + GloriaLabel* _TitleLabel; + GloriaLabel* _SulvLabel; + GloriaLabel* _IsUpLoadLabel; + GloriaLabel* _MusicLabel; + UIImageView * icon_refresh; + UIImageView * icon_data; + UIImageView * icon_police; } @property(nonatomic,strong) UITableView * tableView; @property (nonatomic, strong) NSMutableArray *dataArray; +@property (nonatomic,strong) XZPickView * pickView; + +@property (nonatomic,copy) NSDictionary * dateDic; +@property (nonatomic,strong) NSString * is_open_upload; +@property (nonatomic,strong) NSString * weekStr; +@property (nonatomic, strong) NSDate *selectDate; +@property (nonatomic, assign) NSInteger currentSelectDay; @end @implementation MinePage + +// ������������������ +-(void)pickView:(XZPickView *)pickerView confirmButtonClick:(UIButton *)button{ + + NSInteger left = [pickerView selectedRowInComponent:0]; + self.selectDate = [self.dateDic[@"week"] objectAtIndex:left]; + self.weekStr = self.dateDic[@"week"][left]; + self.weekStr = [self.weekStr substringWithRange:NSMakeRange(0,[self.weekStr length]-1)]; + [self update_refresh_frequency]; +} + +-(void)update_refresh_frequency +{ + //[UserDefault stringForKey:@"user_id"] + NSString *path = [[NSString alloc] initWithFormat:UPDATE_USERINFO]; + + NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; + + //['refresh_frequency', 'video', 'is_open_upload'] + [param setValue:[UserDefault stringForKey:@"user_id"] forKey:@"user_id"]; + [param setValue:@"refresh_frequency" forKey:@"field"]; + [param setValue:self.weekStr forKey:@"value"]; + + MPWeakSelf(self); + [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody) + { + MPStrongSelf(self); + BaseResModel * resModel = [Global toBaseModel:responseBody]; + + if(resModel.code == 0) + { + [UserDefault setObject:self.weekStr forKey:@"refresh_frequency"]; + [UserDefault synchronize]; + + [self.tableView reloadData]; + [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } + else + { + [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } + } + failure:^(NSString *error) + { + + [Global alertMessageEx:error title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + }]; +} + +-(void)update_is_open_upload +{ + //[UserDefault stringForKey:@"user_id"] + NSString *path = [[NSString alloc] initWithFormat:UPDATE_USERINFO]; + + NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; + + //['refresh_frequency', 'video', 'is_open_upload'] + [param setValue:[UserDefault stringForKey:@"user_id"] forKey:@"user_id"]; + [param setValue:@"is_open_upload" forKey:@"field"]; // 1 ������ 0 ������ + [param setValue:self.is_open_upload forKey:@"value"]; + + MPWeakSelf(self); + [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody) + { + MPStrongSelf(self); + BaseResModel * resModel = [Global toBaseModel:responseBody]; + + if(resModel.code == 0) + { + [UserDefault setObject:self.is_open_upload forKey:@"is_open_upload"]; + [UserDefault synchronize]; + + [self.tableView reloadData]; + [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } + else + { + [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + } + } + failure:^(NSString *error) + { + + [Global alertMessageEx:error title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + }]; +} + +-(NSInteger)pickerView:(XZPickView *)pickerView numberOfRowsInComponent:(NSInteger)component{ + + //������ + return [self.dateDic[@"week"] count]; +} + +-(void)pickerView:(XZPickView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component +{ + self.currentSelectDay = [pickerView selectedRowInComponent:0]; + //[pickerView pickReloadComponent:1]; + self.weekStr = self.dateDic[@"week"][row]; + +} + +-(NSString *)pickerView:(XZPickView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component +{ + return self.dateDic[@"week"][row]; +} + +-(NSInteger)numberOfComponentsInPickerView:(XZPickView *)pickerView{ + return 1; +} + +#pragma mark - + + +- (NSDictionary *)LHGetStartTime +{ + NSMutableArray *weekStrArr = [NSMutableArray array]; + [weekStrArr addObject:@"10���"]; + [weekStrArr addObject:@"20���"]; + [weekStrArr addObject:@"30���"]; + NSDictionary *resultDic = @{@"week" : weekStrArr}; + return resultDic; +} + + +#pragma mark - getter methods + +-(XZPickView *)pickView +{ + if(!_pickView){ + _pickView = [[XZPickView alloc]initWithFrame:kScreenBounds title:@"���������"]; + _pickView.delegate = self; + _pickView.dataSource = self; + } + return _pickView; +} + - (UITableView *)tableView { @@ -68,6 +219,9 @@ self.navigationItem.title = @"������"; self.tableView.hidden = NO; + + + } @@ -75,31 +229,6 @@ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - -//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; -//{ -// return 50; -//} -// -//- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; // custom view for header. will be adjusted to default or specified header height -//{ -// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)]; -// -// view.backgroundColor = [UIColor clearColor]; -// -//// UIButton *quitLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; -//// quitLoginBtn.frame =CGRectMake(30, 50, SCREEN_WIDTH-60, 40); -//// [quitLoginBtn.layer setMasksToBounds:YES]; -//// [quitLoginBtn.layer setCornerRadius:5.0]; //������������������������������ -//// quitLoginBtn.backgroundColor = RgbColor(84, 76, 155);/////��������������������� -//// [quitLoginBtn setTitle:@"������������������" forState:UIControlStateNormal]; -//// quitLoginBtn.userInteractionEnabled = YES; -//// [quitLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; -//// [quitLoginBtn addTarget:self action:@selector(exitLoginAction) forControlEvents:UIControlEventTouchUpInside]; -//// [view addSubview:quitLoginBtn]; -// -// return view; -//} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { @@ -153,74 +282,86 @@ { case 0: { - UIImageView * icon_refresh = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; - icon_refresh.image = [UIImage imageNamed:@"icon_refresh"]; - [cell.contentView addSubview:icon_refresh]; + if(icon_refresh==nil) + { + icon_refresh = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; + icon_refresh.image = [UIImage imageNamed:@"icon_refresh"]; + [cell.contentView addSubview:icon_refresh]; + } - GloriaLabel* _TitleLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)]; - _TitleLabel.font = [UIFont systemFontOfSize:14]; - _TitleLabel.textAlignment = UITextAlignmentLeft; - _TitleLabel.textColor = kUIColorFromRGB(0x595959); - _TitleLabel.text = @"������������"; - [cell.contentView addSubview:_TitleLabel]; + if(_TitleLabel == nil) + { + _TitleLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)]; + _TitleLabel.font = [UIFont systemFontOfSize:14]; + _TitleLabel.textAlignment = UITextAlignmentLeft; + _TitleLabel.textColor = kUIColorFromRGB(0x595959); + _TitleLabel.text = @"������������"; + [cell.contentView addSubview:_TitleLabel]; + } + - UITextField*userPhoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40-110, 8, 110, 44)]; - userPhoneTextField.font = [UIFont fontWithName:@"Arial" size:14]; - userPhoneTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"���������������������"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}]; - userPhoneTextField.delegate = self; - [userPhoneTextField setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"]; - //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; - userPhoneTextField.textColor = RgbColor(149, 149, 150); - userPhoneTextField.keyboardType = UIKeyboardTypeNumberPad; - userPhoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - // ������������������blankView���15.0������������View���������width��������������������������������������������������������������� - UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(userPhoneTextField.frame.origin.x,userPhoneTextField.frame.origin.y,10.0, userPhoneTextField.frame.size.height)]; - userPhoneTextField.leftView = blankView; - userPhoneTextField.leftViewMode =UITextFieldViewModeAlways; - [cell.contentView addSubview:userPhoneTextField]; + if(_SulvLabel == nil) + { + _SulvLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 15,SCREEN_WIDTH/2, 30)]; + _SulvLabel.font = [UIFont systemFontOfSize:14]; + _SulvLabel.textAlignment = UITextAlignmentLeft; + _SulvLabel.textColor = kUIColorFromRGB(0x595959); + [cell.contentView addSubview:_SulvLabel]; + } - GloriaLabel* _MiaoLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40, 15,20, 30)]; - _MiaoLabel.font = [UIFont systemFontOfSize:14]; - _MiaoLabel.textAlignment = UITextAlignmentLeft; - _MiaoLabel.textColor = kUIColorFromRGB(0x595959); - _MiaoLabel.text = @"���"; - [cell.contentView addSubview:_MiaoLabel]; + _SulvLabel.text = [NSString stringWithFormat:@"%@���",[UserDefault stringForKey:@"refresh_frequency"]]; } break; case 1: { - UIImageView * icon_data = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; - icon_data.image = [UIImage imageNamed:@"icon_data"]; - [cell.contentView addSubview:icon_data]; + if(icon_data==nil) + { + icon_data = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; + icon_data.image = [UIImage imageNamed:@"icon_data"]; + [cell.contentView addSubview:icon_data]; + } + - GloriaLabel* _TitleLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)]; - _TitleLabel.font = [UIFont systemFontOfSize:14]; - _TitleLabel.textAlignment = UITextAlignmentLeft; - _TitleLabel.textColor = kUIColorFromRGB(0x595959); - _TitleLabel.text = @"������������������"; - [cell.contentView addSubview:_TitleLabel]; - - switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 15, 20, 10)]; - [switchButton setOn:YES]; - [switchButton addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventValueChanged]; - [cell.contentView addSubview:switchButton]; - + if(_IsUpLoadLabel==nil) + { + _IsUpLoadLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50, 15,SCREEN_WIDTH/2, 30)]; + _IsUpLoadLabel.font = [UIFont systemFontOfSize:14]; + _IsUpLoadLabel.textAlignment = UITextAlignmentLeft; + _IsUpLoadLabel.textColor = kUIColorFromRGB(0x595959); + _IsUpLoadLabel.text = @"������������������"; + [cell.contentView addSubview:_IsUpLoadLabel]; + } + + if(switchButton == nil) + { + switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 15, 20, 10)]; + [switchButton setOn:[[UserDefault stringForKey:@"is_open_upload"] intValue] == 1? YES:NO]; + [switchButton addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventValueChanged]; + [cell.contentView addSubview:switchButton]; + } } break; case 2: { - UIImageView * icon_police = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; - icon_police.image = [UIImage imageNamed:@"icon_police"]; - [cell.contentView addSubview:icon_police]; + if(icon_police==nil) + { + icon_police = [[UIImageView alloc] initWithFrame:CGRectMake(20, 22, 15, 15)]; + icon_police.image = [UIImage imageNamed:@"icon_police"]; + [cell.contentView addSubview:icon_police]; + } - GloriaLabel* _TitleLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50,15,SCREEN_WIDTH/2, 30)]; - _TitleLabel.font = [UIFont systemFontOfSize:14]; - _TitleLabel.textAlignment = UITextAlignmentLeft; - _TitleLabel.textColor = kUIColorFromRGB(0x595959); - _TitleLabel.text = @"������������"; - [cell.contentView addSubview:_TitleLabel]; + if(_MusicLabel==nil) + { + _MusicLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(50,15,SCREEN_WIDTH/2, 30)]; + _MusicLabel.font = [UIFont systemFontOfSize:14]; + _MusicLabel.textAlignment = UITextAlignmentLeft; + _MusicLabel.textColor = kUIColorFromRGB(0x595959); + _MusicLabel.text = @"������������"; + [cell.contentView addSubview:_MusicLabel]; + } + UIImageView * icon_line = [[UIImageView alloc] initWithFrame:CGRectMake(20, 59, SCREEN_WIDTH, 1)]; icon_line.image = [UIImage imageNamed:@"icon_line"]; @@ -249,15 +390,25 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger index = [indexPath row]; - - // ������������������������ - // ������������������ - //HotelSelPage* page = [[HotelSelPage alloc] initIsFirstPage:NO]; - //page.bSelRoom = 2; - // ������������ - //BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; - //[self presentViewController:baseNav animated:YES completion:nil]; - //[self showActionForPhoto]; + if(index == 0) + { + NSLog(@"%s",__func__); + self.dateDic = [self LHGetStartTime]; + self.weekStr = self.dateDic[@"week"][0]; + [self.pickView reloadData]; + //[self.userNumPickView selectRow:0 inComponent:0 animated:NO]; + [[UIApplication sharedApplication].keyWindow addSubview:self.pickView]; + [self.pickView show]; + } + else if(index == 2) + { + + // ������������������������ + MusicSetPage* page = [[MusicSetPage alloc] initIsFirstPage:NO]; + // ������������ + BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; + [self presentViewController:baseNav animated:YES completion:nil]; + } } - (void)switchAction @@ -265,54 +416,17 @@ BOOL isButtonOn = [switchButton isOn]; if (isButtonOn) { - //showSwitchValue.text = @"���"; + self.is_open_upload = @"1"; } else { - //showSwitchValue.text = @"���"; + self.is_open_upload = @"0"; } + + [self update_is_open_upload]; } #pragma mark - custom function begin --(void)get_straner -{ - //[UserDefault stringForKey:@"user_id"] - NSString *path = [[NSString alloc] initWithFormat:@"%@",[NSString stringWithFormat:GET_STRANER,[UserDefault stringForKey:@"user_id"]]]; - - NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; - - MPWeakSelf(self); - [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody) - { - MPStrongSelf(self); - BaseResModel * resModel = [Global toBaseModel:responseBody]; - - if(resModel.code == 0) - { - //������������������ - if(![Global isEmptyObject:resModel.content]) - { - - //count = resModel.content; - - } - else - { - [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; - } - } - else - { - [Global alertMessageEx:resModel.desc title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; - } - } - failure:^(NSString *error) - { - - [Global alertMessageEx:error title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; - }]; -} - -(void)exitLoginAction -- Gitblit v1.8.0