123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "KSBaseWKWebViewController.h"
- #import "InstrumentChooseViewController.h"
- #import "NotiferMessageViewController.h"
- #import "HomeNavSearchView.h"
- #import "KSScanViewController.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "HomeButtonView.h"
- #import "KSHomeButton.h"
- #import "PublicNoticeView.h"
- #import <SDCycleScrollView.h>
- #import "NoticeSourceModel.h"
- #import "AppDelegate.h"
- #import "KSNewsAlert.h"
- #import "UserInfo.h"
- #import "UserInfoManager.h"
- #import "HomeRecentCourseView.h"
- #import "AccompanyDetailViewController.h"
- #import "MusicRoomDetailViewController.h"
- #import "VipCouseDetailViewController.h"
- #import "HomeHotAlbumView.h"
- #import "HomeAlbumModel.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeHotMusicView.h"
- #import "HomeHotMusicCollectionCell.h"
- #import "KSPremissionAlert.h"
- #import <RecordCheckManager.h>
- #import "HomeHotTalentView.h"
- #import "HomeHotTalentCell.h"
- #import "TalentTeacherModel.h"
- #import "HomeHotVideoCourseView.h"
- #import "HomeHotVideoCell.h"
- #import "HomeVideoGroupModel.h"
- #import "HomeHotLiveCourseView.h"
- #import "HomeHotLiveCell.h"
- #import "HomeLiveGroupModel.h"
- #import "JXCategoryView.h"
- #import "JXPagerListRefreshView.h"
- #import "HomeInformationBodyView.h"
- #import "HomeTeacherLiveModel.h"
- #import "ToneTuningViewController.h"
- #import "KSAwardAlertView.h"
- #import "HomeNewMusicView.h"
- #import "HomeRecommendMusicView.h"
- #import "HomeMusicModel.h"
- #import "HomeDragButton.h"
- #import "HomeMusicSheetLayout.h"
- #import "HomeArrangeCourseController.h"
- #import "HomeCountView.h"
- #import "KSTabBarViewController.h"
- #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
- #define COLLECTION_HEIGHT (320)
- @interface HomeViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate,SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) HomeNavSearchView *navView;
- @property (nonatomic, strong) HomeMessageModel *flashModel;
- @property (nonatomic, assign) BOOL isFirstLoad;
- // banner
- @property (nonatomic, strong) TYPageControl *pageControl;
- @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
- @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
- @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
- @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
- // 统计
- @property (nonatomic, strong) HomeCountView *countView;
- @property (nonatomic, assign) CGFloat countViewHeight;
- // 按钮
- @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
- @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
- @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
- // 公告
- @property (nonatomic, strong) PublicNoticeView *noticeView;
- @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
- @property (nonatomic, strong) NSMutableArray *noticeArray; // notice数据
- @property (nonatomic, strong) NSMutableArray *noticeTitleArray; // 标题数组
- @property (nonatomic, assign) CGFloat noticeViewHeight;
- // 最近课程
- @property (nonatomic, strong) HomeRecentCourseView *courseView;
- @property (nonatomic, assign) CGFloat courseViewHeight;
- @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
- // 推荐老师
- @property (nonatomic, strong) HomeHotTalentView *talentView;
- @property (nonatomic, strong) UICollectionView *talentCollectionView; // 推荐老师容器
- @property (nonatomic, strong) NSMutableArray *talentArray; // 推荐老师数据
- @property (nonatomic, assign) CGFloat talentViewHeight; // talent 高度
- // 视频课
- @property (nonatomic, strong) HomeHotVideoCourseView *videoCourseView;
- @property (nonatomic, strong) UICollectionView *videoCollectionView; // 视频课容器
- @property (nonatomic, strong) NSMutableArray *videoCourseArray; // 视频课数据
- @property (nonatomic, assign) CGFloat videoViewHeight; // video 高度
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- // 顶部数据容器
- @property (nonatomic, strong) UIView *headView;
- @property (nonatomic, strong) JXCategoryTitleView *myCategoryView;
- @property (nonatomic, assign) NSInteger currentIndex;
- @property (nonatomic, strong) NSMutableArray *listViewArray;
- @property (nonatomic, assign) NSInteger headViewHeight;
- @property (nonatomic, strong) NSMutableArray *liveListArray;
- @property (nonatomic, strong) NSMutableArray *informationArray;
- @property (nonatomic, strong) UIView *headBgView;
- @property (nonatomic, assign) BOOL isCheck;
- @property (nonatomic, strong) HomeMessageModel *buttonModel;
- @property (nonatomic, strong) HomeDragButton *suspendButton;
- @property (nonatomic, assign) CGFloat headheight;
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- _titles = @[@""];
- self.isFirstLoad = YES;
- [self configNavView];
- [self configUI];
- }
- - (void)requestTrackAuth {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate appTrackActionAuth];
- }
- - (void)configNavView {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
- [self.view bringSubviewToFront:self.navView];
- }
- - (void)configHeadView {
- [self.headView addSubview:self.headBgView];
-
- // banner
- [self.headView addSubview:self.bannerView];
- self.bannerViewHeight = CGFLOAT_MIN;
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.headView.mas_top).offset(12);
- make.left.right.mas_equalTo(self.headView);
- make.height.mas_equalTo(self.bannerViewHeight);
- }];
- self.bannerView.hidden = YES;
-
- // 统计
- [self.headView addSubview:self.countView];
- self.countViewHeight = [HomeCountView getViewHeight];
- [self.countView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(self.countViewHeight);
- }];
-
- // 最近课程
- [self.headView addSubview:self.courseView];
- self.courseViewHeight = CGFLOAT_MIN;
- [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.countView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- self.courseView.hidden = YES;
-
- // 公告
- [self.headView addSubview:self.noticeView];
- self.noticeViewHeight = CGFLOAT_MIN;
- [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.courseView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- [self.noticeView.adView addSubview:self.noticeScrollView];
- [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.mas_equalTo(self.noticeView.adView);
- }];
- self.noticeView.hidden = YES;
- // 按钮
- [self.headView addSubview:self.buttonContainer];
- self.buttonViewHeight = CGFLOAT_MIN;
- [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.noticeView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- self.buttonContainer.hidden = YES;
-
- // 找老师
- [self.headView addSubview:self.talentView];
- self.talentViewHeight = CGFLOAT_MIN;
- [self.talentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.buttonContainer.mas_bottom);
- make.height.mas_equalTo(self.talentViewHeight);
- }];
- self.talentView.hidden = YES;
-
- // 视频课
- [self.headView addSubview:self.videoCourseView];
- self.videoViewHeight = CGFLOAT_MIN;
- [self.videoCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.talentView.mas_bottom);
- make.height.mas_equalTo(self.videoViewHeight);
- }];
- self.videoCourseView.hidden = YES;
-
- [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.headView.mas_top);
- make.bottom.mas_equalTo(self.buttonContainer.mas_bottom);
- }];
-
- self.headBgView.layer.masksToBounds = YES;
- self.headBgView.layer.cornerRadius = 18.0f;
- self.headBgView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
-
- [self refreshHeadHeight];
- }
- - (void)refreshHeadHeight {
- CGFloat headSpace = 12.0f;
- CGFloat bottomSpace = 0.0f;
- self.headViewHeight = headSpace + self.bannerViewHeight + self.countViewHeight + self.courseViewHeight + self.noticeViewHeight + self.buttonViewHeight + self.talentViewHeight + self.videoViewHeight + bottomSpace;
- self.headView.frame = CGRectMake(0, 0, KPortraitWidth, self.headViewHeight);
- [self.pagerView resizeTableHeaderViewHeightWithAnimatable:NO duration:0.3f curve:UIViewAnimationCurveEaseInOut];
- }
- - (void)configUI {
- [self configHeadView];
- self.headheight = CGFLOAT_MIN;
- _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNaviBarHeight, KPortraitWidth, self.headheight)];
- self.categoryView.backgroundColor = [UIColor clearColor];
- self.categoryView.titles = self.titles;
- self.categoryView.delegate = self;
- self.categoryView.titleFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
- self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
- self.categoryView.titleSelectedColor = HexRGB(0x333333);
- self.categoryView.titleColor = HexRGB(0x999999);
- self.categoryView.titleColorGradientEnabled = YES;
- self.categoryView.cellWidth = 90.0f;
- self.categoryView.cellSpacing = 16.0f;
- self.categoryView.averageCellSpacingEnabled = NO;
-
- _pagerView = [self preferredPagingView];
- self.pagerView.frame = CGRectMake(0, kNaviBarHeight, KPortraitWidth, KPortraitHeight - kNaviBarHeight - kTabBarHeight);
- self.pagerView.mainTableView.gestureDelegate = self;
- [self.view addSubview:self.pagerView];
- self.pagerView.backgroundColor = [UIColor clearColor];
- self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
- self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- // 头部刷新
- MJWeakSelf;
- self.pagerView.mainTableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
- }
- - (JXPagerView *)preferredPagingView {
- return [[JXPagerView alloc] initWithDelegate:self];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.isFirstLoad == YES) {
- [self requestUserInfo:YES]; // 获取声部
- [self requestTrackAuth];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate handleNotiferSource];
- }
- else {
- [self requestUserInfo:NO];
- }
- [self requestUnreadCount];
- }
- - (void)requestAwardMessage {
- self.isCheck = NO;
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager checkReceiveRewardRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- BOOL isCheck = [[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"check"];
- self.isCheck = isCheck;
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (BOOL)checkHasShowAwardAlert {
- NSDictionary *awardAlertDic = UserDefaultObjectForKey(@"awardAlertConfig");
-
- NSDate *currendDate = [NSDate date];
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- NSString *todayString = [dateFormatter stringFromDate:currendDate];
-
- if (awardAlertDic) {
- NSString *awardAlertTime = [awardAlertDic ks_stringValueForKey:@"time"];
-
- if (![NSString isEmptyString:awardAlertTime]) {
- NSString *userId = [awardAlertDic ks_stringValueForKey:@"userId"];
- if ([todayString isEqualToString:awardAlertTime] && [userId isEqualToString:UserDefaultObjectForKey(UIDKey)]) {
- return YES;
- }
- }
- }
- return NO;
- }
- - (void)checkShowAwardAlert {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.isShowMemoAlert) {
- return;
- }
-
- if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
- return;
- }
-
- KSAwardAlertView *alert = [KSAwardAlertView shareInstance];
- MJWeakSelf;
- [alert awardActionCallback:^(BOOL isSure) {
- if (isSure) {
- [weakSelf displayAwardList];
- }
- }];
-
- [alert showAlert];
- NSDate *currendDate = [NSDate date];
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- NSString *todayString = [dateFormatter stringFromDate:currendDate];
- NSDictionary *saveDic = @{@"time" :todayString , @"userId" : UserDefaultObjectForKey(UIDKey)};
- UserDefaultSetObjectForKey(saveDic, @"awardAlertConfig");
- }
- - (void)displayAwardList {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (void)requestUnreadCount {
- [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *countArray = [dic ks_arrayValueForKey:@"data"];
- NSInteger courseCount = 0;
- NSInteger sysCount = 0;
- for (NSDictionary *parm in countArray) {
- if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
- courseCount = [parm ks_integerValueForKey:@"value"];
- }
- if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
- sysCount = [parm ks_integerValueForKey:@"value"];
- }
- }
- if (courseCount != 0 || sysCount != 0) {
- self.navView.dotView.hidden = NO;
- }
- else {
- self.navView.dotView.hidden = YES;
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestUserInfo:(BOOL)checkSubject {
- self.isFirstLoad = NO;
-
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self refreshSource:checkSubject];
- [self refreshView];
- }];
- }
- - (void)refreshSource:(BOOL)checkSubject {
- if (checkSubject) {
- if ([NSString isEmptyString:self.mineInfo.subjectName]) {
- [self showInstrumentView:YES];
- }
- else {
- [self requestData];
- }
- }
- else { // 刷新老师数据
- [self refreshTalentAndRefresh];
- }
- }
- - (void)showInstrumentView:(BOOL)hideBackButton {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseCallback:^{
- [weakSelf requestUserInfo:NO];
- [weakSelf requestData];
- }];
- if (hideBackButton) {
- ctrl.isModalPresent = YES;
- CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
- navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
- }
- else {
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (void)requestNewsList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- // banner
- NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
- NSMutableArray *bannerInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in bannerArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [bannerInfoArray addObject:model];
- }
- self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
-
- // button
- NSArray *buttonArray = [result ks_arrayValueForKey:@"appMenu"];
- NSMutableArray *buttonInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in buttonArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [buttonInfoArray addObject:model];
- }
- self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
- // news
- NSArray *flashArray = [result ks_arrayValueForKey:@"flashPage"];
- if (flashArray.count) {
- self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
- }
-
- // 首页悬浮按钮
- NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
- if (suspensionArray.count) {
- self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
- }
- else {
- self.buttonModel = nil;
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestStatistics {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeSummaryRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
-
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [self.countView configWithSource:[dic ks_dictionaryValueForKey:@"data"]];
- }
- dispatch_group_leave(self.requestGroup);
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestCourseInfo {
-
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *sourceDic = [dic ks_dictionaryValueForKey:@"data"];
-
- NSArray *videoList = [sourceDic ks_arrayValueForKey:@"videoList"];
- NSMutableArray *videoCourse = [NSMutableArray array];
- for (NSDictionary *parm in videoList) {
- HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
- [videoCourse addObject:model];
- }
- self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
-
- // 最近课程
- NSDictionary *parm = [sourceDic ks_dictionaryValueForKey:@"recentCourses"];
- if (parm == nil) {
- self.recentCourseModel = nil;
- }
- else {
- self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestNotice {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
- if (sourceArray.count) {
- NSDictionary *parm = [sourceArray firstObject];
- NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
- [self.noticeArray addObject:bannerModel];
- [self.noticeTitleArray addObject:bannerModel.title];
- }
- else {
- self.noticeArray = [NSMutableArray array];
- self.noticeTitleArray = [NSMutableArray array];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestTalentSource {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- NSMutableArray *talentArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
- [talentArray addObject:model];
- }
- self.talentArray = [NSMutableArray arrayWithArray:talentArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshTalentAndRefresh {
- [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- NSMutableArray *talentArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
- [talentArray addObject:model];
- }
- self.talentArray = [NSMutableArray arrayWithArray:talentArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self refreshTalentView];
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestLiveList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager queryTeacherLivingListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- NSMutableArray *liveListArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeTeacherLiveModel *model = [[HomeTeacherLiveModel alloc] initWithDictionary:parm];
- [liveListArray addObject:model];
- }
- self.liveListArray = [NSMutableArray arrayWithArray:liveListArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestInformationList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager informationListRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
- NSMutableArray *informationInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [informationInfoArray addObject:model];
- }
- self.informationArray = [NSMutableArray arrayWithArray:informationInfoArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestData {
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [self requestNewsList];
- [self requestStatistics];
- [self requestNotice];
- [self requestCourseInfo];
- // 老师
- [self requestTalentSource];
- [self requestLiveList];
- [self requestInformationList];
- if ([self checkHasShowAwardAlert] == NO) {
- [self requestAwardMessage];
- }
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [LOADING_MANAGER removeCustomLoading];
- [self.pagerView.mainTableView.mj_header endRefreshing];
- [self refreshView];
- });
- }
- - (void)refreshView {
- [self refreshBannaerView];
- [self showButtonMessage];
- [self refreshNotice];
- [self refreshCourseView:self.recentCourseModel];
- // 老师
- [self refreshTalentView];
- // 课程
- [self refreshCourseView];
- [self refreshHeadHeight];
-
- [self refreshPageView];
- if (self.isCheck && [self checkHasShowAwardAlert] == NO) {
- [self checkShowAwardAlert];
- }
- else {
- if (self.flashModel) {
- [self showNewsWithSource:self.flashModel];
- }
- }
-
- // 悬浮按钮
- if (self.buttonModel) {
- [self showFloatingWindow];
- }
- else {
- [self removeFloatWindow];
- }
- }
- - (void)removeFloatWindow {
- if ([self.view.subviews containsObject:self.suspendButton]) {
- [self.suspendButton removeFromSuperview];
- }
- }
- // 显示悬浮窗
- - (void)showFloatingWindow {
- if (![self.view.subviews containsObject:self.suspendButton]) {
- [self.view addSubview:self.suspendButton];
- }
- [self.view bringSubviewToFront:self.suspendButton];
- [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
- }
- - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
- // 登录之后才弹窗
- if ([self checkIsLoginToLoginView:NO]) {
-
- [self displayAlert:sourceModel];
- }
- }
- - (void)displayAlert:(HomeMessageModel *)sourceModel {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.isShowMemoAlert) {
- return;
- }
- if (USER_MANAGER.hasShowFlash) {
- return;
- }
- if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
- return;
- }
-
- KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
- MJWeakSelf;
- [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
- appDelegate.isShowFlashAlert = NO;
- if (isSure) {
- if (![NSString isEmptyString:linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [linkUrl getUrlEndcodeString];
- [weakSelf.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
- }];
- [newAlert showAlert];
- appDelegate.isShowFlashAlert = YES;
- USER_MANAGER.hasShowFlash = YES; // 已展示过flash
- }
- - (void)refreshPageView {
- for (NSInteger i = 0; i < self.listViewArray.count; i++) {
- id view = self.listViewArray[i];
- if ([view isKindOfClass:[HomeInformationBodyView class]]) {
- HomeInformationBodyView *informationView = (HomeInformationBodyView *)view;
- informationView.informationArray = [self.informationArray mutableCopy];
- [informationView beginFirstRefresh];
- }
- }
- }
- - (void)refreshTalentView {
- if (self.talentArray.count) {
- self.talentViewHeight = [HomeHotTalentView getViewHeight];
- self.talentView.hidden = NO;
- }
- else {
- self.talentViewHeight = CGFLOAT_MIN;
- self.talentView.hidden = YES;
- }
- [self.talentView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.talentViewHeight);
- }];
- [self.talentCollectionView reloadData];
- }
- - (void)refreshBannaerView {
-
- if (self.bannerArray.count > 0) {
- self.bannerViewHeight = [HomeBannerView getViewHeight];
- self.bannerView.hidden = NO;
- }
- else {
- self.bannerViewHeight = CGFLOAT_MIN;
- self.bannerView.hidden = YES;
- }
- if (self.bannerArray.count > 1) {
- self.bannerScroll.autoScrollInterval = 3.0f;
- [self.bannerScroll addSubview:self.pageControl];
- }
- else {
- self.bannerScroll.autoScrollInterval = 0;
- [self.pageControl removeFromSuperview];
- }
- [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.bannerViewHeight);
- }];
- _pageControl.numberOfPages = self.bannerArray.count;
- [self.bannerScroll reloadData];
- }
- - (void)showButtonMessage {
- [self.buttonContainer.buttonContentView removeAllSubViews];
- CGFloat buttonSpace = (KPortraitWidth - BUTTON_ROWCOUNT * HOME_BUTTONWIDTH) / (BUTTON_ROWCOUNT /*+ 1*/);
- // 添加按钮
- if (self.buttonArray.count) {
- self.buttonContainer.hidden = NO;
- CGFloat xSpace = 0.0f;
- CGFloat ySpace = 0.0f;
- for (NSInteger i = 0; i < self.buttonArray.count; i++) {
- xSpace = buttonSpace / 2 + (i % BUTTON_ROWCOUNT) * (HOME_BUTTONWIDTH + buttonSpace);
- ySpace = (i / BUTTON_ROWCOUNT) * (HOME_BUTTONHEIGHT + HOME_BUTTON_VERTICAL_SPACE);
- HomeMessageModel *model = self.buttonArray[i];
- KSHomeButton *buttonView = [KSHomeButton shareInstance];
-
- [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
- buttonView.buttonTitle.text = model.title;
- buttonView.frame = CGRectMake(xSpace, ySpace, HOME_BUTTONWIDTH, HOME_BUTTONHEIGHT);
- buttonView.actionButton.tag = 3000 + i;
- [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.buttonContainer.buttonContentView addSubview:buttonView];
- }
- }
- else {
- self.buttonContainer.hidden = YES;
- }
-
- // 高度
- CGFloat buttonViewDefaultHeight = [HomeButtonView getViewHeight:self.buttonArray.count];
- self.buttonViewHeight = buttonViewDefaultHeight;
- [self.buttonContainer mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(buttonViewDefaultHeight);
- }];
- }
- - (void)HomeTopButtonAction:(UIButton *)sender {
-
- NSInteger index = sender.tag - 3000;
- if ([self checkIsLoginToLoginView:YES]) {
- HomeMessageModel *model = self.buttonArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- if ([model.linkUrl isEqualToString:@"native-metronome"]) {
- ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([model.linkUrl isEqualToString:@"native-bookVip"]) {
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([model.linkUrl isEqualToString:@"native-bookAccompany"]) {
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_FIRST];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([model.linkUrl isEqualToString:@"native-bookLive"]) {
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_LIVE];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([model.linkUrl isEqualToString:@"native-bookVideo"]) {
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [model.linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
-
- }
- }
- }
- - (void)refreshNotice {
- if (self.noticeTitleArray.count) {
- self.noticeView.hidden = NO;
- CGFloat height = [PublicNoticeView getViewHeight];
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(height);
- }];
- self.noticeViewHeight = height;
- }
- else {
- self.noticeView.hidden = YES;
- self.noticeViewHeight = CGFLOAT_MIN;
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
-
- }
- self.noticeScrollView.titlesGroup = self.noticeTitleArray;
- }
- - (void)refreshCourseView:(RecentCourseModel *)model {
- if (model) {
- [self.courseView configCourseMessage:model];
- self.courseView.hidden = NO;
- self.courseViewHeight = [HomeRecentCourseView getViewHeight];
- [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.courseViewHeight);
- }];
- }
- else {
- self.courseView.hidden = YES;
- self.courseViewHeight = CGFLOAT_MIN;
- [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.courseViewHeight);
- }];
- }
- }
- - (void)refreshCourseView {
-
- if (self.videoCourseArray.count) {
- self.videoViewHeight = [HomeHotVideoCourseView getViewHeight];
- self.videoCourseView.hidden = NO;
- }
- else {
- self.videoViewHeight = CGFLOAT_MIN;
- self.videoCourseView.hidden = YES;
- }
- [self.videoCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.videoViewHeight);
- }];
-
- [self.videoCollectionView reloadData];
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return self.headView;
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return self.headViewHeight;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.categoryView;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.headheight;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- //和categoryView的item数量一致
- return self.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
-
- HomeInformationBodyView *listView = [[HomeInformationBodyView alloc] init];
- listView.naviController = self.navigationController;
- [self.listViewArray replaceObjectAtIndex:index withObject:listView];
- self.listViewArray[index] = listView;
- listView.selectIndex = index;
- listView.informationArray = [self.informationArray mutableCopy];
- [listView beginFirstRefresh];
- return listView;
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- if (self.listViewArray.count > index) {
- id value = self.listViewArray[index];
- if ([value isKindOfClass:[KSJXBodyView class]]) {
- KSJXBodyView *listView = (KSJXBodyView *)value;
- [listView beginFirstRefresh];
- }
- }
- }
- #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]];
- }
- - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
- NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y);
- NSInteger height = self.headViewHeight;
- CGFloat space = scrollView.contentOffset.y;
- if (space > 0) {
- self.navView.lineView.hidden = NO;
- }
- else {
- self.navView.lineView.hidden = YES;
- }
- if (space >= height) {
- self.categoryView.backgroundColor = [UIColor whiteColor];
- }
- else {
- self.categoryView.backgroundColor = [UIColor clearColor];
- }
- }
- #pragma mark - TYCyclePagerViewDataSource代理
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.bannerArray.count;
- }
- - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- HomeMessageModel *model = self.bannerArray[index];
- HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
- [cell configCellWithModel:model];
- return cell;
- }
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
- layout.itemSize = CGSizeMake(KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
- layout.itemSpacing = 0;
- return layout;
-
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
- if (pageView == self.bannerScroll) {
- [self.pageControl setCurrentPage:toIndex animate:YES];
- }
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
-
- HomeMessageModel *model = self.bannerArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- if ([model.linkType isEqualToString:@"OUT"]) {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [model.linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- #pragma mark ---- collection data source
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (collectionView == self.talentCollectionView) { // 推荐老师
- return self.talentArray.count;
- }
- else/* if (collectionView == self.videoCollectionView)*/ { // 视频课
- return self.videoCourseArray.count;
- }
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.talentCollectionView) {
- TalentTeacherModel *talentModel = self.talentArray[indexPath.item];
- HomeHotTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotTalentCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSource:talentModel callback:^(NSString *teacherId) {
- [weakSelf followTalentTeacher:teacherId];
- }];
- return cell;
- }
- else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.item];
- HomeHotVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotVideoCell" forIndexPath:indexPath];
- [cell configWithSource:model];
- return cell;
- }
- }
- - (void)followTalentTeacher:(NSString *)teacherId {
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [KSNetworkingManager starOrUnStarRequest:KS_GET userId:teacherId starStatus:@"1" success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeCustomLoading];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
-
- [LOADING_MANAGER KSShowMsg:@"关注成功" promptCompletion:^{
- [self requestData];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeCustomLoading];
- }];
- }
- - (void)displaySongDetail:(NSString *)songId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
- [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
-
- } confirm:^{
- [self openSettingView];
- }];
-
- }
- - (void)openSettingView {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.talentCollectionView) { // 老师风采
- TalentTeacherModel *model = self.talentArray[indexPath.item];
- [self displayTeacherDetail:[NSString stringWithFormat:@"%.0f",model.userId]];
- }
- else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- // 老师风采
- - (void)displayTeacherDetail:(NSString *)teacherId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.talentCollectionView) {
- return CGSizeMake(104, 146);
- }
- else if (collectionView == self.videoCollectionView) {
- if (IS_IPAD) {
- return CGSizeMake(205, 158);
- }
- return CGSizeMake(168, 158);
- }
- else {
- return CGSizeMake(168, 158);
- }
- }
- #pragma mark ----- SDCycleScrollViewDelegate
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- NoticeSourceModel *noticeModel = self.noticeArray[index];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- #pragma mark ------- lazying
- - (HomeNavSearchView *)navView {
- if (!_navView) {
- _navView = [HomeNavSearchView shareInstance];
- MJWeakSelf;
- [_navView homeNavSearchAction:^(HOMENAV_TAG action) {
- [weakSelf homeNavAction:action];
- }];
- }
- return _navView;
- }
- - (void)homeNavAction:(HOMENAV_TAG)action {
- switch (action) {
- case HOMENAV_TAG_SCAN: // 扫一扫
- {
- [self showScanView];
- }
- break;
- case HOMENAV_TAG_MESSAGE: // 消息
- {
- NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (void)showScanView {
- // 判断是否有权限
- [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- KSScanViewController *ctrl = [[KSScanViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }];
- }
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- - (UIView *)headView {
- if (!_headView) {
- _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, CGFLOAT_MIN)];
- _headView.backgroundColor = [UIColor clearColor];
- }
- return _headView;
- }
- - (NSMutableArray *)listViewArray {
- if (!_listViewArray) {
- _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]];
- }
- return _listViewArray;
- }
- - (HomeBannerView *)bannerView {
- if (!_bannerView) {
- _bannerView = [HomeBannerView shareInstance];
- [_bannerView.bannerContentView addSubview:self.bannerScroll];
- }
- return _bannerView;
- }
- #pragma mark --- banner
- - (TYCyclePagerView *)bannerScroll {
- if (!_bannerScroll) {
- _bannerScroll = [[TYCyclePagerView alloc] init];
- _bannerScroll.backgroundColor = [UIColor clearColor];
- _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
- _bannerScroll.isInfiniteLoop = YES;
- _bannerScroll.autoScrollInterval = 3.0f;
- _bannerScroll.reloadDataNeedResetIndex = YES;
- _bannerScroll.dataSource = self;
- _bannerScroll.delegate = self;
- [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
- if (@available(iOS 11.0, *)) {
- _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- }
- return _bannerScroll;
- }
- - (TYPageControl *)pageControl {
- if (!_pageControl) {
- _pageControl = [[TYPageControl alloc] init];
- _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- _pageControl.pageIndicatorSpaing = 4.0f;
- _pageControl.frame = CGRectMake(0, (KPortraitWidth - 28) * 132 / 347 - 20, KPortraitWidth-28 - 12, 12);
- _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
- _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
- _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
- _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
- }
- return _pageControl;
- }
- - (NSMutableArray *)bannerArray {
- if (!_bannerArray) {
- _bannerArray = [NSMutableArray array];
- }
- return _bannerArray;
- }
- #pragma mark ---- scroll view delegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-
- }
- #pragma mark ---- countView
- - (HomeCountView *)countView {
- if (!_countView) {
- _countView = [HomeCountView sharedInstance];
- MJWeakSelf;
- [_countView countActionCallback:^(BOOL showCourseTable) {
- [weakSelf homeStatisticsAction:showCourseTable];
- }];
- }
- return _countView;
- }
- - (void)homeStatisticsAction:(BOOL)showCourseTable {
- if (showCourseTable) {
- [(KSTabBarViewController *)self.tabBarController tabBarSelectedWithIndex:2];
- }
- else {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ---- button container
- - (HomeButtonView *)buttonContainer {
- if (!_buttonContainer) {
- _buttonContainer = [HomeButtonView shareInstance];
- }
- return _buttonContainer;
- }
- #pragma mark ---- notice view
- - (UIView *)headBgView {
- if (!_headBgView) {
- _headBgView = [[UIView alloc] init];
- _headBgView.backgroundColor = [UIColor whiteColor];
- }
- return _headBgView;
- }
- - (PublicNoticeView *)noticeView {
- if (!_noticeView) {
- _noticeView = [PublicNoticeView shareInstance];
- MJWeakSelf;
- [_noticeView moreCallback:^{
- [weakSelf moreNotice];
- }];
- }
- return _noticeView;
- }
- - (NSMutableArray *)noticeArray {
- if (!_noticeArray) {
- _noticeArray = [NSMutableArray array];
- }
- return _noticeArray;
- }
- - (NSMutableArray *)noticeTitleArray {
- if (!_noticeTitleArray) {
- _noticeTitleArray = [NSMutableArray array];
- }
- return _noticeTitleArray;
- }
- - (void)moreNotice {
- if (self.noticeArray.count) {
- NoticeSourceModel *bannerModel = self.noticeArray[0];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- - (SDCycleScrollView *)noticeScrollView {
- if (!_noticeScrollView) {
- _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
- _noticeScrollView.onlyDisplayText = YES;
- _noticeScrollView.autoScroll = NO;
- _noticeScrollView.scrollEnabled = NO;
- _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
- _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
- _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor];
- _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
- _noticeScrollView.titlesGroup = self.noticeTitleArray;
- }
- return _noticeScrollView;
- }
- - (HomeRecentCourseView *)courseView {
- if (!_courseView) {
- _courseView = [HomeRecentCourseView shareInstance];
- MJWeakSelf;
- [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
- [weakSelf joinRoomAction:type courseMessage:courseModel];
- }];
- }
- return _courseView;
- }
- - (void)joinRoomAction:(RECENTCOURSE_TYPE)type courseMessage:(RecentCourseModel *)courseModel {
- if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
- AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
- MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else if (type == RECENTCOURSE_TYPE_VIP) { // VIP
- VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ---- talent view
- - (HomeHotTalentView *)talentView {
- if (!_talentView) {
- _talentView = [HomeHotTalentView shareInstance];
- [_talentView.talentContentView addSubview:self.talentCollectionView];
- MJWeakSelf;
- [_talentView homeTalentMore:^{
- [weakSelf teacherMoreIntorduce];
- }];
- [self.talentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_talentView.talentContentView);
- }];
- }
- return _talentView;
- }
- - (void)teacherMoreIntorduce { // 约课-VIP定制
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)talentCollectionView {
- if (!_talentCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(0, 14, 0, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _talentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _talentCollectionView.backgroundColor = [UIColor clearColor];
- _talentCollectionView.delegate = self;
- _talentCollectionView.dataSource = self;
- _talentCollectionView.showsVerticalScrollIndicator = NO;
- _talentCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _talentCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _talentCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_talentCollectionView registerNib:[UINib nibWithNibName:@"HomeHotTalentCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotTalentCell"];
- }
- return _talentCollectionView;
- }
- #pragma mark ----- video course
- - (HomeHotVideoCourseView *)videoCourseView {
- if (!_videoCourseView) {
- _videoCourseView = [HomeHotVideoCourseView shareInstance];
- MJWeakSelf;
- [_videoCourseView homeVideoMore:^{
- [weakSelf toVideoMorePage];
- }];
- [_videoCourseView.videoContentView addSubview:self.videoCollectionView];
- [self.videoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_videoCourseView.videoContentView);
- }];
- }
- return _videoCourseView;
- }
- - (UICollectionView *)videoCollectionView {
- if (!_videoCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _videoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _videoCollectionView.backgroundColor = [UIColor clearColor];
- _videoCollectionView.delegate = self;
- _videoCollectionView.dataSource = self;
- _videoCollectionView.showsVerticalScrollIndicator = NO;
- _videoCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _videoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _videoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
-
- [_videoCollectionView registerNib:[UINib nibWithNibName:@"HomeHotVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotVideoCell"];
- }
- return _videoCollectionView;
- }
- - (void)toVideoMorePage { // 约课-视频
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (NSMutableArray *)informationArray {
- if (!_informationArray) {
- _informationArray = [NSMutableArray array];
- }
- return _informationArray;
- }
- - (NSMutableArray *)liveListArray {
- if (!_liveListArray) {
- _liveListArray = [NSMutableArray array];
- }
- return _liveListArray;
- }
- - (HomeDragButton *)suspendButton {
- if (!_suspendButton) {
- _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
- MJWeakSelf;
- [_suspendButton clickAction:^{
- [weakSelf showDragWindowDetail];
- }];
- }
- return _suspendButton;
- }
- - (void)showDragWindowDetail {
- NSString *linkUrl = self.buttonModel.linkUrl;
- if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- else {
- if (![NSString isEmptyString:linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- /*
- #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
|