MinePageViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. //
  2. // MinePageViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/29.
  6. //
  7. #import "MinePageViewController.h"
  8. #import "MinePageHeadView.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "MinePageVIPCourseView.h"
  12. #import "MinePageCourseView.h"
  13. #import "MinePageVideoView.h"
  14. #import "TeacherInfo.h"
  15. #import "UserInfoManager.h"
  16. #import "MinePageTopView.h"
  17. #import "BadgeIntroduceView.h"
  18. #import "MyStyleViewController.h"
  19. #import "JXCategoryIndicatorGradientLineView.h"
  20. #import "MinePageAccompanyCourseView.h"
  21. #define HEADER_HEIGHT (50)
  22. @interface MinePageViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  23. @property (nonatomic, strong) MinePageHeadView *headView;
  24. @property (nonatomic, assign) NSInteger selectedIndex;
  25. @property (nonatomic, strong) NSMutableArray *listViewArray;
  26. @property (nonatomic, strong) TeacherInfo *teacherInfo;
  27. @property (nonatomic, strong) MinePageTopView *topView;
  28. @property (nonatomic, strong) NSMutableArray *subjectList;
  29. @property (nonatomic, strong) BadgeIntroduceView *intruduceAlert;
  30. @end
  31. @implementation MinePageViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. self.ks_prefersNavigationBarHidden = YES;
  36. _titles = @[@"VIP定制课",@"趣纠课",@"直播课",@"视频课",@"乐谱"];
  37. [self configUI];
  38. [self countUMEvent];
  39. }
  40. - (void)countUMEvent {
  41. [USER_MANAGER sendUMEvent:@"klx_minePage"];
  42. }
  43. - (void)configUI {
  44. [self.scrollView removeFromSuperview];
  45. [self.view addSubview:self.headView];
  46. CGFloat headHeight = [self.headView getViewHeight];
  47. self.headView.frame = CGRectMake(0, 0, kScreenWidth, headHeight);
  48. CGFloat topHeight = kNaviBarHeight;
  49. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, topHeight, kScreenWidth, HEADER_HEIGHT)];
  50. _categoryView.backgroundColor = HexRGB(0xf8f9fc);
  51. self.categoryView.titles = self.titles;
  52. self.categoryView.delegate = self;
  53. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  54. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
  55. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  56. self.categoryView.titleColor = HexRGB(0x666666);
  57. self.categoryView.titleColorGradientEnabled = YES;
  58. JXCategoryIndicatorGradientLineView *lineView = [[JXCategoryIndicatorGradientLineView alloc] init];
  59. lineView.indicatorColor = [UIColor clearColor];
  60. [lineView configStartColor:HexRGB(0x2DC7AA) startPoint:CGPointMake(0.02, 1) endColor:HexRGBAlpha(0x2DC7AA, 0) endPoint:CGPointMake(1, 1)];
  61. lineView.indicatorHeight = 6.0f;
  62. lineView.verticalMargin = 15;
  63. self.categoryView.indicators = @[lineView];
  64. _pagerView = [self preferredPagingView];
  65. self.pagerView.frame = CGRectMake(0, topHeight, KPortraitWidth, KPortraitHeight - iPhoneXSafeBottomMargin - topHeight);
  66. self.pagerView.mainTableView.gestureDelegate = self;
  67. self.pagerView.backgroundColor = [UIColor clearColor];
  68. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  69. self.pagerView.listContainerView.backgroundColor = [UIColor clearColor];
  70. self.pagerView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
  71. [self.view addSubview:self.pagerView];
  72. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  73. }
  74. - (void)requestTeachMessage {
  75. [KSNetworkingManager queryTeacherInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  76. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  77. self.teacherInfo = [[TeacherInfo alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  78. [self refreshHeadView];
  79. }
  80. else {
  81. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  82. }
  83. } faliure:^(NSError * _Nonnull error) {
  84. }];
  85. }
  86. - (void)refreshHeadView {
  87. [self.topView configSource:self.teacherInfo];
  88. // 刷新达人认证和音乐人认证状态
  89. [self refreshAuthStatus];
  90. [self.headView.bgView sd_setImageWithURL:[NSURL URLWithString:[self.teacherInfo.heardUrl getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:TEACHER_AVATAR]];
  91. [self.pagerView reloadData];
  92. }
  93. - (void)refreshAuthStatus {
  94. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  95. id view = self.listViewArray[index];
  96. if ([view isKindOfClass:[MinePageCourseView class]]) {
  97. MinePageCourseView *courseView = (MinePageCourseView *)view;
  98. courseView.liveFlag = [self.teacherInfo.liveFlag isEqualToString:@"1"] ? YES : NO;
  99. courseView.teaherStatus = self.teacherInfo.entryStatus;
  100. }
  101. else if ([view isKindOfClass:[MinePageVideoView class]]) {
  102. MinePageVideoView *videoCourseView = (MinePageVideoView *)view;
  103. videoCourseView.teaherStatus = self.teacherInfo.entryStatus;
  104. }
  105. }
  106. }
  107. - (void)viewWillAppear:(BOOL)animated {
  108. [super viewWillAppear:animated];
  109. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  110. [self requestTeachMessage];
  111. [self requestSubjectList];
  112. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  113. id value = self.listViewArray[self.categoryView.selectedIndex];
  114. if ([value isKindOfClass:[MinePageCourseView class]]) {
  115. MinePageCourseView *listView = (MinePageCourseView *)value;
  116. [listView beginFirstRefresh];
  117. }
  118. else if ([value isKindOfClass:[MinePageAccompanyCourseView class]]) {
  119. MinePageAccompanyCourseView *listView = (MinePageAccompanyCourseView *)value;
  120. [listView beginFirstRefresh];
  121. }
  122. else if ([value isKindOfClass:[MinePageVIPCourseView class]]) {
  123. MinePageVIPCourseView *listView = (MinePageVIPCourseView *)value;
  124. [listView beginFirstRefresh];
  125. }
  126. else if ([value isKindOfClass:[kSJXCollectionView class]]) {
  127. MinePageVideoView *listView = (MinePageVideoView *)value;
  128. [listView beginFirstRefresh];
  129. }
  130. }
  131. [IQKeyboardManager sharedManager].enable = NO;
  132. }
  133. - (void)viewWillDisappear:(BOOL)animated {
  134. [super viewWillDisappear:animated];
  135. [IQKeyboardManager sharedManager].enable = YES;
  136. }
  137. - (void)viewDidAppear:(BOOL)animated {
  138. [super viewDidAppear:animated];
  139. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  140. }
  141. - (JXPagerView *)preferredPagingView {
  142. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  143. }
  144. - (void)requestSubjectList {
  145. [KSNetworkingManager querySubjectItemRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  146. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  147. NSArray *dataArray = [NSMutableArray array];
  148. dataArray = [dic ks_arrayValueForKey:@"data"];
  149. NSMutableArray *subjectArray = [NSMutableArray array];
  150. for (NSDictionary *parm in dataArray) {
  151. NSMutableDictionary *subjectSource = [NSMutableDictionary dictionary];
  152. [subjectSource setValue:[parm ks_stringValueForKey:@"id"] forKey:@"subjectId"];
  153. [subjectSource setValue:[parm ks_stringValueForKey:@"name"] forKey:@"subjectName"];
  154. [subjectArray addObject:subjectSource];
  155. }
  156. self.subjectList = [subjectArray mutableCopy];
  157. [self refreshSubjectMessage];
  158. }
  159. else{
  160. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  161. }
  162. } faliure:^(NSError * _Nonnull error) {
  163. }];
  164. }
  165. - (void)refreshSubjectMessage {
  166. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  167. id view = self.listViewArray[index];
  168. if ([view isKindOfClass:[MinePageCourseView class]]) {
  169. MinePageCourseView *courseView = (MinePageCourseView *)view;
  170. courseView.subjectList = [self.subjectList mutableCopy];
  171. }
  172. }
  173. }
  174. #pragma mark - JXPagerViewDelegate
  175. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  176. return self.topView;
  177. }
  178. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  179. NSUInteger topHeight = (NSUInteger)[self.topView getViewHeight:self.teacherInfo];
  180. return topHeight;
  181. }
  182. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  183. return HEADER_HEIGHT;
  184. }
  185. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  186. return self.categoryView;
  187. }
  188. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  189. //和categoryView的item数量一致
  190. return self.titles.count;
  191. }
  192. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  193. if (index == 0) { // VIP定制
  194. MinePageVIPCourseView *listView = [[MinePageVIPCourseView alloc] init];
  195. listView.naviController = self.navigationController;
  196. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  197. self.listViewArray[index] = listView;
  198. listView.selectIndex = index;
  199. [listView beginFirstRefresh];
  200. return listView;
  201. }
  202. else if (index == 1) { // 趣纠课
  203. MinePageAccompanyCourseView *listView = [[MinePageAccompanyCourseView alloc] init];
  204. listView.naviController = self.navigationController;
  205. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  206. self.listViewArray[index] = listView;
  207. listView.selectIndex = index;
  208. // if (self.teacherInfo) {
  209. // listView.teaherStatus = self.teacherInfo.entryStatus;
  210. // }
  211. // else {
  212. // listView.teaherStatus = @"PASS";
  213. // }
  214. [listView beginFirstRefresh];
  215. return listView;
  216. }
  217. else if (index == 2) { // 直播
  218. MinePageCourseView *listView = [[MinePageCourseView alloc] init];
  219. listView.naviController = self.navigationController;
  220. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  221. self.listViewArray[index] = listView;
  222. listView.selectIndex = index;
  223. if (self.teacherInfo) {
  224. listView.liveFlag = [self.teacherInfo.liveFlag isEqualToString:@"1"] ? YES : NO;
  225. listView.teaherStatus = self.teacherInfo.entryStatus;
  226. }
  227. else {
  228. listView.liveFlag = YES;
  229. listView.teaherStatus = @"PASS";
  230. }
  231. [listView beginFirstRefresh];
  232. return listView;
  233. }
  234. else if (index == 4) { // 乐谱
  235. MinePageCourseView *listView = [[MinePageCourseView alloc] init];
  236. listView.naviController = self.navigationController;
  237. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  238. self.listViewArray[index] = listView;
  239. listView.selectIndex = index;
  240. if (self.teacherInfo) {
  241. listView.teaherStatus = self.teacherInfo.entryStatus;
  242. }
  243. else {
  244. listView.teaherStatus = @"PASS";
  245. }
  246. if (self.subjectList) {
  247. listView.subjectList = [self.subjectList mutableCopy];
  248. }
  249. [listView beginFirstRefresh];
  250. return listView;
  251. }
  252. else { // 视频课
  253. MinePageVideoView *listView = [[MinePageVideoView alloc] init];
  254. listView.naviController = self.navigationController;
  255. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  256. self.listViewArray[index] = listView;
  257. listView.selectIndex = index;
  258. if (self.teacherInfo) {
  259. listView.teaherStatus = self.teacherInfo.entryStatus;
  260. }
  261. else {
  262. listView.teaherStatus = @"PASS";
  263. }
  264. [listView beginFirstRefresh];
  265. return listView;
  266. }
  267. }
  268. #pragma mark - JXCategoryViewDelegate
  269. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  270. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  271. if (self.listViewArray.count > index) {
  272. id value = self.listViewArray[index];
  273. if ([value isKindOfClass:[KSJXBodyView class]]) {
  274. KSJXBodyView *listView = (KSJXBodyView *)value;
  275. [listView beginFirstRefresh];
  276. }
  277. else if ([value isKindOfClass:[kSJXCollectionView class]]) {
  278. kSJXCollectionView *listView = (kSJXCollectionView *)value;
  279. [listView beginFirstRefresh];
  280. }
  281. }
  282. }
  283. #pragma mark - JXPagerMainTableViewGestureDelegate
  284. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  285. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  286. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  287. return NO;
  288. }
  289. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  290. }
  291. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  292. NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y);
  293. CGFloat height = [self.topView getViewHeight:self.teacherInfo];
  294. CGFloat space = scrollView.contentOffset.y;
  295. if (space > 100) {
  296. CGFloat rate = (space - 100) / (height - 100);
  297. NSLog(@"rate ---------%f",rate);
  298. self.headView.topView.backgroundColor = HexRGBAlpha(0xffffff, rate);
  299. if (rate == 1) {
  300. [self.headView.backImage setImage:[UIImage imageNamed:@"back_black"]];
  301. [self.headView.editImage setImage:[UIImage imageNamed:@"minePage_nav_edit_black"]];
  302. }
  303. else {
  304. [self.headView.backImage setImage:[UIImage imageNamed:@"back_white"]];
  305. [self.headView.editImage setImage:[UIImage imageNamed:@"minePage_nav_edit_black"]];
  306. }
  307. }
  308. else {
  309. self.headView.topView.backgroundColor = [UIColor clearColor];
  310. [self.headView.backImage setImage:[UIImage imageNamed:@"back_white"]];
  311. [self.headView.editImage setImage:[UIImage imageNamed:@"minePage_nav_edit_white"]];
  312. }
  313. }
  314. #pragma mark --- lazying
  315. - (MinePageHeadView *)headView {
  316. if (!_headView) {
  317. _headView = [MinePageHeadView shareInstance];
  318. MJWeakSelf;
  319. [_headView backAction:^(BOOL isBack) {
  320. if (isBack) {
  321. [weakSelf backAction];
  322. }
  323. else {
  324. [weakSelf editAction];
  325. }
  326. }];
  327. }
  328. return _headView;
  329. }
  330. - (NSMutableArray *)listViewArray {
  331. if (!_listViewArray) {
  332. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@""]];
  333. }
  334. return _listViewArray;
  335. }
  336. - (MinePageTopView *)topView {
  337. if (!_topView) {
  338. _topView = [MinePageTopView shareInstance];
  339. MJWeakSelf;
  340. [_topView badgeDetail:^(MINEPAGE_TOP topAction) {
  341. [weakSelf topAction:topAction];
  342. }];
  343. }
  344. return _topView;
  345. }
  346. - (void)topAction:(MINEPAGE_TOP)topAction {
  347. switch (topAction) {
  348. case MINEPAGE_TOP_STYLEVIDEO:
  349. {
  350. [self showStyleVideo];
  351. }
  352. break;
  353. case MINEPAGE_TOP_FANSGROUP:
  354. {
  355. [self showFansGroup];
  356. }
  357. break;
  358. case MINEPAGE_TOP_EDIT:
  359. {
  360. [self editAction];
  361. }
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. - (void)showStyleVideo {
  368. }
  369. - (void)showFansGroup {
  370. }
  371. - (void)editAction {
  372. MyStyleViewController *style = [[MyStyleViewController alloc] init];
  373. [self.navigationController pushViewController:style animated:YES];
  374. }
  375. - (BadgeIntroduceView *)intruduceAlert {
  376. if (!_intruduceAlert) {
  377. _intruduceAlert = [BadgeIntroduceView shareInstance];
  378. _intruduceAlert.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
  379. }
  380. return _intruduceAlert;
  381. }
  382. - (void)showDescAlert {
  383. [self.intruduceAlert showAlertInView:[NSObject getKeyWindow]];
  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