MyStyleViewController.m 32 KB

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