123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- //
- // JXMyBaseInFovc.m
- // shiku_im
- //
- // Created by 123 on 2020/5/29.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXMyBaseInFovc.h"
- #import "JXQRCodeViewController.h"
- #import "JXImageScrollVC.h"
- #import "DMScaleTransition.h"
- #import "JXTelAreaListVC.h"
- #import "RITLPhotosViewController.h"
- #import "JXselectSexView.h"
- #import "JXCameraVC.h"
- #import "STAlertView.h"
- #import "selectProvinceVC.h"
- @interface JXMyBaseInFovc ()<RITLPhotosViewControllerDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate,JXActionSheetVCDelegate,JXCameraVCDelegate,UITextFieldDelegate>
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
- @property (weak, nonatomic) IBOutlet UIView *updateheadIMG;
- @property (weak, nonatomic) IBOutlet UIImageView *IconIMG;
- @property (weak, nonatomic) IBOutlet UITextField *nickName;
- @property (weak, nonatomic) IBOutlet UILabel *sexL;
- @property (weak, nonatomic) IBOutlet UILabel *addrL;
- @property (weak, nonatomic) IBOutlet UIView *qQCodeView;
- @property (weak, nonatomic) IBOutlet UIView *addressView;
- @property (weak, nonatomic) IBOutlet UIView *sexView;
- @property (weak, nonatomic) IBOutlet UIButton *compleBtn;
- @property (nonatomic,copy) NSString *recordUrlIcon;
- @property (nonatomic,assign) int cityStr;
- @property (nonatomic,assign) int proViStr;
- @property (nonatomic,assign) int areaStr;
- @property (nonatomic,strong) JXselectSexView *selectSexView;
- @property (nonatomic,assign) NSInteger sexInt;
- @end
- @implementation JXMyBaseInFovc
- -(instancetype)init{
- if (self=[super init]) {
- [g_notify addObserver:self selector:@selector(newRequest:) name:kXMPPNewRequestNotifaction object:nil];
- }
-
- return self;
- }
-
-
- #pragma mark - 发送原图
- // - (void)photosViewController:(UIViewController *)viewController images:(NSArray<UIImage *> *)images infos:(NSArray<NSDictionary *> *)infos {
- //
- // self.IconIMG.image = images.firstObject;
- //
- // // [g_server uploadHeadImage:_user.userId image:self.IconIMG.image toView:self];
- //
- // }
- // #pragma mark - 发送缩略图
- // - (void)photosViewController:(UIViewController *)viewController thumbnailImages:(NSArray *)thumbnailImages infos:(NSArray<NSDictionary *> *)infos {
- // self.IconIMG.image = thumbnailImages.firstObject;
- // // [g_server uploadHeadImage:_user.userId image:self.IconIMG.image toView:self];
- // }
- - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index {
- if (index == 0) {
- UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
- ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- ipc.delegate = self;
- ipc.allowsEditing = YES;
- //选择图片模式
- ipc.modalPresentationStyle = UIModalPresentationCurrentContext;
- // [g_window addSubview:ipc.view];
- if (IS_PAD) {
- UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc];
- [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- }else {
- [self presentViewController:ipc animated:YES completion:nil];
- }
-
- }else {
- JXCameraVC *vc = [JXCameraVC alloc];
- vc.cameraDelegate = self;
- vc.isPhoto = YES;
- vc = [vc init];
- [self presentViewController:vc animated:YES completion:nil];
- }
- }
- - (void)cameraVC:(JXCameraVC *)vc didFinishWithImage:(UIImage *)image {
- //_image = [ImageResize image:image fillSize:CGSizeMake(640, 640)];
- // [_image retain];
- // 照相
-
- [g_server uploadHeadImage:g_server.myself.userId image:image toView:self];
-
- self.IconIMG.image = image;
-
- }
- -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
- {
- [picker dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
- {
- //_image = [ImageResize image:[info objectForKey:@"UIImagePickerControllerEditedImage"] fillSize:CGSizeMake(640, 640)];
- UIImage *imgV = [info objectForKey:@"UIImagePickerControllerEditedImage"];
- self.IconIMG.image=imgV;
- [g_server uploadHeadImage:g_server.myself.userId image:imgV toView:self];
- [picker dismissViewControllerAnimated:YES completion:nil];
-
- }
- -(void)onHeadImage{
-
- JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:@[] names:@[Localized(@"JX_ChoosePhoto"),Localized(@"JX_TakePhoto")]];
- actionVC.delegate = self;
- [self presentViewController:actionVC animated:NO completion:nil];
-
- UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
- ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- ipc.delegate = self;
- ipc.allowsEditing = YES;
- ipc.modalPresentationStyle = UIModalPresentationFullScreen;
- // [g_window addSubview:ipc.view];
- if (IS_PAD) {
- UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc];
- [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- }else {
- [self presentViewController:ipc animated:YES completion:nil];
- }
-
- // RITLPhotosViewController *photoController = RITLPhotosViewController.photosViewController;
- // photoController.configuration.maxCount = 1;//最大的选择数目
- // photoController.configuration.containVideo = NO;//选择类型,目前只选择图片不选择视频
- //
- // photoController.photo_delegate = self;
- // photoController.thumbnailSize = CGSizeMake(320, 320);//缩略图的尺寸
- // // photoController.defaultIdentifers = self.saveAssetIds;//记录已经选择过的资源
- //
- // [self presentViewController:photoController animated:true completion:^{}];
-
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- UILabel *tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT>=812?88:64, JX_SCREEN_WIDTH, 30)];
- tipLabel.text=@"请使用中文昵称";
- tipLabel.textAlignment=NSTextAlignmentCenter;
- tipLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
- [self.view addSubview:tipLabel];
- self.topViewH.constant=JX_SCREEN_HEIGHT>=812?88+30:64+30;
- [self defineNavBar:@"个人信息" andRinghtBtnImg:@""];
- self.IconIMG.layer.cornerRadius=22;
- self.IconIMG.layer.masksToBounds=YES;
- self.compleBtn.layer.cornerRadius=5;
- self.compleBtn.layer.masksToBounds=YES;
- _selectSexView=[[JXselectSexView alloc]init];
- _selectSexView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.7];
- _selectSexView.frame=[UIScreen mainScreen].bounds;
- [[UIApplication sharedApplication].keyWindow addSubview:_selectSexView];
- _selectSexView.hidden=YES;
- _nickName.delegate=self;
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)name:UITextFieldTextDidChangeNotification object:_nickName];
-
- __weak typeof(self) weakSelf=self;
- _selectSexView.selectBtnBlock = ^(UIButton *sender) {
- weakSelf.selectSexView.hidden=YES;
- weakSelf.sexInt=sender.tag;
- if (sender.tag == 0) {// 女
- weakSelf.sexL.text = @"男";
- }else {// 男
- weakSelf.sexL.text = @"女";
- }
-
- };
-
-
- self.nickName.text=self.user.userNickname;
- if ([_user.sex intValue] == 0) {// 女
- _sexL.text = @"女";
- }else {// 男
- _sexL.text = @"男";
- }
- //self.addrL.text=[NSString stringWithFormat:@"%@",self.user.cityId];
- //self.addrL.text=[NSString stringWithFormat:@"%@%@%@",_user,g_server.myself.provinceId,g_server.myself.cityId];
-
- NSString* city = [g_constant getAddressForNumber:_user.provinceId cityId:_user.cityId areaId:_user.areaId];
- _addrL.text = [NSString stringWithFormat:@"%@",city.length > 0 ? city : @"--"];
-
- [g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:self.IconIMG];
- // http://47.57.16.13:8092/user/update?language=zh&access_token=b78dad1a039d4329b7f4bac634613fdf&salt=1591627301966&secret=l2qBmMzO557VWSh62nJiNA%3D%3D
-
- [self.compleBtn addTarget:self action:@selector(compleBtnClick) forControlEvents:UIControlEventTouchUpInside];
-
- [self.updateheadIMG addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onHeadImage)]];
- [self.sexView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sexViewView)]];
-
-
-
- [self.qQCodeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qQCodeViewClick)]];
-
-
- [self.addressView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addressViewClick)]];
-
-
- [g_server getUser:self.userId toView:self];
-
- }
- //=====================================start ============
- - (BOOL)textFieldShouldReturn:(UITextField *)textField{
- [textField resignFirstResponder];
-
- //过滤非汉字字符
- textField.text = [self filterCharactor:textField.text withRegex:@"[^\u4e00-\u9fa5]"];
-
- if (textField.text.length >= 24) {
- textField.text = [textField.text substringToIndex:24];
-
- }
- return NO;
- }
-
- - (void)textFiledEditChanged:(id)notification{
-
- UITextRange *selectedRange = _nickName.markedTextRange;
- UITextPosition *position = [_nickName positionFromPosition:selectedRange.start offset:0];
-
- if (!position) { //// 没有高亮选择的字
- //过滤非汉字字符
- _nickName.text = [self filterCharactor:_nickName.text withRegex:@"[^\u4e00-\u9fa5]"];
-
- if (_nickName.text.length >= 24) {
- _nickName.text = [_nickName.text substringToIndex:24];
- }
- }else { //有高亮文字
- //do nothing
- }
- }
-
- //根据正则,过滤特殊字符
- - (NSString *)filterCharactor:(NSString *)string withRegex:(NSString *)regexStr{
- NSString *searchText = string;
- NSError *error = NULL;
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error];
- NSString *result = [regex stringByReplacingMatchesInString:searchText options:NSMatchingReportCompletion range:NSMakeRange(0, searchText.length) withTemplate:@""];
- return result;
- }
- //=====================================end=============
- //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
- // if(textField == _birthday){
- //
- // return NO;
- // }else{
- //
- // return YES;
- // }
- //}
- /**地区选择*/
- - (void)addressViewClick{
- selectProvinceVC *vc = [[selectProvinceVC alloc] init];
- vc.delegate = self;
- vc.didSelect = @selector(onSelCity:);
- vc.showCity = YES;
- vc.showArea = NO;
- vc.parentId = 1;
- vc = [vc init];
- // [g_window addSubview:vc.view];
- [g_navigation pushViewController:vc animated:YES];
- }
- -(void)onSelCity:(selectProvinceVC*)sender{
- // resume.cityId = sender.cityId;
- // resume.provinceId = sender.provinceId;
- // resume.areaId = sender.areaId;
- // resume.countryId = 1;
- // _city.text = sender.selValue;
-
- _proViStr = sender.provinceId;
- _areaStr = sender.areaId;
- _cityStr =sender.cityId;
-
-
-
- _addrL.text= [NSString stringWithFormat:@"%@",sender.selValue];
-
- }
- - (void)didSelectTelArea:(NSDictionary *)areaCode{
-
- _addrL.text= [NSString stringWithFormat:@"%@",areaCode[@"prefix"]];
-
- }
- - (void)sexViewView{
-
- _selectSexView.hidden=NO;
- }
- /**完成 */
- - (void)compleBtnClick{
- JXUserObject *user=[[JXUserObject alloc]init];
- user.userNickname = _nickName.text.length>0?_nickName.text:self.user.userNickname;
- user.sex = [NSNumber numberWithBool:_sexInt];
-
- user.cityId= @(_cityStr);;
- user.provinceId= @(_proViStr);;
- user.areaId= @(_areaStr);;
- user.countryId=@(1);
-
- // [g_server delHeadImage:self.user.userId];
- //URL v /user/update?sex=1&nickname=t%E5%91%83%E5%91%83%E5%91%83&language=zh&access_token=c4892f40d8c54e7887b59bf1a6c97190&salt=1594274614096&secret=vq9AvT%2BoEkmQnVlh2g0p2A%3D%3D HTTP/1.1
-
- //[g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:_IconIMG];
- // 更新用户信息
- //[user updateUserNickname];
-
- [g_server updateUser:user toView:self];
-
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
-
- if( [aDownload.action isEqualToString:act_UserGet] ){
- JXUserObject* user = [[JXUserObject alloc]init];
- [user getDataFromDict:dict];
- [user insertFriend];
- [user updateUserNickname];
- [user updateRemarkName];
- [user updateTelephone];
- [self setUserInfo:user];
- }if( [aDownload.action isEqualToString:act_UploadHeadImage] ){
- JXUserObject* user = [[JXUserObject alloc]init];
- _recordUrlIcon=dict[@"data"][@"TUrl"];
-
- }if( [aDownload.action isEqualToString:act_UserUpdate] ){
-
- [g_notify postNotificationName:@"updateUserHeadIMG" object:nil];
- [g_navigation dismissViewController:self animated:NO];
-
- }
-
- }
- - (void)newRequest:(NSNotification *)notif {
- [g_server getUser:self.user.userId toView:self];
- }
- - (void) setUserInfo:(JXUserObject *)user {
- if (self.user.content) {
- user.content = self.user.content;
- }
-
-
- [g_server delHeadImage:self.user.userId];
- [g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:_IconIMG];
- // 更新用户信息
- [user updateUserNickname];
-
- }
-
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
- return show_error;
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
- return show_error;
- }
- -(void) didServerConnectStart:(JXConnection*)aDownload{
- if( [aDownload.action isEqualToString:act_UserGet] ){
-
- return;
- }
-
- }
- - (void)qQCodeViewClick{
-
- JXQRCodeViewController * qrVC = [[JXQRCodeViewController alloc] init];
- qrVC.type = QRUserType;
- qrVC.userId = _user.userId;
- qrVC.account = _user.account;
- qrVC.nickName = _user.userNickname;
- qrVC.sex = _user.sex;
- // [g_window addSubview:qrVC.view];
- [g_navigation pushViewController:qrVC animated:YES];
-
-
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self.view endEditing:YES];
- }
- @end
|