MinePageViewController.m 17 KB

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