MyMusicViewController.m 16 KB

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