MinePageViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 "MinePageMienBodyView.h"
  12. #import "MinePageCourseView.h"
  13. #import "MinePageVideoView.h"
  14. #import "TeacherInfo.h"
  15. #import "UserInfoManager.h"
  16. #import "MinePageTopView.h"
  17. #define HEADER_HEIGHT (50)
  18. @interface MinePageViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  19. @property (nonatomic, strong) MinePageHeadView *headView;
  20. @property (nonatomic, assign) NSInteger selectedIndex;
  21. @property (nonatomic, strong) NSMutableArray *listViewArray;
  22. @property (nonatomic, strong) TeacherInfo *teacherInfo;
  23. @property (nonatomic, strong) MinePageTopView *topView;
  24. @property (nonatomic, strong) NSMutableArray *subjectList;
  25. @end
  26. @implementation MinePageViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. self.ks_prefersNavigationBarHidden = YES;
  31. _titles = @[@"个人风采",@"陪练课",@"直播课",@"视频课",@"乐谱"];
  32. [self configUI];
  33. }
  34. - (void)configUI {
  35. [self.scrollView removeFromSuperview];
  36. [self.view addSubview:self.headView];
  37. CGFloat headHeight = [self.headView getViewHeight];
  38. self.headView.frame = CGRectMake(0, 0, kScreenWidth, headHeight);
  39. CGFloat topHeight = kNaviBarHeight + 30;
  40. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, topHeight, kScreenWidth, HEADER_HEIGHT)];
  41. _categoryView.backgroundColor = [UIColor clearColor];
  42. self.categoryView.titles = self.titles;
  43. self.categoryView.delegate = self;
  44. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  45. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
  46. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  47. self.categoryView.titleColor = HexRGB(0x666666);
  48. self.categoryView.titleColorGradientEnabled = YES;
  49. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  50. lineView.indicatorColor = THEMECOLOR;
  51. lineView.indicatorWidth = 16;
  52. lineView.indicatorHeight = 4.0f;
  53. self.categoryView.indicators = @[lineView];
  54. _pagerView = [self preferredPagingView];
  55. self.pagerView.frame = CGRectMake(0, topHeight, kScreenWidth, kScreenHeight - iPhoneXSafeBottomMargin - topHeight);
  56. self.pagerView.mainTableView.gestureDelegate = self;
  57. self.pagerView.backgroundColor = [UIColor clearColor];
  58. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  59. self.pagerView.listContainerView.backgroundColor = [UIColor clearColor];
  60. self.pagerView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
  61. [self.view addSubview:self.pagerView];
  62. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  63. }
  64. - (void)requestTeachMessage {
  65. [KSNetworkingManager queryTeacherInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  66. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  67. self.teacherInfo = [[TeacherInfo alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  68. NSString *rongToken = UserDefault(RongTokenKey);
  69. if ([NSString isEmptyString:rongToken]) {
  70. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  71. }
  72. [self refreshHeadView];
  73. }
  74. else {
  75. [self MBPShow:MESSAGEKEY];
  76. }
  77. } faliure:^(NSError * _Nonnull error) {
  78. }];
  79. }
  80. - (void)refreshHeadView {
  81. [self.topView configSource:self.teacherInfo];
  82. // 刷新老师认证和音乐人认证状态
  83. [self refreshAuthStatus];
  84. }
  85. - (void)refreshAuthStatus {
  86. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  87. id view = self.listViewArray[index];
  88. if ([view isKindOfClass:[MinePageCourseView class]]) {
  89. MinePageCourseView *courseView = (MinePageCourseView *)view;
  90. courseView.liveFlag = [self.teacherInfo.liveFlag isEqualToString:@"1"] ? YES : NO;
  91. courseView.teaherStatus = self.teacherInfo.entryStatus;
  92. courseView.musicianStatus = self.teacherInfo.musicianAuthStatus;
  93. }
  94. else if ([view isKindOfClass:[MinePageVideoView class]]) {
  95. MinePageVideoView *videoCourseView = (MinePageVideoView *)view;
  96. videoCourseView.teaherStatus = self.teacherInfo.entryStatus;
  97. }
  98. }
  99. }
  100. - (void)viewWillAppear:(BOOL)animated {
  101. [super viewWillAppear:animated];
  102. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  103. [self requestTeachMessage];
  104. [self requestSubjectList];
  105. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  106. id value = self.listViewArray[self.categoryView.selectedIndex];
  107. if ([value isKindOfClass:[MinePageCourseView class]]) {
  108. MinePageCourseView *listView = (MinePageCourseView *)value;
  109. [listView beginFirstRefresh];
  110. }
  111. else if ([value isKindOfClass:[MinePageMienBodyView class]]) {
  112. MinePageMienBodyView *listView = (MinePageMienBodyView *)value;
  113. [listView beginFirstRefresh];
  114. }
  115. else if ([value isKindOfClass:[kSJXCollectionView class]]) {
  116. MinePageVideoView *listView = (MinePageVideoView *)value;
  117. [listView beginFirstRefresh];
  118. }
  119. }
  120. }
  121. - (void)viewDidAppear:(BOOL)animated {
  122. [super viewDidAppear:animated];
  123. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  124. }
  125. - (JXPagerView *)preferredPagingView {
  126. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  127. }
  128. - (void)requestSubjectList {
  129. [KSNetworkingManager querySubjectItemRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  130. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  131. NSArray *dataArray = [NSMutableArray array];
  132. dataArray = [dic arrayValueForKey:@"data"];
  133. NSMutableArray *subjectArray = [NSMutableArray array];
  134. for (NSDictionary *parm in dataArray) {
  135. NSMutableDictionary *subjectSource = [NSMutableDictionary dictionary];
  136. [subjectSource setValue:[parm stringValueForKey:@"id"] forKey:@"subjectId"];
  137. [subjectSource setValue:[parm stringValueForKey:@"name"] forKey:@"subjectName"];
  138. [subjectArray addObject:subjectSource];
  139. }
  140. self.subjectList = [subjectArray mutableCopy];
  141. [self refreshSubjectMessage];
  142. }
  143. else{
  144. [self MBPShow:MESSAGEKEY];
  145. }
  146. } faliure:^(NSError * _Nonnull error) {
  147. }];
  148. }
  149. - (void)refreshSubjectMessage {
  150. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  151. id view = self.listViewArray[index];
  152. if ([view isKindOfClass:[MinePageCourseView class]]) {
  153. MinePageCourseView *courseView = (MinePageCourseView *)view;
  154. courseView.subjectList = [self.subjectList mutableCopy];
  155. }
  156. }
  157. }
  158. #pragma mark - JXPagerViewDelegate
  159. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  160. return self.topView;
  161. }
  162. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  163. return [self.topView getViewHeight];
  164. }
  165. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  166. return HEADER_HEIGHT;
  167. }
  168. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  169. return self.categoryView;
  170. }
  171. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  172. //和categoryView的item数量一致
  173. return self.titles.count;
  174. }
  175. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  176. if (index == 0) { // 个人风采
  177. MinePageMienBodyView *listView = [[MinePageMienBodyView alloc] init];
  178. listView.naviController = self.navigationController;
  179. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  180. self.listViewArray[index] = listView;
  181. listView.selectIndex = index;
  182. [listView beginFirstRefresh];
  183. return listView;
  184. }
  185. else if (index == 1) { // 陪练课
  186. MinePageCourseView *listView = [[MinePageCourseView alloc] init];
  187. listView.naviController = self.navigationController;
  188. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  189. self.listViewArray[index] = listView;
  190. listView.selectIndex = index;
  191. if (self.teacherInfo) {
  192. listView.teaherStatus = self.teacherInfo.entryStatus;
  193. }
  194. else {
  195. listView.teaherStatus = @"PASS";
  196. }
  197. [listView beginFirstRefresh];
  198. return listView;
  199. }
  200. else if (index == 2) { // 直播
  201. MinePageCourseView *listView = [[MinePageCourseView alloc] init];
  202. listView.naviController = self.navigationController;
  203. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  204. self.listViewArray[index] = listView;
  205. listView.selectIndex = index;
  206. if (self.teacherInfo) {
  207. listView.liveFlag = [self.teacherInfo.liveFlag isEqualToString:@"1"] ? YES : NO;
  208. listView.teaherStatus = self.teacherInfo.entryStatus;
  209. }
  210. else {
  211. listView.liveFlag = YES;
  212. listView.teaherStatus = @"PASS";
  213. }
  214. [listView beginFirstRefresh];
  215. return listView;
  216. }
  217. else if (index == 4) { // 乐谱
  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.musicianStatus = self.teacherInfo.musicianAuthStatus;
  225. }
  226. else {
  227. listView.musicianStatus = @"PASS";
  228. }
  229. if (self.subjectList) {
  230. listView.subjectList = [self.subjectList mutableCopy];
  231. }
  232. [listView beginFirstRefresh];
  233. return listView;
  234. }
  235. else { // 视频课
  236. MinePageVideoView *listView = [[MinePageVideoView alloc] init];
  237. listView.naviController = self.navigationController;
  238. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  239. self.listViewArray[index] = listView;
  240. listView.selectIndex = index;
  241. if (self.teacherInfo) {
  242. listView.teaherStatus = self.teacherInfo.entryStatus;
  243. }
  244. else {
  245. listView.teaherStatus = @"PASS";
  246. }
  247. [listView beginFirstRefresh];
  248. return listView;
  249. }
  250. }
  251. #pragma mark - JXCategoryViewDelegate
  252. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  253. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  254. if (self.listViewArray.count > index) {
  255. id value = self.listViewArray[index];
  256. if ([value isKindOfClass:[KSJXBodyView class]]) {
  257. KSJXBodyView *listView = (KSJXBodyView *)value;
  258. [listView beginFirstRefresh];
  259. }
  260. else if ([value isKindOfClass:[kSJXCollectionView class]]) {
  261. kSJXCollectionView *listView = (kSJXCollectionView *)value;
  262. [listView beginFirstRefresh];
  263. }
  264. }
  265. }
  266. #pragma mark - JXPagerMainTableViewGestureDelegate
  267. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  268. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  269. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  270. return NO;
  271. }
  272. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  273. }
  274. #pragma mark --- lazying
  275. - (MinePageHeadView *)headView {
  276. if (!_headView) {
  277. _headView = [MinePageHeadView shareInstance];
  278. MJWeakSelf;
  279. [_headView backAction:^{
  280. [weakSelf backAction];
  281. }];
  282. }
  283. return _headView;
  284. }
  285. - (NSMutableArray *)listViewArray {
  286. if (!_listViewArray) {
  287. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@""]];
  288. }
  289. return _listViewArray;
  290. }
  291. - (MinePageTopView *)topView {
  292. if (!_topView) {
  293. _topView = [MinePageTopView shareInstance];
  294. }
  295. return _topView;
  296. }
  297. /*
  298. #pragma mark - Navigation
  299. // In a storyboard-based application, you will often want to do a little preparation before navigation
  300. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  301. // Get the new view controller using [segue destinationViewController].
  302. // Pass the selected object to the new view controller.
  303. }
  304. */
  305. @end