MyCourseViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // MyCourseViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/5.
  6. //
  7. #import "MyCourseViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "MyVideoCourseBodyView.h"
  12. #import "MyLessonBodyView.h"
  13. #import "TeacherInfo.h"
  14. #import "UserInfoManager.h"
  15. #define HEADER_HEIGHT (64)
  16. @interface MyCourseViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  17. @property (nonatomic, assign) NSInteger selectedIndex;
  18. @property (nonatomic, strong) NSMutableArray *listViewArray;
  19. @property (nonatomic, strong) TeacherInfo *teacherInfo;
  20. @end
  21. @implementation MyCourseViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self allocTitle:@"我的课程"];
  26. self.titles = @[@"陪练课",@"直播课",@"视频课"];
  27. [self configUI];
  28. }
  29. - (void)requestTeachMessage {
  30. [KSNetworkingManager queryTeacherInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  31. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  32. self.teacherInfo = [[TeacherInfo alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  33. NSString *rongToken = UserDefault(RongTokenKey);
  34. if ([NSString isEmptyString:rongToken]) {
  35. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  36. }
  37. [self refreshAuthStatus];
  38. }
  39. else {
  40. [self MBPShow:MESSAGEKEY];
  41. }
  42. } faliure:^(NSError * _Nonnull error) {
  43. }];
  44. }
  45. - (void)refreshAuthStatus {
  46. for (NSInteger index = 0; index < self.listViewArray.count; index++) {
  47. id view = self.listViewArray[index];
  48. if ([view isKindOfClass:[MyLessonBodyView class]]) {
  49. MyLessonBodyView *courseView = (MyLessonBodyView *)view;
  50. courseView.teaherAuth = [self.teacherInfo.entryStatus isEqualToString:@"PASS"] ? YES : NO;
  51. }
  52. else if ([view isKindOfClass:[MyVideoCourseBodyView class]]) {
  53. MyVideoCourseBodyView *videoCourseView = (MyVideoCourseBodyView *)view;
  54. videoCourseView.teaherAuth = [self.teacherInfo.entryStatus isEqualToString:@"PASS"] ? YES : NO;
  55. }
  56. }
  57. }
  58. - (void)configUI {
  59. [self.scrollView removeFromSuperview];
  60. self.view.backgroundColor = HexRGB(0xf6f8f9);
  61. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, HEADER_HEIGHT)];
  62. self.categoryView.titles = self.titles;
  63. self.categoryView.delegate = self;
  64. self.categoryView.titleFont = [UIFont systemFontOfSize:17.0f];
  65. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightMedium];
  66. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  67. self.categoryView.titleColor = HexRGB(0x666666);
  68. self.categoryView.titleColorGradientEnabled = YES;
  69. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  70. lineView.indicatorColor = THEMECOLOR;
  71. lineView.indicatorWidth = 16;
  72. self.categoryView.indicators = @[lineView];
  73. _pagerView = [self preferredPagingView];
  74. self.pagerView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
  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. }
  83. - (void)viewWillAppear:(BOOL)animated {
  84. [super viewWillAppear:animated];
  85. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  86. [self requestTeachMessage];
  87. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  88. id value = self.listViewArray[self.categoryView.selectedIndex];
  89. if ([value isKindOfClass:[MyVideoCourseBodyView class]]) {
  90. MyVideoCourseBodyView *listView = (MyVideoCourseBodyView *)value;
  91. [listView beginFirstRefresh];
  92. }
  93. else if ([value isKindOfClass:[MyLessonBodyView class]]) {
  94. MyLessonBodyView *listView = (MyLessonBodyView *)value;
  95. [listView beginFirstRefresh];
  96. }
  97. }
  98. }
  99. - (void)viewDidAppear:(BOOL)animated {
  100. [super viewDidAppear:animated];
  101. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  102. }
  103. - (JXPagerView *)preferredPagingView {
  104. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  105. }
  106. #pragma mark - JXPagerViewDelegate
  107. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  108. return [UIView new];
  109. }
  110. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  111. return CGFLOAT_MIN;
  112. }
  113. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  114. return HEADER_HEIGHT;
  115. }
  116. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  117. return self.categoryView;
  118. }
  119. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  120. //和categoryView的item数量一致
  121. return self.titles.count;
  122. }
  123. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  124. if (index == 2) {
  125. MyVideoCourseBodyView *listView = [[MyVideoCourseBodyView alloc] init];
  126. listView.naviController = self.navigationController;
  127. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  128. self.listViewArray[index] = listView;
  129. listView.selectIndex = index;
  130. [listView beginFirstRefresh];
  131. if (self.teacherInfo) {
  132. listView.teaherAuth = [self.teacherInfo.entryStatus isEqualToString:@"PASS"] ? YES : NO;
  133. }
  134. else {
  135. listView.teaherAuth = YES;
  136. }
  137. return listView;
  138. }
  139. else {
  140. MyLessonBodyView *listView = [[MyLessonBodyView alloc] init];
  141. listView.naviController = self.navigationController;
  142. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  143. self.listViewArray[index] = listView;
  144. listView.selectIndex = index;
  145. if (self.teacherInfo) {
  146. listView.teaherAuth = [self.teacherInfo.entryStatus isEqualToString:@"PASS"] ? YES : NO;
  147. }
  148. else {
  149. listView.teaherAuth = YES;
  150. }
  151. [listView beginFirstRefresh];
  152. return listView;
  153. }
  154. }
  155. #pragma mark - JXCategoryViewDelegate
  156. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  157. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  158. }
  159. #pragma mark - JXPagerMainTableViewGestureDelegate
  160. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  161. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  162. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  163. return NO;
  164. }
  165. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  166. }
  167. - (NSMutableArray *)listViewArray {
  168. if (!_listViewArray) {
  169. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@"",@""]];
  170. }
  171. return _listViewArray;
  172. }
  173. /*
  174. #pragma mark - Navigation
  175. // In a storyboard-based application, you will often want to do a little preparation before navigation
  176. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  177. // Get the new view controller using [segue destinationViewController].
  178. // Pass the selected object to the new view controller.
  179. }
  180. */
  181. @end