236 lines
7.7 KiB
Objective-C
236 lines
7.7 KiB
Objective-C
//
|
|
// XPMineUserInfoEditPresenter.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/23.
|
|
//
|
|
|
|
#import "XPMineUserInfoEditPresenter.h"
|
|
///Api
|
|
#import "Api+Mine.h"
|
|
///Tool
|
|
#import "AccountInfoStorage.h"
|
|
#import "UploadFile.h"
|
|
///Model
|
|
#import "XPMineUserInfoEditModel.h"
|
|
#import "UserInfoModel.h"
|
|
|
|
///P
|
|
#import "XPMineUserInfoEditProtocol.h"
|
|
@interface XPMineUserInfoEditPresenter ()
|
|
///昵称
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *nickItem;
|
|
///头像
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *avatarItem;
|
|
///生日
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *birthItem;
|
|
///相册
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *photoItem;
|
|
///介绍
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *desItem;
|
|
///标签
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *tagItem;
|
|
///地区
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *areaItem;
|
|
///声音
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *soundItem;;
|
|
|
|
///
|
|
@property (nonatomic,strong) NSMutableArray *editArray;
|
|
///日期的格式
|
|
@property (nonatomic,strong) NSDateFormatter *dateFormatter;
|
|
@end
|
|
|
|
@implementation XPMineUserInfoEditPresenter
|
|
|
|
///获取用户信息
|
|
- (void)getUserInfo {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithDictionary:data.data];
|
|
[[self getView] onGetUserInfoSuccess:infoModel];
|
|
}] uid:uid];
|
|
}
|
|
|
|
///获取个人资料页编辑的数据源
|
|
- (void)getUserInfoEditDataSourceWithUserInfo:(UserInfoModel *)userInfo {
|
|
///数据组装
|
|
if (self.editArray.count <= 0) {
|
|
[self.editArray addObject:self.avatarItem];
|
|
[self.editArray addObject:self.nickItem];
|
|
[self.editArray addObject:self.birthItem];
|
|
[self.editArray addObject:self.photoItem];
|
|
[self.editArray addObject:self.areaItem];
|
|
// [self.editArray addObject:self.tagItem];
|
|
// [self.editArray addObject:self.soundItem];
|
|
[self.editArray addObject:self.desItem];
|
|
|
|
}
|
|
|
|
|
|
self.avatarItem.isReview = userInfo.isReview;
|
|
self.avatarItem.avatarUrl = userInfo.isReview ? userInfo.reviewingAvatar : userInfo.avatar;
|
|
|
|
self.nickItem.subTitle = userInfo.nick;
|
|
NSString *dateStr = [self.dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:userInfo.birth/1000]];
|
|
self.birthItem.subTitle = dateStr;
|
|
|
|
self.photoItem.photoArray = userInfo.privatePhoto;
|
|
|
|
self.desItem.subTitle = userInfo.userDesc.length > 0 ? userInfo.userDesc : @"";
|
|
///数据回传
|
|
[[self getView] getUserInfoEditDataSourceSuccess:self.editArray];
|
|
}
|
|
|
|
/// 补全资料
|
|
/// @param avatar 头像
|
|
/// @param nick 昵称
|
|
/// @param birth 生日
|
|
/// @param userDesc 用户的签名
|
|
- (void)complectionInfoWithAvatar:(NSString * _Nullable)avatar
|
|
nick:(NSString * _Nullable)nick
|
|
birth:(NSString * _Nullable)birth
|
|
userDesc:(NSString * _Nullable)userDesc {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString * ticket = [[AccountInfoStorage instance] getTicket];
|
|
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
|
if (avatar.length > 0) {
|
|
[dic setValue:avatar forKey:@"avatar"];
|
|
}
|
|
|
|
if (nick.length > 0) {
|
|
[dic setValue:nick forKey:@"nick"];
|
|
}
|
|
|
|
if (birth.length > 0) {
|
|
[dic setValue:birth forKey:@"birth"];
|
|
}
|
|
|
|
if (userDesc.length > 0) {
|
|
[dic setValue:userDesc forKey:@"userDesc"];
|
|
}
|
|
|
|
[dic setObject:uid forKey:@"uid"];
|
|
[dic setObject:ticket forKey:@"ticket"];
|
|
[Api completeUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithDictionary:data.data];
|
|
[[self getView] completeUserInfoSuccess:infoModel];
|
|
}showLoading:YES] userInfo:dic];
|
|
}
|
|
|
|
|
|
/// 上传头像
|
|
/// @param avatar 头像
|
|
- (void)uploadAvatar:(UIImage *)avatar {
|
|
NSData *data = UIImageJPEGRepresentation(avatar, 0.5);
|
|
NSString *format = [UIImage getImageTypeWithImageData:data];
|
|
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
|
|
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
|
|
[[self getView] uploadImageSuccess:key];
|
|
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
|
|
|
|
}];
|
|
}
|
|
|
|
///获取地区列表
|
|
-(void)getAreaList{
|
|
[Api getAreaList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
[[self getView]getAreaListSuccess:data.data];
|
|
}showLoading:NO]];
|
|
}
|
|
///保存地区列表
|
|
-(void)saveAreaConfigWithArea:(NSString *)area{
|
|
[Api saveAreaConfigWithArea:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
[[self getView]saveAreaSuccess];
|
|
}showLoading:YES errorToast:YES] region:area];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (XPMineUserInfoEditModel *)nickItem {
|
|
if (!_nickItem) {
|
|
_nickItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_nickItem.type = XPMineUserInfoEditType_Nick;
|
|
_nickItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter1");
|
|
}
|
|
return _nickItem;
|
|
}
|
|
|
|
- (XPMineUserInfoEditModel *)avatarItem {
|
|
if (!_avatarItem) {
|
|
_avatarItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_avatarItem.type = XPMineUserInfoEditType_Avatar;
|
|
_avatarItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter2");
|
|
}
|
|
return _avatarItem;
|
|
}
|
|
|
|
|
|
- (XPMineUserInfoEditModel *)birthItem {
|
|
if (!_birthItem) {
|
|
_birthItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_birthItem.type = XPMineUserInfoEditType_Birth;
|
|
_birthItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter3");
|
|
}
|
|
return _birthItem;
|
|
}
|
|
-(XPMineUserInfoEditModel *)areaItem{
|
|
if (!_areaItem){
|
|
_areaItem = [XPMineUserInfoEditModel new];
|
|
_areaItem.type = XPMineUserInfoEditType_Area;
|
|
_areaItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter10");
|
|
}
|
|
return _areaItem;
|
|
}
|
|
- (XPMineUserInfoEditModel *)tagItem{
|
|
if (!_tagItem){
|
|
_tagItem = [XPMineUserInfoEditModel new];
|
|
_tagItem.type = XPMineUserInfoEditType_Tag;
|
|
_tagItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter8");
|
|
_tagItem.subTitle = YMLocalizedString(@"XPMineUserInfoEditPresenter9");
|
|
}
|
|
return _tagItem;
|
|
}
|
|
- (XPMineUserInfoEditModel *)photoItem {
|
|
if (!_photoItem) {
|
|
_photoItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_photoItem.type = XPMineUserInfoEditType_Photo;
|
|
_photoItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter4");
|
|
}
|
|
return _photoItem;
|
|
}
|
|
|
|
- (XPMineUserInfoEditModel *)desItem {
|
|
if (!_desItem) {
|
|
_desItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_desItem.type = XPMineUserInfoEditType_UseDes;
|
|
_desItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter5");
|
|
}
|
|
return _desItem;
|
|
}
|
|
- (XPMineUserInfoEditModel *)soundItem{
|
|
if (!_soundItem){
|
|
_soundItem = [[XPMineUserInfoEditModel alloc]init];
|
|
_soundItem.type = XPMineUserInfoEditType_Sound;
|
|
_soundItem.title = YMLocalizedString(@"XPMineUserInfoEditPresenter6");
|
|
_soundItem.subTitle = YMLocalizedString(@"XPMineUserInfoEditPresenter7");
|
|
}
|
|
return _soundItem;
|
|
}
|
|
- (NSMutableArray *)editArray {
|
|
if (!_editArray) {
|
|
_editArray = [NSMutableArray array];
|
|
}
|
|
return _editArray;
|
|
}
|
|
|
|
- (NSDateFormatter *)dateFormatter {
|
|
if (!_dateFormatter) {
|
|
_dateFormatter = [[NSDateFormatter alloc] init];
|
|
_dateFormatter.dateFormat = @"yyyy-MM-dd";
|
|
|
|
}
|
|
return _dateFormatter;
|
|
}
|
|
|
|
|
|
@end
|