MyStyleViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. //
  2. // MyStyleViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/11.
  6. //
  7. #import "MyStyleViewController.h"
  8. #import "MyStyleInstrumentCell.h"
  9. #import "MyStyleIntroduceCell.h"
  10. #import "MyStyleVideoCell.h"
  11. #import "InstrumentChooseViewController.h"
  12. #import "KSMediaManager.h"
  13. #import "StyleVideoModel.h"
  14. #import "WMPlayer.h"
  15. #import "KSVideoHelper.h"
  16. #import <RSKImageCropper/RSKImageCropper.h>
  17. #import "CustomNavViewController.h"
  18. #import "MinePageGroupModel.h"
  19. #import "MyStyleNavView.h"
  20. #import "UserInfoManager.h"
  21. #import "MyCreateGroupHeadView.h"
  22. #import "MyStyleEditHeadView.h"
  23. #import "CreateFansGroupViewController.h"
  24. #import "ModifyPhoneCheckController.h"
  25. #import "UserAuthViewController.h"
  26. #import "ModifyNameViewController.h"
  27. #import "LiveRoomAlertView.h"
  28. @interface MyStyleViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate,RSKImageCropViewControllerDelegate,RSKImageCropViewControllerDataSource>
  29. {
  30. WMPlayer *_wmPlayer;
  31. CGRect _playerFrame;
  32. }
  33. @property (nonatomic, strong) MyStyleNavView *navView;
  34. @property (nonatomic, strong) UIView *bgView;
  35. @property (nonatomic, assign) BOOL isRatation;
  36. @property (nonatomic, strong) NSMutableArray *instrumentArray;
  37. @property (nonatomic, strong) NSMutableArray *videoArray;
  38. @property (nonatomic, strong) NSMutableArray *videoPageArray;
  39. @property (nonatomic, strong) NSString *content;
  40. @property (nonatomic, strong) UITableView *tableView;
  41. @property (nonatomic, strong) KSMediaManager *mediaManager;
  42. @property (strong, nonatomic) MBProgressHUD *HUD;
  43. @property (nonatomic, assign) NSInteger chooseFileIndex;
  44. @property (nonatomic, assign) BOOL hasModifyVideoImage;
  45. @property (nonatomic, strong) NSMutableArray *fansGroupArray;
  46. @property (nonatomic, strong) UserInfo *mineInfo;
  47. @property (nonatomic, strong) MyStyleEditHeadView *infoHeadView;
  48. @property (nonatomic, assign) BOOL hasModify;
  49. /// 提示窗
  50. @property (nonatomic, strong) LiveRoomAlertView *alertView;
  51. @property (nonatomic, assign) BOOL isModifyAvatal;
  52. @end
  53. @implementation MyStyleViewController
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. // Do any additional setup after loading the view.
  57. self.ks_prefersNavigationBarHidden = YES;
  58. [self configUI];
  59. [self requestMyStyle];
  60. [self countUMEvent];
  61. }
  62. - (void)countUMEvent {
  63. [USER_MANAGER sendUMEvent:@"klx_styleEdit"];
  64. }
  65. - (void)viewWillAppear:(BOOL)animated {
  66. [super viewWillAppear:animated];
  67. [self requestUserMessage];
  68. }
  69. - (void)configUI {
  70. [self.scrollView removeFromSuperview];
  71. [self.view addSubview:self.navView];
  72. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.right.top.mas_equalTo(self.view);
  74. make.height.mas_equalTo(kNaviBarHeight);
  75. }];
  76. [self.view addSubview:self.tableView];
  77. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.mas_equalTo(self.navView.mas_bottom);
  79. make.left.right.mas_equalTo(self.view);
  80. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  81. }];
  82. }
  83. - (void)requestUserMessage {
  84. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  85. self.mineInfo = userInfo;
  86. [self refreshMineInfo];
  87. }];
  88. }
  89. - (void)refreshMineInfo {
  90. [self.infoHeadView configUserMessage:self.mineInfo];
  91. }
  92. - (void)requestMyStyle {
  93. [self showhud];
  94. [KSNetworkingManager queryTeacherStyleRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  95. [self removehub];
  96. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  97. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  98. NSString *subjectIds = [result stringValueForKey:@"subjectId"];
  99. NSString *subjectNames = [result stringValueForKey:@"subjectName"];
  100. [self configWithSubjectMessage:subjectIds subjectName:subjectNames];
  101. // introduction
  102. self.content = [result stringValueForKey:@"introduction"];
  103. NSArray *videoList = [result arrayValueForKey:@"styleVideo"];
  104. [self.videoArray removeAllObjects];
  105. for (NSDictionary *parm in videoList) {
  106. StyleVideoModel *model = [[StyleVideoModel alloc] initWithDictionary:parm];
  107. [self.videoArray addObject:model];
  108. }
  109. }
  110. else {
  111. [self MBPShow:MESSAGEKEY];
  112. }
  113. [self.tableView reloadData];
  114. } faliure:^(NSError * _Nonnull error) {
  115. [self removehub];
  116. }];
  117. }
  118. - (void)configWithSubjectMessage:(NSString *)subjectId subjectName:(NSString *)subjectName {
  119. if (![NSString isEmptyString:subjectId] && ![NSString isEmptyString:subjectName]) {
  120. NSArray *subjectIdArray = [subjectId componentsSeparatedByString:@","];
  121. NSArray *subjectNameArray = [subjectName componentsSeparatedByString:@","];
  122. NSInteger count = subjectNameArray.count > subjectIdArray.count ? subjectIdArray.count : subjectNameArray.count;
  123. NSMutableArray *subjectArray = [NSMutableArray array];
  124. for (NSInteger i = 0; i < count; i++) {
  125. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  126. [parm setValue:subjectIdArray[i] forKey:@"subjectId"];
  127. [parm setValue:subjectNameArray[i] forKey:@"subjectName"];
  128. [subjectArray addObject:parm];
  129. }
  130. self.instrumentArray = [NSMutableArray arrayWithArray:subjectArray];
  131. }
  132. }
  133. - (void)submitMyStyle {
  134. [self.view endEditing:YES];
  135. if (self.instrumentArray.count <= 0) {
  136. [self MBPShow:@"至少选择一个可教授乐器"];
  137. return;
  138. }
  139. BOOL hasEmptyCover = NO;
  140. for (StyleVideoModel *model in self.videoArray) {
  141. if ([NSString isEmptyString:model.cover]) {
  142. hasEmptyCover = YES;
  143. break;
  144. }
  145. }
  146. if (hasEmptyCover) {
  147. [self MBPShow:@"请上传视频封面图"];
  148. return;
  149. }
  150. NSMutableArray *subjectIdArray = [NSMutableArray array];
  151. NSMutableArray *subjectNameArray = [NSMutableArray array];
  152. for (NSDictionary *parm in self.instrumentArray) {
  153. [subjectIdArray addObject:[parm stringValueForKey:@"subjectId"]];
  154. [subjectNameArray addObject:[parm stringValueForKey:@"subjectName"]];
  155. }
  156. NSString *subjectIds = [subjectIdArray componentsJoinedByString:@","];
  157. NSString *subjectNames = [subjectNameArray componentsJoinedByString:@","];
  158. NSMutableArray *videoArray = [NSMutableArray array];
  159. BOOL hasNewVideoSubmit = NO;
  160. for (StyleVideoModel *model in self.videoArray) {
  161. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  162. if (model.isChooseVideo) {
  163. hasNewVideoSubmit = YES;
  164. [parm setValue:model.videoUrl forKey:@"videoUrl"];
  165. [parm setValue:model.cover forKey:@"cover"];
  166. }
  167. else {
  168. [parm setValue:model.internalBaseClassIdentifier forKey:@"id"];
  169. [parm setValue:model.cover forKey:@"cover"];
  170. [parm setValue:model.videoUrl forKey:@"videoUrl"];
  171. }
  172. [videoArray addObject:parm];
  173. }
  174. [self showhud];
  175. [KSNetworkingManager saveTeacherStyleRequest:KS_POST styleVideo:videoArray subjectId:subjectIds subjectName:subjectNames introduction:self.content success:^(NSDictionary * _Nonnull dic) {
  176. [self removehub];
  177. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  178. self.hasModify = NO;
  179. MJWeakSelf;
  180. NSString *descMessage = (hasNewVideoSubmit || self.hasModifyVideoImage) ? @"提交成功,请耐心等待审核" : @"保存成功";
  181. [self KSShowMsg:descMessage promptCompletion:^{
  182. [weakSelf backAction];
  183. }];
  184. }
  185. else {
  186. [self MBPShow:MESSAGEKEY];
  187. }
  188. } faliure:^(NSError * _Nonnull error) {
  189. [self removehub];
  190. }];
  191. }
  192. #pragma mark ---- table data source
  193. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  194. return 1;
  195. }
  196. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  197. return 3;
  198. }
  199. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  200. return [MyStyleEditHeadView getViewHeight];
  201. }
  202. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  203. return CGFLOAT_MIN;
  204. }
  205. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  206. return self.infoHeadView;
  207. }
  208. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  209. return [UIView new];
  210. }
  211. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  212. if (indexPath.row == 0) {
  213. MyStyleInstrumentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleInstrumentCell"];
  214. MJWeakSelf;
  215. [cell configWithSource:self.instrumentArray callback:^(STYLE_INSTRUMENT type, NSMutableArray * _Nullable sourceArray) {
  216. if (type == STYLE_INSTRUMENT_CHOOSE) {
  217. [weakSelf chooseInstrumentWithArray:sourceArray];
  218. }
  219. else { // 刷新
  220. weakSelf.hasModify = YES;
  221. [weakSelf refreshInstrumentPart:sourceArray];
  222. }
  223. }];
  224. return cell;
  225. }
  226. else if (indexPath.row == 1) {
  227. MyStyleIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleIntroduceCell"];
  228. MJWeakSelf;
  229. [cell configWithIntroduceMessage:self.content modifyCallback:^(NSString * _Nullable content) {
  230. weakSelf.hasModify = YES;
  231. weakSelf.content = content;
  232. }];
  233. return cell;
  234. }
  235. else {
  236. MyStyleVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyStyleVideoCell"];
  237. [cell configWithSource:self.videoArray];
  238. MJWeakSelf;
  239. [cell opreationCallback:^(STYLEVIDEO type, UIView * _Nullable containerView) {
  240. [weakSelf opreationVideoCell:type container:containerView];
  241. }];
  242. return cell;
  243. }
  244. }
  245. - (void)opreationVideoCell:(STYLEVIDEO)type container:(UIView *)container {
  246. switch (type) {
  247. case STYLEVIDEO_CHOOSEFILE:
  248. {
  249. // 调用相册
  250. self.mediaManager = [[KSMediaManager alloc] init];
  251. self.mediaManager.mediaType = MEDIATYPE_VIDEO;
  252. self.mediaManager.maxPhotoNumber = 1;
  253. self.mediaManager.baseCtrl = self;
  254. self.mediaManager.needCropImage = NO;
  255. MJWeakSelf;
  256. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  257. NSLog(@"%@", videoUrl);
  258. weakSelf.hasModify = YES;
  259. [weakSelf uploadVideoWithUrl:videoUrl coverUrl:nil];
  260. }];
  261. [self.mediaManager pushImagePickerController];
  262. }
  263. break;
  264. case STYLEVIDEO_PLAY: // 播放
  265. {
  266. NSInteger index = container.tag - 1000;
  267. if (self.videoArray.count > index) {
  268. StyleVideoModel *model = self.videoArray[index];
  269. [self playVideoWithUrl:model.videoUrl];
  270. }
  271. }
  272. break;
  273. case STYLEVIDEO_DELETE: // 删除
  274. {
  275. NSInteger index = container.tag - 1000;
  276. if (self.videoArray.count > index) {
  277. if ([self canDeleteVideoIndex:index]) {
  278. self.hasModify = YES;
  279. [self.videoArray removeObjectAtIndex:index];
  280. }
  281. else {
  282. [self MBPShow:@"需至少保留一个通过审核风采视频"];
  283. }
  284. }
  285. [self.tableView reloadData];
  286. }
  287. break;
  288. case STYLEVIDEO_CHOOSEIMAGE: // 选择图片
  289. {
  290. NSInteger index = container.tag - 1000;
  291. // 调用相册
  292. self.mediaManager = [[KSMediaManager alloc] init];
  293. self.mediaManager.mediaType = MEDIATYPE_PHOTO;
  294. self.mediaManager.maxPhotoNumber = 1;
  295. self.mediaManager.baseCtrl = self;
  296. self.mediaManager.needCropImage = NO;
  297. MJWeakSelf;
  298. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  299. // 裁剪
  300. weakSelf.hasModifyVideoImage = YES;
  301. [weakSelf cropImage:[imageArray lastObject] fileIndex:index];
  302. }];
  303. [self.mediaManager pushImagePickerController];
  304. }
  305. break;
  306. default:
  307. break;
  308. }
  309. }
  310. - (void)cropImage:(UIImage *)image fileIndex:(NSInteger)index {
  311. // 上传图片
  312. self.chooseFileIndex = index;
  313. // 跳转到裁剪功能
  314. RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:image cropMode:RSKImageCropModeCustom];
  315. imageCropVC.avoidEmptySpaceAroundImage = YES;
  316. imageCropVC.rotationEnabled = YES;
  317. imageCropVC.delegate = self;
  318. imageCropVC.dataSource = self;
  319. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
  320. navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  321. [self.navigationController presentViewController:navCtrl animated:YES completion:nil];
  322. }
  323. - (BOOL)canDeleteVideoIndex:(NSInteger)index {
  324. NSInteger passVideoCount = 0;
  325. if (self.videoArray.count > index) {
  326. StyleVideoModel *videoSource = self.videoArray[index];
  327. for (StyleVideoModel *model in self.videoArray) {
  328. if ([model.authStatus isEqualToString:@"PASS"]) {
  329. passVideoCount++;
  330. }
  331. }
  332. if (passVideoCount > 1) {
  333. return YES;
  334. }
  335. else if (passVideoCount == 1) {
  336. if ([videoSource.authStatus isEqualToString:@"PASS"]) {
  337. return NO;
  338. }
  339. else {
  340. return YES;
  341. }
  342. }
  343. }
  344. return YES;
  345. }
  346. - (void)uploadImage:(UIImage *)firstImage index:(NSInteger)index {
  347. // 上传图片
  348. NSData *imgData = [UIImage compressImage:firstImage maxLength:5];
  349. NSString *fileName = @"styleImage";
  350. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  351. [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  352. NSString *imageUrl = [fileUrlArray lastObject];
  353. if (self.videoArray.count > index) {
  354. StyleVideoModel *model = self.videoArray[index];
  355. model.cover = imageUrl;
  356. [self.tableView reloadData];
  357. }
  358. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  359. if ([NSString isEmptyString:descMessaeg]) {
  360. [self MBPShow:descMessaeg];
  361. }
  362. }];
  363. }
  364. - (void)uploadUrlAndGetImagePath:(NSString *)videoUrl {
  365. [KSVideoHelper getLocalVideoPreViewUrlWithPath:videoUrl callback:^(UIImage * _Nullable firstImage) {
  366. if (firstImage) {
  367. // 上传图片
  368. NSData *imgData = [UIImage compressImage:firstImage maxLength:5];
  369. NSString *fileName = @"styleImage";
  370. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  371. [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  372. NSString *imageUrl = [fileUrlArray lastObject];
  373. [self uploadVideoWithUrl:videoUrl coverUrl:imageUrl];
  374. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  375. if ([NSString isEmptyString:descMessaeg]) {
  376. [self MBPShow:descMessaeg];
  377. }
  378. }];
  379. }
  380. else {
  381. // 如果没有直接上传图片
  382. [self uploadVideoWithUrl:videoUrl coverUrl:nil];
  383. }
  384. }];
  385. }
  386. #pragma mark --- 上传视频文件
  387. - (void)uploadVideoWithUrl:(NSString *)videoUrl coverUrl:(NSString *)coverUrl {
  388. [self hudTipWillShow:YES];
  389. NSURL *fileUrl = [NSURL fileURLWithPath:videoUrl];
  390. NSData *fileData = [NSData dataWithContentsOfURL:fileUrl];
  391. NSString *suffix = [NSString stringWithFormat:@".%@",[fileUrl pathExtension]];
  392. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  393. [[KSUploadManager shareInstance] videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
  394. dispatch_main_async_safe(^{
  395. // 显示进度
  396. if (self.HUD) {
  397. self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
  398. }
  399. });
  400. } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  401. [self hudTipWillShow:NO];
  402. NSString *fileUrl = [fileUrlArray lastObject];
  403. // 删除文件
  404. [self removeVideoWithPath:videoUrl];
  405. StyleVideoModel *model = [[StyleVideoModel alloc] init];
  406. model.videoUrl = fileUrl;
  407. model.isChooseVideo = YES;
  408. model.cover = coverUrl;
  409. [self.videoArray addObject:model];
  410. [self.tableView reloadData];
  411. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  412. [self hudTipWillShow:NO];
  413. if ([NSString isEmptyString:descMessaeg]) {
  414. [self MBPShow:descMessaeg];
  415. }
  416. }];
  417. }
  418. - (void)removeVideoWithPath:(NSString *)videoUrl {
  419. NSFileManager *fileMamager = [NSFileManager defaultManager];
  420. if ([fileMamager fileExistsAtPath:videoUrl]) {
  421. [fileMamager removeItemAtPath:videoUrl error:nil];
  422. }
  423. }
  424. - (void)chooseInstrumentWithArray:(NSMutableArray *)instrumentArray {
  425. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  426. ctrl.preChooseArray = instrumentArray;
  427. MJWeakSelf;
  428. [ctrl chooseCallback:^(NSMutableArray *chooseArray) {
  429. weakSelf.hasModify = YES;
  430. [weakSelf refreshInstrumentPart:chooseArray];
  431. }];
  432. [self.navigationController pushViewController:ctrl animated:YES];
  433. }
  434. - (void)refreshInstrumentPart:(NSMutableArray *)chooseArray {
  435. self.instrumentArray = [NSMutableArray arrayWithArray:chooseArray];
  436. [self.tableView reloadData];
  437. }
  438. #pragma mark ------ WMPlayer
  439. - (void)playVideoWithUrl:(NSString *)fileUrl {
  440. fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  441. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  442. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  443. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  444. playModel.videoURL = [NSURL URLWithString:fileUrl];
  445. _wmPlayer.playerModel = playModel;
  446. _wmPlayer.delegate = self;
  447. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  448. _bgView.backgroundColor = [UIColor blackColor];
  449. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  450. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  451. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  452. [_wmPlayer play];
  453. }
  454. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  455. [wmplayer removePlayer];
  456. [_bgView removeFromSuperview];
  457. [self setNeedsStatusBarAppearanceUpdate];
  458. }
  459. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  460. self.isRatation = !self.isRatation;
  461. if (self.isRatation) {
  462. [wmplayer removeFromSuperview];
  463. [UIView animateWithDuration:1.0f animations:^{
  464. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  465. } completion:^(BOOL finished) {
  466. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  467. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  468. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  469. }];
  470. }
  471. else {
  472. [wmplayer removeFromSuperview];
  473. [UIView animateWithDuration:1.0f animations:^{
  474. // 复原
  475. wmplayer.transform = CGAffineTransformIdentity;
  476. } completion:^(BOOL finished) {
  477. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  478. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  479. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  480. }];
  481. }
  482. }
  483. #pragma mark ---- lazying
  484. - (MyStyleNavView *)navView {
  485. if (!_navView) {
  486. _navView = [MyStyleNavView shareInstance];
  487. MJWeakSelf;
  488. [_navView saveStyleAction:^(BOOL isBack) {
  489. if (isBack) {
  490. [weakSelf backAction];
  491. }
  492. else {
  493. [weakSelf submitMyStyle];
  494. }
  495. }];
  496. }
  497. return _navView;
  498. }
  499. - (void)backAction {
  500. [self.view endEditing:YES];
  501. // 根据需要返回到不同页面
  502. if (self.hasModify) {
  503. self.alertView = [LiveRoomAlertView liveroomAlertWithTitle:@"您尚未保存修改信息,返回后将取消修改" leftButtonTitle:@"取消" rightTitle:@"确认" inView:self.view cancel:^{
  504. } confirm:^{
  505. [self.navigationController popViewControllerAnimated:YES];
  506. }];
  507. }
  508. else {
  509. [self.navigationController popViewControllerAnimated:YES];
  510. }
  511. }
  512. - (UITableView *)tableView {
  513. if (!_tableView) {
  514. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  515. _tableView.delegate = self;
  516. _tableView.dataSource = self;
  517. _tableView.backgroundColor = [UIColor clearColor];
  518. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  519. _tableView.showsHorizontalScrollIndicator = NO;
  520. _tableView.showsVerticalScrollIndicator = NO;
  521. _tableView.rowHeight = UITableViewAutomaticDimension;
  522. _tableView.estimatedRowHeight = 150.0f;
  523. [_tableView registerNib:[UINib nibWithNibName:@"MyStyleInstrumentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleInstrumentCell"];
  524. [_tableView registerNib:[UINib nibWithNibName:@"MyStyleIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleIntroduceCell"];
  525. [_tableView registerNib:[UINib nibWithNibName:@"MyStyleVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyStyleVideoCell"];
  526. [_tableView registerNib:[UINib nibWithNibName:@"MineFansGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineFansGroupCell"];
  527. }
  528. return _tableView;
  529. }
  530. - (NSMutableArray *)instrumentArray {
  531. if (!_instrumentArray) {
  532. _instrumentArray = [NSMutableArray array];
  533. }
  534. return _instrumentArray;
  535. }
  536. - (NSMutableArray *)videoArray {
  537. if (!_videoArray) {
  538. _videoArray = [NSMutableArray array];
  539. }
  540. return _videoArray;
  541. }
  542. - (NSMutableArray *)videoPageArray {
  543. if (!_videoPageArray) {
  544. _videoPageArray = [NSMutableArray array];
  545. }
  546. return _videoPageArray;
  547. }
  548. - (void)hudTipWillShow:(BOOL)willShow{
  549. if (willShow) {
  550. [self resignFirstResponder];
  551. UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
  552. if (!_HUD) {
  553. _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
  554. _HUD.removeFromSuperViewOnHide = YES;
  555. _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
  556. _HUD.label.text = @"正在上传视频文件...";
  557. _HUD.contentColor = [UIColor whiteColor];
  558. _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  559. _HUD.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  560. }else{
  561. _HUD.progress = 0;
  562. [keyWindow addSubview:_HUD];
  563. [_HUD showAnimated:YES];
  564. }
  565. }else{
  566. [_HUD hideAnimated:YES];
  567. }
  568. }
  569. - (MyStyleEditHeadView *)infoHeadView {
  570. if (!_infoHeadView) {
  571. _infoHeadView = [MyStyleEditHeadView shareInstance];
  572. MJWeakSelf;
  573. [_infoHeadView modifyCallback:^(MODIFY_TYPE type, NSString * _Nullable sexType) {
  574. [weakSelf modifyUserAction:type sexType:sexType];
  575. }];
  576. }
  577. return _infoHeadView;
  578. }
  579. - (void)modifyUserAction:(MODIFY_TYPE)type sexType:(NSString *)sexType {
  580. switch (type) {
  581. case MODIFY_TYPE_AVATAR:
  582. {
  583. // 调用相册
  584. self.mediaManager = [[KSMediaManager alloc] init];
  585. self.mediaManager.mediaType = MEDIATYPE_PHOTO;
  586. self.mediaManager.maxPhotoNumber = 1;
  587. self.mediaManager.baseCtrl = self;
  588. self.mediaManager.needCropImage = YES;
  589. MJWeakSelf;
  590. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  591. UIImage *sendImg = [imageArray lastObject];
  592. weakSelf.isModifyAvatal = YES;
  593. // 跳转到裁剪功能
  594. RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:sendImg cropMode:RSKImageCropModeSquare];
  595. imageCropVC.avoidEmptySpaceAroundImage = YES;
  596. imageCropVC.rotationEnabled = YES;
  597. imageCropVC.delegate = weakSelf;
  598. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
  599. navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  600. [weakSelf.navigationController presentViewController:navCtrl animated:YES completion:nil];
  601. }];
  602. [self.mediaManager pushImagePickerController];
  603. }
  604. break;
  605. case MODIFY_TYPE_NICKNAME:
  606. {
  607. ModifyNameViewController *nameCtrl = [[ModifyNameViewController alloc] init];
  608. nameCtrl.preNickName = self.mineInfo.username;
  609. [self.navigationController pushViewController:nameCtrl animated:YES];
  610. }
  611. break;
  612. case MODIFY_TYPE_AUTH:
  613. {
  614. if (USER_MANAGER.hasAuth == NO) {
  615. UserAuthViewController *ctrl = [[UserAuthViewController alloc] init];
  616. [self.navigationController pushViewController:ctrl animated:YES];
  617. }
  618. }
  619. break;
  620. case MODIFY_TYPE_PHONE:
  621. {
  622. ModifyPhoneCheckController *checkCtrl = [[ModifyPhoneCheckController alloc] init];
  623. [self.navigationController pushViewController:checkCtrl animated:YES];
  624. }
  625. break;
  626. case MODIFY_TYPE_SEX:
  627. {
  628. if ([sexType isEqual:self.mineInfo.gender] || sexType == nil) {
  629. return;
  630. }
  631. [self modifyUserMessage:nil gender:sexType];
  632. }
  633. break;
  634. default:
  635. break;
  636. }
  637. }
  638. - (void)updateWithUserLogo:(UIImage *)image {
  639. NSData *imgData = [UIImage turnsImaegDataByImage:image];
  640. NSString *fileName = @"image";
  641. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  642. [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  643. NSString *avatarUrl = [fileUrlArray lastObject];
  644. [self modifyUserMessage:avatarUrl gender:nil];
  645. } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
  646. if ([NSString isEmptyString:descMessaeg]) {
  647. [self MBPShow:descMessaeg];
  648. }
  649. }];
  650. }
  651. - (void)modifyUserMessage:(NSString *)imgUrl gender:(NSString *)gender {
  652. NSString *userName = nil;
  653. [self showhud];
  654. [KSNetworkingManager modifyTeacherMessage:KS_POST avatal:imgUrl gender:gender username:userName success:^(NSDictionary * _Nonnull dic) {
  655. [self removehub];
  656. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  657. [self MBPShow:@"修改成功"];
  658. if (![NSString isEmptyString:imgUrl]) {
  659. UserDefaultSetObjectForKey(imgUrl, AvatarUrlKey);
  660. [self updateRongCloudUserInfo];
  661. }
  662. [self requestUserMessage];
  663. }
  664. else {
  665. [self MBPShow:MESSAGEKEY];
  666. }
  667. } faliure:^(NSError * _Nonnull error) {
  668. [self removehub];
  669. }];
  670. }
  671. - (void)updateRongCloudUserInfo {
  672. // 设置个人信息
  673. RCUserInfo *currentUserInfo =
  674. [[RCUserInfo alloc] initWithUserId:UserDefault(UIDKey) name:UserDefault(NicknameKey) portrait:UserDefault(AvatarUrlKey)];
  675. [RCIM sharedRCIM].currentUserInfo = currentUserInfo;
  676. [[RCIM sharedRCIM] clearGroupUserInfoCache];
  677. }
  678. #pragma mark --- RSKImageCropViewControllerDelegate
  679. - (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller {
  680. CGFloat width = (KPortraitWidth - 40);
  681. // CGFloat height = width / 16 * 9;
  682. CGFloat height = width;
  683. return CGRectMake(20, (KPortraitHeight - height) / 2.0f, width, height);
  684. }
  685. - (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller {
  686. //返回裁剪框的位置
  687. CGFloat width = (KPortraitWidth - 40);
  688. // CGFloat height = width / 16 * 9;
  689. CGFloat height = width;
  690. UIBezierPath *path=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, (KPortraitHeight - height) / 2.0f, width, height) cornerRadius:0];
  691. return path;
  692. }
  693. /**
  694. 返回一个图片可以移动的矩形区域
  695. 仅在RSKImageCropModeCustom下有效
  696. 如果你想支持图片旋转,则必须实现该方法
  697. */
  698. - (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
  699. {
  700. return controller.maskRect;
  701. }
  702. /**
  703. 通知 delegate 取消裁剪图像。
  704. */
  705. - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller {
  706. if (self.isModifyAvatal) {
  707. self.isModifyAvatal = NO;
  708. }
  709. [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
  710. }
  711. /**
  712. 通知 delegate 原始图像已经被裁剪。此外,还提供了一个裁剪矩形和用于生成图像的旋转角度。
  713. */
  714. - (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {
  715. // croppedImage
  716. if (self.isModifyAvatal) {
  717. self.isModifyAvatal = NO;
  718. [self updateWithUserLogo:croppedImage];
  719. }
  720. else {
  721. self.hasModify = YES;
  722. [self uploadImage:croppedImage index:self.chooseFileIndex];
  723. }
  724. [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
  725. }
  726. /*
  727. #pragma mark - Navigation
  728. // In a storyboard-based application, you will often want to do a little preparation before navigation
  729. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  730. // Get the new view controller using [segue destinationViewController].
  731. // Pass the selected object to the new view controller.
  732. }
  733. */
  734. @end