MinePageViewController.m 19 KB

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