123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- //
- // MyStyleViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/11.
- //
- #import "MyStyleViewController.h"
- #import "MyStyleInstrumentCell.h"
- #import "MyStyleIntroduceCell.h"
- #import "MyStyleVideoCell.h"
- #import "InstrumentChooseViewController.h"
- #import "KSMediaManager.h"
- #import "StyleVideoModel.h"
- #import <WMPlayer.h>
- #import <KSVideoHelper.h>
- #import <RSKImageCropper/RSKImageCropper.h>
- #import "CustomNavViewController.h"
- #import "MinePageGroupModel.h"
- #import "MyStyleNavView.h"
- #import "UserInfoManager.h"
- #import "MyCreateGroupHeadView.h"
- #import "MyStyleEditHeadView.h"
- #import "CreateFansGroupViewController.h"
- #import "ModifyPhoneCheckController.h"
- #import "UserAuthViewController.h"
- #import "ModifyNameViewController.h"
- #import "LiveRoomAlertView.h"
- @interface MyStyleViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate,RSKImageCropViewControllerDelegate,RSKImageCropViewControllerDataSource>
- {
- WMPlayer *_wmPlayer;
- CGRect _playerFrame;
- }
- @property (nonatomic, strong) MyStyleNavView *navView;
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, assign) BOOL isRatation;
- @property (nonatomic, strong) NSMutableArray *instrumentArray;
- @property (nonatomic, strong) NSMutableArray *videoArray;
- @property (nonatomic, strong) NSMutableArray *videoPageArray;
- @property (nonatomic, strong) NSString *content;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (strong, nonatomic) MBProgressHUD *HUD;
- @property (nonatomic, assign) NSInteger chooseFileIndex;
- @property (nonatomic, assign) BOOL hasModifyVideoImage;
- @property (nonatomic, strong) NSMutableArray *fansGroupArray;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) MyStyleEditHeadView *infoHeadView;
- @property (nonatomic, assign) BOOL hasModify;
- /// 提示窗
- @property (nonatomic, strong) LiveRoomAlertView *alertView;
- @property (nonatomic, assign) BOOL isModifyAvatal;
- @end
- @implementation MyStyleViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- [self configUI];
- [self requestMyStyle];
- [self countUMEvent];
- }
- - (void)countUMEvent {
- [USER_MANAGER sendUMEvent:@"klx_styleEdit"];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestUserMessage];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
-
- [self.view addSubview:self.tableView];
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- }
- - (void)requestUserMessage {
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self refreshMineInfo];
- }];
- }
- - (void)refreshMineInfo {
- [self.infoHeadView configUserMessage:self.mineInfo];
- }
- - (void)requestMyStyle {
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager queryTeacherStyleRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- NSString *subjectIds = [result ks_stringValueForKey:@"subjectId"];
- NSString *subjectNames = [result ks_stringValueForKey:@"subjectName"];
- [self configWithSubjectMessage:subjectIds subjectName:subjectNames];
- // introduction
- self.content = [result ks_stringValueForKey:@"introduction"];
- NSArray *videoList = [result ks_arrayValueForKey:@"styleVideo"];
- [self.videoArray removeAllObjects];
- for (NSDictionary *parm in videoList) {
- StyleVideoModel *model = [[StyleVideoModel alloc] initWithDictionary:parm];
- [self.videoArray addObject:model];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- - (void)configWithSubjectMessage:(NSString *)subjectId subjectName:(NSString *)subjectName {
- if (![NSString isEmptyString:subjectId] && ![NSString isEmptyString:subjectName]) {
- NSArray *subjectIdArray = [subjectId componentsSeparatedByString:@","];
- NSArray *subjectNameArray = [subjectName componentsSeparatedByString:@","];
- NSInteger count = subjectNameArray.count > subjectIdArray.count ? subjectIdArray.count : subjectNameArray.count;
- NSMutableArray *subjectArray = [NSMutableArray array];
- for (NSInteger i = 0; i < count; i++) {
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:subjectIdArray[i] forKey:@"subjectId"];
- [parm setValue:subjectNameArray[i] forKey:@"subjectName"];
- [subjectArray addObject:parm];
- }
- self.instrumentArray = [NSMutableArray arrayWithArray:subjectArray];
- }
- }
- - (void)submitMyStyle {
- [self.view endEditing:YES];
- if (self.instrumentArray.count <= 0) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"至少选择一个可教授乐器"];
- return;
- }
- BOOL hasEmptyCover = NO;
- for (StyleVideoModel *model in self.videoArray) {
- if ([NSString isEmptyString:model.cover]) {
- hasEmptyCover = YES;
- break;
- }
- }
- if (hasEmptyCover) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请上传视频封面图"];
- return;
- }
- NSMutableArray *subjectIdArray = [NSMutableArray array];
- NSMutableArray *subjectNameArray = [NSMutableArray array];
-
- for (NSDictionary *parm in self.instrumentArray) {
- [subjectIdArray addObject:[parm ks_stringValueForKey:@"subjectId"]];
- [subjectNameArray addObject:[parm ks_stringValueForKey:@"subjectName"]];
- }
- NSString *subjectIds = [subjectIdArray componentsJoinedByString:@","];
- NSString *subjectNames = [subjectNameArray componentsJoinedByString:@","];
- NSMutableArray *videoArray = [NSMutableArray array];
- BOOL hasNewVideoSubmit = NO;
- for (StyleVideoModel *model in self.videoArray) {
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- if (model.isChooseVideo) {
- hasNewVideoSubmit = YES;
- [parm setValue:model.videoUrl forKey:@"videoUrl"];
- [parm setValue:model.cover forKey:@"cover"];
- }
- else {
- [parm setValue:model.internalBaseClassIdentifier forKey:@"id"];
- [parm setValue:model.cover forKey:@"cover"];
- [parm setValue:model.videoUrl forKey:@"videoUrl"];
- }
- [videoArray addObject:parm];
- }
-
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager saveTeacherStyleRequest:KS_POST styleVideo:videoArray subjectId:subjectIds subjectName:subjectNames introduction:self.content success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- self.hasModify = NO;
- NSString *descMessage = (hasNewVideoSubmit || self.hasModifyVideoImage) ? @"提交成功,请耐心等待审核" : @"保存成功";
-
- [LOADING_MANAGER KSShowMsg:descMessage promptCompletion:^{
- [self backAction];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- #pragma mark ---- table data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 3;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return [MyStyleEditHeadView getViewHeight];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return self.infoHeadView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [UIView new];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- MyStyleInstrumentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleInstrumentCell"];
- MJWeakSelf;
- [cell configWithSource:self.instrumentArray callback:^(STYLE_INSTRUMENT type, NSMutableArray * _Nullable sourceArray) {
- if (type == STYLE_INSTRUMENT_CHOOSE) {
- [weakSelf chooseInstrumentWithArray:sourceArray];
- }
- else { // 刷新
- weakSelf.hasModify = YES;
- [weakSelf refreshInstrumentPart:sourceArray];
- }
- }];
- return cell;
- }
- else if (indexPath.row == 1) {
- MyStyleIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleIntroduceCell"];
- MJWeakSelf;
- [cell configWithIntroduceMessage:self.content modifyCallback:^(NSString * _Nullable content) {
- weakSelf.hasModify = YES;
- weakSelf.content = content;
- }];
- return cell;
- }
- else {
- MyStyleVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleVideoCell"];
- [cell configWithSource:self.videoArray];
- MJWeakSelf;
- [cell opreationCallback:^(STYLEVIDEO type, UIView * _Nullable containerView) {
- [weakSelf opreationVideoCell:type container:containerView];
- }];
- return cell;
- }
- }
- - (void)opreationVideoCell:(STYLEVIDEO)type container:(UIView *)container {
- switch (type) {
- case STYLEVIDEO_CHOOSEFILE:
- {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_VIDEO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- NSLog(@"%@", videoUrl);
- weakSelf.hasModify = YES;
- [weakSelf uploadVideoWithUrl:videoUrl coverUrl:nil];
- }];
- [self.mediaManager pushImagePickerController];
- }
- break;
- case STYLEVIDEO_PLAY: // 播放
- {
- NSInteger index = container.tag - 1000;
- if (self.videoArray.count > index) {
- StyleVideoModel *model = self.videoArray[index];
- [self playVideoWithUrl:model.videoUrl];
- }
-
- }
- break;
- case STYLEVIDEO_DELETE: // 删除
- {
- NSInteger index = container.tag - 1000;
- if (self.videoArray.count > index) {
- if ([self canDeleteVideoIndex:index]) {
- self.hasModify = YES;
- [self.videoArray removeObjectAtIndex:index];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"需至少保留一个通过审核风采视频"];
- }
-
- }
- [self.tableView reloadData];
- }
- break;
- case STYLEVIDEO_CHOOSEIMAGE: // 选择图片
- {
- NSInteger index = container.tag - 1000;
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- // 裁剪
- weakSelf.hasModifyVideoImage = YES;
- [weakSelf cropImage:[imageArray lastObject] fileIndex:index];
- }];
- [self.mediaManager pushImagePickerController];
- }
- break;
- default:
- break;
- }
- }
- - (void)cropImage:(UIImage *)image fileIndex:(NSInteger)index {
- // 上传图片
- self.chooseFileIndex = index;
- // 跳转到裁剪功能
- RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:image cropMode:RSKImageCropModeCustom];
- imageCropVC.avoidEmptySpaceAroundImage = YES;
- imageCropVC.rotationEnabled = YES;
- imageCropVC.delegate = self;
- imageCropVC.dataSource = self;
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
- navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.navigationController presentViewController:navCtrl animated:YES completion:nil];
- }
- - (BOOL)canDeleteVideoIndex:(NSInteger)index {
- NSInteger passVideoCount = 0;
- if (self.videoArray.count > index) {
- StyleVideoModel *videoSource = self.videoArray[index];
- for (StyleVideoModel *model in self.videoArray) {
- if ([model.authStatus isEqualToString:@"PASS"]) {
- passVideoCount++;
- }
- }
- if (passVideoCount > 1) {
- return YES;
- }
- else if (passVideoCount == 1) {
- if ([videoSource.authStatus isEqualToString:@"PASS"]) {
- return NO;
- }
- else {
- return YES;
- }
- }
- }
-
- return YES;
- }
- - (void)uploadImage:(UIImage *)firstImage index:(NSInteger)index {
- // 上传图片
- NSData *imgData = [UIImage compressImage:firstImage maxLength:5];
- NSString *fileName = @"styleImage";
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [UPLOAD_MANAGER uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *imageUrl = [fileUrlArray lastObject];
- if (self.videoArray.count > index) {
- StyleVideoModel *model = self.videoArray[index];
- model.cover = imageUrl;
- [self.tableView reloadData];
- }
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- - (void)uploadUrlAndGetImagePath:(NSString *)videoUrl {
-
- [KSVideoHelper getLocalVideoPreViewUrlWithPath:videoUrl callback:^(UIImage * _Nullable firstImage) {
- if (firstImage) {
- // 上传图片
- NSData *imgData = [UIImage compressImage:firstImage maxLength:5];
- NSString *fileName = @"styleImage";
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *imageUrl = [fileUrlArray lastObject];
- [self uploadVideoWithUrl:videoUrl coverUrl:imageUrl];
-
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- else {
- // 如果没有直接上传图片
- [self uploadVideoWithUrl:videoUrl coverUrl:nil];
- }
-
- }];
- }
- #pragma mark --- 上传视频文件
- - (void)uploadVideoWithUrl:(NSString *)videoUrl coverUrl:(NSString *)coverUrl {
- [self hudTipWillShow:YES];
- NSURL *fileUrl = [NSURL fileURLWithPath:videoUrl];
- NSData *fileData = [NSData dataWithContentsOfURL:fileUrl];
- NSString *suffix = [NSString stringWithFormat:@".%@",[fileUrl pathExtension]];
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [[KSUploadManager shareInstance] videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
- dispatch_main_async_safe(^{
- // 显示进度
- if (self.HUD) {
- self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
- }
- });
- } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- [self hudTipWillShow:NO];
- NSString *fileUrl = [fileUrlArray lastObject];
- // 删除文件
- [self removeVideoWithPath:videoUrl];
- StyleVideoModel *model = [[StyleVideoModel alloc] init];
- model.videoUrl = fileUrl;
- model.isChooseVideo = YES;
- model.cover = coverUrl;
- [self.videoArray addObject:model];
- [self.tableView reloadData];
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- [self hudTipWillShow:NO];
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- - (void)removeVideoWithPath:(NSString *)videoUrl {
- NSFileManager *fileMamager = [NSFileManager defaultManager];
- if ([fileMamager fileExistsAtPath:videoUrl]) {
- [fileMamager removeItemAtPath:videoUrl error:nil];
- }
- }
- - (void)chooseInstrumentWithArray:(NSMutableArray *)instrumentArray {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- ctrl.preChooseArray = instrumentArray;
- MJWeakSelf;
- [ctrl chooseCallback:^(NSMutableArray *chooseArray) {
- weakSelf.hasModify = YES;
- [weakSelf refreshInstrumentPart:chooseArray];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)refreshInstrumentPart:(NSMutableArray *)chooseArray {
- self.instrumentArray = [NSMutableArray arrayWithArray:chooseArray];
- [self.tableView reloadData];
- }
- #pragma mark ------ WMPlayer
- - (void)playVideoWithUrl:(NSString *)fileUrl {
- fileUrl = [fileUrl getUrlEndcodeString];
- _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
- WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
- playModel.videoURL = [NSURL URLWithString:fileUrl];
- _wmPlayer.playerModel = playModel;
- _wmPlayer.delegate = self;
- _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- _bgView.backgroundColor = [UIColor blackColor];
- [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
- [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
-
- [_wmPlayer play];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
- [wmplayer removePlayer];
- [_bgView removeFromSuperview];
- [self setNeedsStatusBarAppearanceUpdate];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
- self.isRatation = !self.isRatation;
-
- if (self.isRatation) {
- [wmplayer removeFromSuperview];
- [UIView animateWithDuration:1.0f animations:^{
- wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- else {
- [wmplayer removeFromSuperview];
-
- [UIView animateWithDuration:1.0f animations:^{
- // 复原
- wmplayer.transform = CGAffineTransformIdentity;
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- }
- #pragma mark ---- lazying
- - (MyStyleNavView *)navView {
- if (!_navView) {
- _navView = [MyStyleNavView shareInstance];
- MJWeakSelf;
- [_navView saveStyleAction:^(BOOL isBack) {
- if (isBack) {
- [weakSelf backAction];
- }
- else {
- [weakSelf submitMyStyle];
- }
- }];
- }
- return _navView;
- }
- - (void)backAction {
- [self.view endEditing:YES];
- // 根据需要返回到不同页面
- if (self.hasModify) {
- self.alertView = [LiveRoomAlertView liveroomAlertWithTitle:@"您尚未保存修改信息,返回后将取消修改" leftButtonTitle:@"取消" rightTitle:@"确认" inView:self.view cancel:^{
-
- } confirm:^{
- [self.navigationController popViewControllerAnimated:YES];
- }];
- }
- else {
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.estimatedRowHeight = 150.0f;
- [_tableView registerNib:[UINib nibWithNibName:@"MyStyleInstrumentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleInstrumentCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"MyStyleIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleIntroduceCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"MyStyleVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleVideoCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"MineFansGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineFansGroupCell"];
-
- }
- return _tableView;
- }
- - (NSMutableArray *)instrumentArray {
- if (!_instrumentArray) {
- _instrumentArray = [NSMutableArray array];
- }
- return _instrumentArray;
- }
- - (NSMutableArray *)videoArray {
- if (!_videoArray) {
- _videoArray = [NSMutableArray array];
- }
- return _videoArray;
- }
- - (NSMutableArray *)videoPageArray {
- if (!_videoPageArray) {
- _videoPageArray = [NSMutableArray array];
- }
- return _videoPageArray;
- }
- - (void)hudTipWillShow:(BOOL)willShow{
- if (willShow) {
- [self resignFirstResponder];
- UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
- if (!_HUD) {
- _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
- _HUD.removeFromSuperViewOnHide = YES;
- _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
- _HUD.label.text = @"正在上传视频文件...";
- _HUD.contentColor = [UIColor whiteColor];
- _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- _HUD.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8);
- }else{
- _HUD.progress = 0;
- [keyWindow addSubview:_HUD];
- [_HUD showAnimated:YES];
- }
- }else{
- [_HUD hideAnimated:YES];
- }
- }
- - (MyStyleEditHeadView *)infoHeadView {
- if (!_infoHeadView) {
- _infoHeadView = [MyStyleEditHeadView shareInstance];
- MJWeakSelf;
- [_infoHeadView modifyCallback:^(MODIFY_TYPE type, NSString * _Nullable sexType) {
- [weakSelf modifyUserAction:type sexType:sexType];
- }];
- }
- return _infoHeadView;
- }
- - (void)modifyUserAction:(MODIFY_TYPE)type sexType:(NSString *)sexType {
- switch (type) {
- case MODIFY_TYPE_AVATAR:
- {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = YES;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- UIImage *sendImg = [imageArray lastObject];
- weakSelf.isModifyAvatal = YES;
- // 跳转到裁剪功能
- RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:sendImg cropMode:RSKImageCropModeSquare];
- imageCropVC.avoidEmptySpaceAroundImage = YES;
- imageCropVC.rotationEnabled = YES;
- imageCropVC.delegate = weakSelf;
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
- navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
- [weakSelf.navigationController presentViewController:navCtrl animated:YES completion:nil];
- }];
- [self.mediaManager pushImagePickerController];
- }
- break;
- case MODIFY_TYPE_NICKNAME:
- {
- ModifyNameViewController *nameCtrl = [[ModifyNameViewController alloc] init];
- nameCtrl.preNickName = self.mineInfo.username;
- [self.navigationController pushViewController:nameCtrl animated:YES];
- }
- break;
- case MODIFY_TYPE_AUTH:
- {
- if (USER_MANAGER.hasAuth == NO) {
- UserAuthViewController *ctrl = [[UserAuthViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- break;
- case MODIFY_TYPE_PHONE:
- {
- ModifyPhoneCheckController *checkCtrl = [[ModifyPhoneCheckController alloc] init];
- [self.navigationController pushViewController:checkCtrl animated:YES];
- }
- break;
- case MODIFY_TYPE_SEX:
- {
- if ([sexType integerValue] == self.mineInfo.gender || sexType == nil) {
- return;
- }
- [self modifyUserMessage:nil gender:sexType];
- }
- break;
- default:
- break;
- }
- }
- - (void)updateWithUserLogo:(UIImage *)image {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- NSString *fileName = @"image";
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *avatarUrl = [fileUrlArray lastObject];
- [self modifyUserMessage:avatarUrl gender:nil];
- } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- - (void)modifyUserMessage:(NSString *)imgUrl gender:(NSString *)gender {
- NSString *userName = nil;
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager modifyTeacherMessage:KS_POST avatal:imgUrl gender:gender username:userName success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"修改成功"];
- if (![NSString isEmptyString:imgUrl]) {
- UserDefaultSetObjectForKey(imgUrl, AvatarUrlKey);
- }
- [self requestUserMessage];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- #pragma mark --- RSKImageCropViewControllerDelegate
- - (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller {
- CGFloat width = (KPortraitWidth - 40);
- // CGFloat height = width / 16 * 9;
- CGFloat height = width;
- return CGRectMake(20, (KPortraitHeight - height) / 2.0f, width, height);
- }
- - (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller {
- //返回裁剪框的位置
- CGFloat width = (KPortraitWidth - 40);
- // CGFloat height = width / 16 * 9;
- CGFloat height = width;
- UIBezierPath *path=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, (KPortraitHeight - height) / 2.0f, width, height) cornerRadius:0];
- return path;
- }
- /**
- 返回一个图片可以移动的矩形区域
- 仅在RSKImageCropModeCustom下有效
- 如果你想支持图片旋转,则必须实现该方法
- */
- - (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
- {
- return controller.maskRect;
- }
- /**
- 通知 delegate 取消裁剪图像。
- */
- - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller {
- self.zh_statusBarHidden = NO;
- if (self.isModifyAvatal) {
- self.isModifyAvatal = NO;
- }
- [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- /**
- 通知 delegate 原始图像已经被裁剪。此外,还提供了一个裁剪矩形和用于生成图像的旋转角度。
- */
- - (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {
- // croppedImage
- self.zh_statusBarHidden = NO;
- if (self.isModifyAvatal) {
- self.isModifyAvatal = NO;
- [self updateWithUserLogo:croppedImage];
- }
- else {
- self.hasModify = YES;
- [self uploadImage:croppedImage index:self.chooseFileIndex];
- }
-
- [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- /*
- #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
|