cdts/xdts-ios 3/TreeHole/Code/Features/Login/ViewController/SetAvatarViewController.m

119 lines
4.4 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// SetAvatarViewController.m
// Youth
//
// Created by mambaxie on 2022/1/1.
//
#import "SetAvatarViewController.h"
#import "TZImagePickerController+MTImagePicker.h"
@interface SetAvatarViewController ()
@property (nonatomic, strong) PYImageView *avatarImageView;
@property (nonatomic, strong) UIImage *avatarImage;
@end
@implementation SetAvatarViewController
- (NSString *)topImageName {
return @"TH_login_head_img";
}
- (NSString *)tipsContent {
return @"拍照或上传,成为最靓的崽";
}
- (void)viewDidLoad {
[super viewDidLoad];
UIView *addAvatarItem = [[UIView alloc] init];
addAvatarItem.size = CGSizeMake(FIX_SIZE(120), FIX_SIZE(120));
addAvatarItem.backgroundColor = COLOR_WITH_RGB(0xF3F9FB);
addAvatarItem.layer.cornerRadius = FIX_SIZE(16);
addAvatarItem.clipsToBounds = YES;
addAvatarItem.y = FIX_SIZE(77);
addAvatarItem.centerX = SCREEN_WIDTH * 0.5;
WeakSelf(self);
[addAvatarItem addTapWithAction:^{
TZImagePickerController *picker = [TZImagePickerController mt_imagePickerWithMaxImagesCount:1 didFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
if (photos.count) {
weakself.avatarImageView.image = photos.firstObject;
weakself.avatarImageView.hidden = NO;
weakself.avatarImage = weakself.avatarImageView.image;
}
}];
[weakself presentViewController:picker animated:YES completion:nil];
}];
[self.cardView addSubview:addAvatarItem];
UIImageView *addIconView = [[UIImageView alloc] init];
addIconView.size = CGSizeMake(FIX_SIZE(26), FIX_SIZE(26));
addIconView.image = ImageNamed(@"TH_login_add_icon");
addIconView.center = CGPointMake(addAvatarItem.width * 0.5, addAvatarItem.height * 0.5);
[addAvatarItem addSubview:addIconView];
UILabel *addLabel = [[UILabel alloc] init];
addLabel.text = @"点击选取头像";
addLabel.textColor = CONTENT_COLOR;
addLabel.font = SMALL_FONT;
[addLabel sizeToFit];
addLabel.y = addIconView.bottom + FIX_SIZE(13.5);
addLabel.centerX = addIconView.centerX;
[addAvatarItem addSubview:addLabel];
PYImageView *avatarImageView = [[PYImageView alloc] init];
avatarImageView.frame = addAvatarItem.bounds;;
avatarImageView.backgroundColor = addAvatarItem.backgroundColor;
avatarImageView.hidden = YES;
[addAvatarItem addSubview:avatarImageView];
self.avatarImageView = avatarImageView;
PYThemeButton *doneButton = [PYThemeButton buttonWithTitle:@"完成" action:^(UIButton * _Nonnull button) {
if (!weakself.avatarImage) {
[SVProgressHUD showInfoWithStatus:@"请先选择头像"];
return;
}
[SVProgressHUD showWithStatus:nil];
[PYHTTPManager uploadFileWithScene:AliOSSUploadSceneAvatar data:compressImageToDataIfNeed(weakself.avatarImage) completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[UserService updateUserToRemoteWithParams:@{
@"avatar": rsp ?: @""
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[UserService currentUser].is_default_avatar = false;
[PYAppService login];
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
}
}];
}];
doneButton.width = FIX_SIZE(124);
doneButton.centerX = addAvatarItem.centerX;
doneButton.y = addAvatarItem.bottom + FIX_SIZE(30);
[self.cardView addSubview:doneButton];
UILabel *jumpLabel = [[UILabel alloc] init];
jumpLabel.text = @"跳过";
jumpLabel.width = FIX_SIZE(50);
jumpLabel.height = FIX_SIZE(30);
jumpLabel.textAlignment = NSTextAlignmentCenter;
jumpLabel.textColor = CONTENT_COLOR;
jumpLabel.font = SMALL_FONT;
[jumpLabel addTapWithAction:^{
[PYAppService login];
}];
jumpLabel.centerX = doneButton.centerX;
jumpLabel.y = doneButton.bottom + FIX_SIZE(10);
[self.cardView addSubview:jumpLabel];
}
@end