MyStyleViewController.m 31 KB

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