| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- //
- // MyCourseViewController.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2022/4/19.
- //
- #import "MyCourseViewController.h"
- #import "MyLessonBodyView.h"
- #import "MyVideoCourseBodyView.h"
- #import "JXCategoryView.h"
- #import "JXPagerListRefreshView.h"
- #import "UserInfoManager.h"
- #define HEADER_HEIGHT (50)
- @interface MyCourseViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
- @property (nonatomic, assign) NSInteger selectedIndex;
- @property (nonatomic, strong) NSMutableArray *listViewArray;
- @property (nonatomic, strong) NSMutableArray *subjectList;
- @property (nonatomic, assign) DISPLAY_INDEX displayIndex;
- @end
- @implementation MyCourseViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"我的课程"];
- self.titles = @[@"陪练课",@"直播课",@"视频课",@"琴房课"];
- [self configUI];
- [self countUMEvent];
- }
- - (void)countUMEvent {
- [USER_MANAGER sendUMEvent:@"klx_myCourse"];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- self.view.backgroundColor = HexRGB(0xf6f8f9);
-
- _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, HEADER_HEIGHT)];
- self.categoryView.titles = self.titles;
- self.categoryView.delegate = self;
- self.categoryView.titleFont = [UIFont systemFontOfSize:17.0f];
- self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightMedium];
- self.categoryView.titleSelectedColor = HexRGB(0x333333);
- self.categoryView.titleColor = HexRGB(0x666666);
- self.categoryView.titleColorGradientEnabled = YES;
- self.categoryView.backgroundColor = [UIColor whiteColor];
-
- JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
- lineView.indicatorColor = THEMECOLOR;
- lineView.indicatorHeight = 4.0f;
- lineView.indicatorWidth = 28;
- self.categoryView.indicators = @[lineView];
-
- _pagerView = [self preferredPagingView];
- self.pagerView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- self.pagerView.backgroundColor = [UIColor clearColor];
- self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
- self.pagerView.listContainerView.backgroundColor = [UIColor clearColor];
- self.pagerView.mainTableView.gestureDelegate = self;
- self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- self.pagerView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
- [self.view addSubview:self.pagerView];
- if (self.displayIndex != 0) {
- [self.categoryView setDefaultSelectedIndex:self.displayIndex];
- }
- }
- - (void)displayWithIndex:(DISPLAY_INDEX)displayIndex {
- self.displayIndex = displayIndex;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- [self requestSubjectList];
- if (self.listViewArray.count > self.categoryView.selectedIndex) {
- id value = self.listViewArray[self.categoryView.selectedIndex];
- if ([value isKindOfClass:[MyVideoCourseBodyView class]]) {
- MyVideoCourseBodyView *listView = (MyVideoCourseBodyView *)value;
- [listView beginFirstRefresh];
- }
- else if ([value isKindOfClass:[MyLessonBodyView class]]) {
- MyLessonBodyView *listView = (MyLessonBodyView *)value;
- [listView beginFirstRefresh];
- }
- }
- }
- - (void)requestSubjectList {
- [KSNetworkingManager querySubjectItemRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *dataArray = [NSMutableArray array];
- dataArray = [dic arrayValueForKey:@"data"];
- NSMutableArray *subjectArray = [NSMutableArray array];
- for (NSDictionary *parm in dataArray) {
- NSMutableDictionary *subjectSource = [NSMutableDictionary dictionary];
- [subjectSource setValue:[parm stringValueForKey:@"id"] forKey:@"subjectId"];
- [subjectSource setValue:[parm stringValueForKey:@"name"] forKey:@"subjectName"];
- [subjectArray addObject:subjectSource];
- }
- self.subjectList = [subjectArray mutableCopy];
- [self refreshSubjectMessage];
- }
- else{
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)refreshSubjectMessage {
- for (NSInteger index = 0; index < self.listViewArray.count; index++) {
- id view = self.listViewArray[index];
- if ([view isKindOfClass:[MyLessonBodyView class]]) {
- MyLessonBodyView *courseView = (MyLessonBodyView *)view;
- courseView.subjectList = [self.subjectList mutableCopy];
- }
- else if ([view isKindOfClass:[MyVideoCourseBodyView class]]) {
- MyVideoCourseBodyView *videoCourseView = (MyVideoCourseBodyView *)view;
- videoCourseView.subjectList = [self.subjectList mutableCopy];
- }
- }
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
- }
- - (JXPagerView *)preferredPagingView {
- return [[JXPagerListRefreshView alloc] initWithDelegate:self];
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return [UIView new];
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return CGFLOAT_MIN;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return HEADER_HEIGHT;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.categoryView;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- //和categoryView的item数量一致
- return self.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
- if (index == 2) {
- MyVideoCourseBodyView *listView = [[MyVideoCourseBodyView alloc] init];
- listView.naviController = self.navigationController;
- [self.listViewArray replaceObjectAtIndex:index withObject:listView];
- self.listViewArray[index] = listView;
- listView.selectIndex = index;
- if (self.subjectList) {
- listView.subjectList = [self.subjectList mutableCopy];
- }
- [listView beginFirstRefresh];
- return listView;
- }
- else {
- MyLessonBodyView *listView = [[MyLessonBodyView alloc] init];
- listView.naviController = self.navigationController;
- [self.listViewArray replaceObjectAtIndex:index withObject:listView];
- self.listViewArray[index] = listView;
- listView.selectIndex = index;
- if (self.subjectList) {
- listView.subjectList = [self.subjectList mutableCopy];
- }
- [listView beginFirstRefresh];
- return listView;
- }
-
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- }
- #pragma mark - JXPagerMainTableViewGestureDelegate
- - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- //禁止categoryView左右滑动的时候,上下和左右都可以滚动
- if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
- return NO;
- }
- return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
- }
- - (NSMutableArray *)listViewArray {
- if (!_listViewArray) {
- _listViewArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@""]];
- }
- return _listViewArray;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|