热更新demo

userInfoController.m 18KB

    // // userInfoController.m // ThePaperDemo // // Created by scar1900 on 14/12/5. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "userInfoController.h" #import "AsyncImageView.h" #import "userInfoTableController.h" #import "UIImage-Extensions.h" #import "AsyncImageScrollView.h" #import "TPSelectButton.h" #import "myDynamicController.h" #import "TPImageScannerController.h" #import "readHistoryController.h" #import "pointsMallController.h" @interface userInfoController () <UIAlertViewDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, AsyImageScrollDelegate,imageScanerDelegate> @property(nonatomic, strong)UIButton *backBtn; @property(nonatomic, strong)AsyncImageView *headImageView; @property(nonatomic, strong)UIImageView *authImageView; @property(nonatomic, strong)UIButton *headBackView; @property(nonatomic, strong)TPSelectButton *dynamicBtn; @property(nonatomic, strong)TPSelectButton *historyBtn; @property(nonatomic, strong)TPSelectButton *haibeiBtn; @property(nonatomic, strong)UIView *line; @property(nonatomic, strong)userInfoTableController *tableVC; @property(nonatomic, strong)UIActionSheet *actionSheet; @property(nonatomic, strong)UIImagePickerController *picker; @property(nonatomic, strong)userBO *userBO; @end @implementation userInfoController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil]; [self.view addSubview:self.backBtn]; [self.view addSubview:self.headImageView]; [self.view addSubview:self.authImageView]; [self.view addSubview:self.headBackView]; [self.view addSubview:self.dynamicBtn]; [self.view addSubview:self.historyBtn]; [self.view addSubview:self.haibeiBtn]; [self.view addSubview:self.line]; [self.view addSubview:self.tableVC.view]; [self addChildViewController:self.tableVC]; [self.tableVC didMoveToParentViewController:self]; [self layoutViews]; } - (void)needrefreshNightMode { self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; if ([[TPUserDefault instance].isNightMode intValue] == 0) { [_backBtn setImage:Image(@"detailPage/backBtn.png") forState:UIControlStateNormal]; [_backBtn setImage:Image(@"detailPage/backBtn_s.png") forState:UIControlStateHighlighted]; }else { [_backBtn setImage:Image(@"detailPage/backBtn_night.png") forState:UIControlStateNormal]; [_backBtn setImage:Image(@"detailPage/backBtn_night_s.png") forState:UIControlStateHighlighted]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.userBO = [TPUserDefault instance].userBO; } - (void)layoutViews { [self.backBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.top).offset(18); make.left.equalTo(self.view.left); make.width.and.height.mas_equalTo(@40); }]; [self.headImageView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.top).offset(33); make.centerX.equalTo(self.view.centerX); make.width.and.height.mas_equalTo(@44); }]; [self.authImageView makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.headImageView.right).offset(3); make.bottom.equalTo(self.headImageView.bottom).offset(1); make.width.and.height.mas_equalTo(@12); }]; [self.headBackView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.headImageView); }]; [self.dynamicBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.headImageView.bottom).offset(25); make.left.equalTo(self.view.left).offset(16); make.width.mas_equalTo(@70); make.height.mas_equalTo(@45); }]; [self.historyBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.dynamicBtn.top); make.centerX.equalTo(self.view.centerX); make.width.mas_equalTo(@70); make.height.mas_equalTo(@45); }]; [self.haibeiBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.dynamicBtn.top); make.right.equalTo(self.view.right).offset(-16); make.width.mas_equalTo(@70); make.height.mas_equalTo(@45); }]; [self.line makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.dynamicBtn.bottom).offset(11); make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.height.mas_equalTo(@1); }]; [self.tableVC.view makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.line.bottom); make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.bottom.equalTo(self.view.bottom); }]; } #pragma mark - get and set method - (UIButton*)backBtn { if (!_backBtn) { _backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _backBtn.backgroundColor = [UIColor clearColor]; if ([[TPUserDefault instance].isNightMode intValue] == 0) { [_backBtn setImage:Image(@"detailPage/backBtn.png") forState:UIControlStateNormal]; }else { [_backBtn setImage:Image(@"detailPage/backBtn_night.png") forState:UIControlStateNormal]; } [_backBtn setImage:Image(@"detailPage/backBtn_s.png") forState:UIControlStateHighlighted]; [_backBtn addTarget:self action:@selector(backHandler) forControlEvents:UIControlEventTouchUpInside]; } return _backBtn; } - (AsyncImageView*)headImageView { if (!_headImageView) { _headImageView = [[AsyncImageView alloc] init]; _headImageView.isHaveWaterPrint = NO; _headImageView.layer.cornerRadius = 44/2; _headImageView.clipsToBounds = YES; _headImageView.defaultImage = Image(@"login/loginIcon_s.png"); /** * bug:5287(打底图问题汇总) */ } return _headImageView; } - (UIImageView*)authImageView { if (!_authImageView) { _authImageView = [[UIImageView alloc] init]; _authImageView.backgroundColor = [UIColor clearColor]; _authImageView.image = Image(@"topic/auth.png"); _authImageView.hidden = YES; } return _authImageView; } - (UIButton*)headBackView { if (!_headBackView) { _headBackView = [UIButton buttonWithType:UIButtonTypeCustom]; _headBackView.backgroundColor = [UIColor clearColor]; [_headBackView addTarget:self action:@selector(headClick:) forControlEvents:UIControlEventTouchUpInside]; } return _headBackView; } - (TPSelectButton*)dynamicBtn { if (!_dynamicBtn) { _dynamicBtn = [[TPSelectButton alloc] initWithFrame:CGRectZero target:self selector:@selector(gotoDynamic)]; [_dynamicBtn setBUttonNormalImage:Image(@"login/dynamic.png") highLightImage:Image(@"login/dynamic_s.png") selectedImage:nil]; _dynamicBtn.titleText = @"我的动态"; [_dynamicBtn.textLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_dynamicBtn.left); make.right.equalTo(_dynamicBtn.right); make.bottom.equalTo(_dynamicBtn.bottom); make.height.equalTo(@14); }]; } _dynamicBtn.textLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); return _dynamicBtn; } - (TPSelectButton*)historyBtn { if (!_historyBtn) { _historyBtn = [[TPSelectButton alloc] initWithFrame:CGRectZero target:self selector:@selector(gotoHistory)]; [_historyBtn setBUttonNormalImage:Image(@"login/history.png") highLightImage:Image(@"login/history_s.png") selectedImage:nil]; _historyBtn.titleText = @"阅读历史"; [_historyBtn.textLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_historyBtn.left); make.right.equalTo(_historyBtn.right); make.bottom.equalTo(_historyBtn.bottom); make.height.equalTo(@14); }]; } _historyBtn.textLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); return _historyBtn; } - (TPSelectButton*)haibeiBtn { if (!_haibeiBtn) { _haibeiBtn = [[TPSelectButton alloc] initWithFrame:CGRectZero target:self selector:@selector(gotoHaibei)]; [_haibeiBtn setBUttonNormalImage:Image(@"login/haibei.png") highLightImage:Image(@"login/haibei_s.png") selectedImage:nil]; _haibeiBtn.titleText = @"我的海贝"; [_haibeiBtn.textLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_haibeiBtn.left); make.right.equalTo(_haibeiBtn.right); make.bottom.equalTo(_haibeiBtn.bottom); make.height.equalTo(@14); }]; } _haibeiBtn.textLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); return _haibeiBtn; } - (UIView*)line { if (!_line) { _line = [[UIView alloc] init]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } - (userInfoTableController*)tableVC { if (!_tableVC) { _tableVC = [userInfoTableController new]; } return _tableVC; } - (void)setUserBO:(userBO *)user { _userBO = user; self.headImageView.imageView.hidden = NO; self.headImageView.imageView.backgroundColor = [UIColor clearColor]; self.headImageView.imageUrl = user.pic; self.headImageView.imageId = getImageNameFromURL(user.pic); if ([user.isAuth integerValue] == 1) self.authImageView.hidden = NO; } #pragma mark - btn event handler - (void)backHandler { ((MLNavigationController *)self.navigationController).canDragBack = YES; [self.navigationController popViewControllerAnimated:YES]; } - (void)headClick:(UIButton*)btn { if (!_actionSheet) { _actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"查看头像", @"相册选择",@"拍照",nil]; _actionSheet.actionSheetStyle = UIActionSheetStyleDefault; } [_actionSheet showInView:self.view]; } - (void)gotoDynamic { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //bug5449: 个人信息页:我的动态和阅读历史进入后,滑动返回至个人信息页,不要显示点击效果 myDynamicController *dynamicVC = [myDynamicController new]; commentObjectVO *comment = [commentObjectVO new]; comment.userInfo = setDataModelToDic([TPUserDefault instance].userBO, [userBO class]); dynamicVC.comment = comment; [self.navigationController pushViewController:dynamicVC animated:YES]; }); } - (void)gotoHistory { [MobClick event:@"86"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //bug5449: 个人信息页:我的动态和阅读历史进入后,滑动返回至个人信息页,不要显示点击效果 readHistoryController *readHistoryVC = [readHistoryController new]; [self.navigationController pushViewController:readHistoryVC animated:YES]; }); } - (void)gotoHaibei { [MobClick event:@"88"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ pointsMallController *pointsMallVC = [pointsMallController new]; [self.navigationController pushViewController:pointsMallVC animated:YES]; }); } #pragma actionsheet delegate - (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //呼出的菜单按钮点击后的响应 if (buttonIndex == _actionSheet.cancelButtonIndex) { NSLog(@"取消"); return; } switch (buttonIndex) { case 0: //查看头像 [self viewHead]; break; case 1: //本地相册 [self localPhoto]; break; case 2: //拍照 [self takePhoto]; break; default: break; } } - (void)viewHead { imageObjectBO *imageBO = imageObjectBO.new; imageBO.url = _userBO.pic; imageBO.width = [NSString stringWithFormat:@"%f",self.headImageView.imageView.image.size.width]; imageBO.height = [NSString stringWithFormat:@"%f",self.headImageView.imageView.image.size.height]; imageBO.tags = @"WWW"; NSMutableArray *array = [NSMutableArray arrayWithObjects:imageBO, nil]; TPImageScannerController *imageScanner = [[TPImageScannerController alloc]init]; imageScanner.currentIndex = 0; imageScanner.imageBOList =array; imageScanner.type = contentImageScannerType; imageScanner.delegate = self; [self.navigationController pushViewController:imageScanner animated:YES]; } - (void)localPhoto { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { if (!_picker) { _picker = [[UIImagePickerController alloc] init]; _picker.delegate = self; _picker.allowsEditing = YES; } _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:_picker animated:YES completion:^{}]; } } - (void)takePhoto { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { if (!_picker) { _picker = [[UIImagePickerController alloc] init]; _picker.delegate = self; _picker.allowsEditing = YES; } _picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:_picker animated:YES completion:^{}]; } } #pragma mark - imageScanner delegate - (void)imageContentClick:(imageObjectBO*)imageBO { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - imagepicker delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; if ([type isEqualToString:@"public.image"]) { [picker dismissViewControllerAnimated:YES completion:^{}]; UIImage *originalImage, *editedImage, *imageToUpload; editedImage = [info objectForKey:UIImagePickerControllerEditedImage]; originalImage = [info objectForKey:UIImagePickerControllerOriginalImage]; if (editedImage) { imageToUpload = editedImage; } else { imageToUpload = originalImage; } CGSize imageSize = imageToUpload.size; if (imageSize.width>200) { imageToUpload = [imageToUpload imageByScalingProportionallyToMinimumSize:CGSizeMake(200,imageSize.height*200/imageSize.width)]; } NSData *imgData = UIImagePNGRepresentation(imageToUpload); NSString *type = @"png"; if (imgData == nil) { imgData = UIImageJPEGRepresentation(imageToUpload, 1); type = @"jpg"; } CGFloat lengh = [imgData length]; NSDictionary *dic = @{@"C_TYPE":type, @"C_LEN":[NSString stringWithFormat:@"%.f",lengh]}; __weak typeof(self) Self = self; [self startHud]; [Remote upLoadImageAsyncWithBlock:getUploadURL actionTag:0 parameter:dic image:nil completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSString *status = responseData[@"STATUS"]; if ([status intValue] != 1 && [status intValue] != 13) { ShowTextMessage(responseData[@"DESC"]); [Self stopHud]; return; } NSString *url = responseData[@"URL"]; NSString *fileName = responseData[@"FILE_NAME"]; SaveFile(CachePath(fileName), imgData); NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:responseData]; [dic removeObjectForKey:@"URL"]; [dic setValue:@"0" forKey:@"P_START"]; [dic setValue:dic[@"C_LEN"] forKey:@"P_END"]; [dic removeObjectForKey:@"PARAM"]; [dic removeObjectForKey:@"STATUS"]; [dic removeObjectForKey:@"RESULT"]; [Remote upLoadImageAsyncWithBlock:url actionTag:1 parameter:dic image:CachePath(fileName) completion:^(BOOL success, NSString *message, id responseData) { if (success) { TPLOG (@"%@",responseData); NSString *status = responseData[@"STATUS"]; if ([status intValue] == 13) { NSString *newImageURL = responseData[@"IMAGEURL"]; userBO *user = [TPUserDefault instance].userBO; user.pic = newImageURL; [TPUserDefault instance].userBO = user; Self.userBO = [TPUserDefault instance].userBO; [[NSNotificationCenter defaultCenter]postNotificationName:CHANGEUSERPICSUCCESS object:nil]; }else { ShowTextMessage(message); } }else { ShowTextMessage(message); } [Self stopHud]; }]; }else { ShowTextMessage(message); [Self stopHud]; } }]; } } - (void)startHud { [self.view addSubview:self.waitBackView]; [self.view bringSubviewToFront:self.waitBackView]; self.waitCursor.animating = YES; } - (void)stopHud { [self.waitBackView removeFromSuperview]; self.waitBackView = nil; self.waitCursor.animating = NO; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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