MyCourseViewController.m 8.4 KB

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