MyMusicViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. //
  2. // MyMusicViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/28.
  6. //
  7. #import "MyMusicViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "MyMusicBodyView.h"
  12. #import "TeacherInfo.h"
  13. #import "UserInfoManager.h"
  14. #import "MusicShareModel.h"
  15. #import "MusicShareDisplayView.h"
  16. #import "UIImage+KSScreenShot.h"
  17. #import "TZImageManager.h"
  18. #import "RecordCheckManager.h"
  19. #import "KSPremissionAlert.h"
  20. #import "KSUMShareManager.h"
  21. #import "MyMusicSearchView.h"
  22. #import "KSChoosePicker.h"
  23. #import "MyMusicNavView.h"
  24. #define HEADER_HEIGHT (50)
  25. #define SEARCH_HEIGHT (50)
  26. @interface MyMusicViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  27. @property (nonatomic, strong) MyMusicNavView *navView;
  28. @property (nonatomic, assign) NSInteger selectedIndex;
  29. @property (nonatomic, strong) NSMutableArray *listViewArray;
  30. @property (nonatomic, strong) TeacherInfo *teacherInfo;
  31. @property (nonatomic, strong) MusicShareDisplayView *shareView;
  32. @property (nonatomic, strong) MyMusicSearchView *searchView;
  33. @property (nonatomic, strong) NSMutableArray *subjectList;
  34. @property (nonatomic, strong) NSString *searchKey;
  35. @property (nonatomic, strong) NSString *subjectIds;
  36. @end
  37. @implementation MyMusicViewController
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. // Do any additional setup after loading the view.
  41. self.ks_prefersNavigationBarHidden = YES;
  42. _titles = @[@"已上架",@"审核中",@"审核失败",@"已下架"];
  43. [self configUI];
  44. [self countUMEvent];
  45. }
  46. - (void)countUMEvent {
  47. [USER_MANAGER sendUMEvent:@"klx_uploadMusic"];
  48. }
  49. - (void)configUI {
  50. [self.scrollView removeFromSuperview];
  51. self.view.backgroundColor = HexRGB(0xf6f8f9);
  52. [self.view addSubview:self.navView];
  53. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.right.top.mas_equalTo(self.view);
  55. make.height.mas_equalTo(kNaviBarHeight);
  56. }];
  57. [self.view addSubview:self.searchView];
  58. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.right.mas_equalTo(self.view);
  60. make.top.mas_equalTo(self.navView.mas_bottom);
  61. make.height.mas_equalTo(SEARCH_HEIGHT);
  62. }];
  63. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, SEARCH_HEIGHT + kNaviBarHeight, kScreenWidth, HEADER_HEIGHT)];
  64. self.categoryView.titles = self.titles;
  65. self.categoryView.delegate = self;
  66. self.categoryView.titleFont = [UIFont systemFontOfSize:17.0f];
  67. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightMedium];
  68. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  69. self.categoryView.titleColor = HexRGB(0x666666);
  70. self.categoryView.titleColorGradientEnabled = YES;
  71. self.categoryView.backgroundColor = [UIColor whiteColor];
  72. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  73. lineView.indicatorColor = THEMECOLOR;
  74. lineView.indicatorWidth = 16;
  75. lineView.indicatorHeight = 4.0f;
  76. self.categoryView.indicators = @[lineView];
  77. _pagerView = [self preferredPagingView];
  78. self.pagerView.frame = CGRectMake(0, SEARCH_HEIGHT + kNaviBarHeight, KPortraitWidth, KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin - SEARCH_HEIGHT);
  79. self.pagerView.backgroundColor = [UIColor clearColor];
  80. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  81. self.pagerView.listContainerView.backgroundColor = [UIColor clearColor];
  82. self.pagerView.mainTableView.gestureDelegate = self;
  83. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  84. self.pagerView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
  85. [self.view addSubview:self.pagerView];
  86. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  87. }
  88. - (void)shareButtonClick { // 获取分享数据
  89. [self showhud];
  90. [KSNetworkingManager queryMusicShareMessageRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  91. [self removehub];
  92. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  93. NSDictionary *resultDic = [dic ks_dictionaryValueForKey:@"data"];
  94. MusicShareModel *model = [[MusicShareModel alloc] initWithDictionary:resultDic];
  95. if (model.musicSheetCount == 0) {
  96. [self MBPShow:@"您还没有上架曲谱"];
  97. }
  98. else {
  99. [self displayShareViewWithSource:model];
  100. }
  101. }
  102. else {
  103. [self MBPShow:MESSAGEKEY];
  104. }
  105. } faliure:^(NSError * _Nonnull error) {
  106. [self removehub];
  107. }];
  108. }
  109. - (void)displayShareViewWithSource:(MusicShareModel *)model {
  110. self.shareView = [MusicShareDisplayView shareInstance];
  111. [self.shareView configWithSource:model];
  112. MJWeakSelf;
  113. [self.shareView shareActionCallback:^(SHARETYPE type) {
  114. UIImage *image = [UIImage getCurrentViewShot:weakSelf.shareView.containerView];
  115. if (type == SHARETYPE_SAVE) {
  116. [weakSelf savePicWithImage:image];
  117. }
  118. else {
  119. [weakSelf showShareUI:image];
  120. }
  121. }];
  122. [self.shareView showShareViewInView:self.view];
  123. }
  124. - (void)showShareUI:(UIImage *)image {
  125. [KSUMShareManager shareInstanceWithImage:image url:@"" shareTitle:@"" descMessage:@"" shareType:KSSHARETYPE_IMAGE showInView:self callback:^(BOOL isSuccess, NSString * _Nonnull descMessage) {
  126. if (isSuccess) {
  127. [self .shareView hideView];
  128. }
  129. else {
  130. }
  131. [self MBPShow:descMessage];
  132. }];
  133. }
  134. - (void)savePicWithImage:(UIImage *)image {
  135. // 判断相册权限
  136. PREMISSIONTYPE albumEnable = [RecordCheckManager checkPhotoLibraryPremissionAvaiable:NO showInView:nil];
  137. if (albumEnable == PREMISSIONTYPE_YES) { // 如果有权限
  138. [[TZImageManager manager] savePhotoWithImage:image completion:^(PHAsset *asset, NSError *error) {
  139. if (!error) {
  140. [self .shareView hideView];
  141. [self MBPShow:@"保存成功"];
  142. }
  143. else {
  144. [self MBPShow:@"保存图片失败"];
  145. }
  146. }];
  147. }
  148. else {
  149. if (albumEnable == PREMISSIONTYPE_NO) {
  150. [self showAlertWithMessage:@"请开启相册访问权限" type:CHECKDEVICETYPE_CAMREA];
  151. }
  152. }
  153. }
  154. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  155. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  156. } confirm:^{
  157. [self openSettingView];
  158. }];
  159. }
  160. - (void)openSettingView {
  161. if (@available(iOS 10, *)) {
  162. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  163. } else {
  164. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  165. }
  166. }
  167. - (void)viewWillAppear:(BOOL)animated {
  168. [super viewWillAppear:animated];
  169. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  170. [self requestTeachMessage];
  171. [self requestSubjectList];
  172. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  173. id value = self.listViewArray[self.categoryView.selectedIndex];
  174. if ([value isKindOfClass:[MyMusicBodyView class]]) {
  175. MyMusicBodyView *listView = (MyMusicBodyView *)value;
  176. [listView beginFirstRefresh];
  177. }
  178. }
  179. }
  180. - (void)requestTeachMessage {
  181. [KSNetworkingManager queryTeacherInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  182. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  183. self.teacherInfo = [[TeacherInfo alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  184. NSString *rongToken = UserDefault(RongTokenKey);
  185. if ([NSString isEmptyString:rongToken]) {
  186. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  187. }
  188. [self refreshHeadView];
  189. }
  190. else {
  191. [self MBPShow:MESSAGEKEY];
  192. }
  193. } faliure:^(NSError * _Nonnull error) {
  194. }];
  195. }
  196. - (void)refreshHeadView {
  197. // 刷新达人认证和音乐人认证状态
  198. [self refreshAuthStatus];
  199. }
  200. - (void)refreshAuthStatus {
  201. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  202. id view = self.listViewArray[index];
  203. if ([view isKindOfClass:[MyMusicBodyView class]]) {
  204. MyMusicBodyView *listView = (MyMusicBodyView *)view;
  205. listView.teaherStatus = self.teacherInfo.entryStatus;
  206. }
  207. }
  208. }
  209. - (void)requestSubjectList {
  210. [KSNetworkingManager querySubjectItemRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  211. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  212. NSArray *dataArray = [NSMutableArray array];
  213. dataArray = [dic ks_arrayValueForKey:@"data"];
  214. NSMutableArray *subjectArray = [NSMutableArray array];
  215. for (NSDictionary *parm in dataArray) {
  216. NSMutableDictionary *subjectSource = [NSMutableDictionary dictionary];
  217. [subjectSource setValue:[parm ks_stringValueForKey:@"id"] forKey:@"subjectId"];
  218. [subjectSource setValue:[parm ks_stringValueForKey:@"name"] forKey:@"subjectName"];
  219. [subjectArray addObject:subjectSource];
  220. }
  221. self.subjectList = [subjectArray mutableCopy];
  222. }
  223. else{
  224. [self MBPShow:MESSAGEKEY];
  225. }
  226. } faliure:^(NSError * _Nonnull error) {
  227. }];
  228. }
  229. - (void)viewDidAppear:(BOOL)animated {
  230. [super viewDidAppear:animated];
  231. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  232. }
  233. - (JXPagerView *)preferredPagingView {
  234. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  235. }
  236. #pragma mark - JXPagerViewDelegate
  237. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  238. return [UIView new];
  239. }
  240. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  241. return CGFLOAT_MIN;
  242. }
  243. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  244. return HEADER_HEIGHT;
  245. }
  246. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  247. return self.categoryView;
  248. }
  249. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  250. //和categoryView的item数量一致
  251. return self.titles.count;
  252. }
  253. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  254. MyMusicBodyView *listView = [[MyMusicBodyView alloc] init];
  255. listView.naviController = self.navigationController;
  256. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  257. self.listViewArray[index] = listView;
  258. listView.selectIndex = index;
  259. if (self.teacherInfo) {
  260. listView.teaherStatus = self.teacherInfo.entryStatus;
  261. }
  262. else {
  263. listView.teaherStatus = @"PASS";
  264. }
  265. listView.subjectIds = self.subjectIds;
  266. listView.searchKey = self.searchKey;
  267. [listView beginFirstRefresh];
  268. return listView;
  269. }
  270. #pragma mark - JXCategoryViewDelegate
  271. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  272. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  273. if (self.listViewArray.count > index) {
  274. id value = self.listViewArray[index];
  275. if ([value isKindOfClass:[KSJXBodyView class]]) {
  276. KSJXBodyView *listView = (KSJXBodyView *)value;
  277. [listView beginFirstRefresh];
  278. }
  279. }
  280. }
  281. #pragma mark - JXPagerMainTableViewGestureDelegate
  282. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  283. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  284. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  285. return NO;
  286. }
  287. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  288. }
  289. - (NSMutableArray *)listViewArray {
  290. if (!_listViewArray) {
  291. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@""]];
  292. }
  293. return _listViewArray;
  294. }
  295. - (MyMusicSearchView *)searchView {
  296. if (!_searchView) {
  297. _searchView = [MyMusicSearchView shareInstance];
  298. MJWeakSelf;
  299. [_searchView musicSearchAction:^(MYMUSICSORT type, NSString * _Nullable searchKey) {
  300. [weakSelf musicSearchAction:type searchKey:searchKey];
  301. }];
  302. }
  303. return _searchView;
  304. }
  305. - (void)musicSearchAction:(MYMUSICSORT)type searchKey:(NSString *)searchKey {
  306. switch (type) {
  307. case MYMUSICSORT_SUBJECT:
  308. {
  309. [self searchSubject];
  310. }
  311. break;
  312. case MYMUSICSORT_SEARCH:
  313. {
  314. [self evaluateSource:searchKey];
  315. }
  316. break;
  317. case MYMUSICSORT_UPLOAD:
  318. {
  319. [self uploadSong];
  320. }
  321. break;
  322. default:
  323. break;
  324. }
  325. }
  326. - (void)uploadSong {
  327. NSString *url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-upload"];
  328. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  329. webCtrl.url = url;
  330. [self.navigationController pushViewController:webCtrl animated:YES];
  331. }
  332. - (void)searchSubject {
  333. if (self.subjectList.count) {
  334. NSMutableArray *nameArray = [NSMutableArray array];
  335. [nameArray addObject:@"全部"];
  336. for (NSDictionary *parm in self.subjectList) {
  337. [nameArray addObject:[parm ks_stringValueForKey:@"subjectName"]];
  338. }
  339. MJWeakSelf;
  340. KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"声部筛选" sourceData:nameArray chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
  341. if (chooseIndex == 0) {
  342. weakSelf.searchView.subjectLabel.text = @"声部";
  343. weakSelf.subjectIds = nil;
  344. }
  345. else {
  346. NSDictionary *parm = self.subjectList[chooseIndex-1];
  347. weakSelf.searchView.subjectLabel.text = returnValue;
  348. weakSelf.subjectIds = [parm ks_stringValueForKey:@"subjectId"];
  349. }
  350. [weakSelf refreshSearchSource];
  351. } cancel:^{
  352. }];
  353. [picker showPicker];
  354. }
  355. else {
  356. [self MBPShow:@"无声部信息"];
  357. }
  358. }
  359. - (void)evaluateSource:(NSString *)searchKey {
  360. self.searchKey = searchKey;
  361. [self refreshSearchSource];
  362. }
  363. - (void)refreshSearchSource {
  364. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  365. id view = self.listViewArray[index];
  366. if ([view isKindOfClass:[MyMusicBodyView class]]) {
  367. MyMusicBodyView *courseView = (MyMusicBodyView *)view;
  368. courseView.subjectIds = self.subjectIds;
  369. courseView.searchKey = self.searchKey;
  370. [courseView beginFirstRefresh];
  371. }
  372. }
  373. }
  374. - (MyMusicNavView *)navView {
  375. if (!_navView) {
  376. _navView = [MyMusicNavView shareInstance];
  377. MJWeakSelf;
  378. [_navView musicNavAction:^(MUSICNAVACTION action) {
  379. if (action == MUSICNAVACTION_BACK) {
  380. [weakSelf backAction];
  381. }
  382. else {
  383. [weakSelf shareButtonClick];
  384. }
  385. }];
  386. }
  387. return _navView;
  388. }
  389. /*
  390. #pragma mark - Navigation
  391. // In a storyboard-based application, you will often want to do a little preparation before navigation
  392. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  393. // Get the new view controller using [segue destinationViewController].
  394. // Pass the selected object to the new view controller.
  395. }
  396. */
  397. @end