1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627 |
- //
- // 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-bookGroup"]) {
- HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
- [ctrl displayWithIndex:DISPLAY_INDEX_GROUP];
- [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.courseType = MUTIL_COURSE_TYPE_MUSIC;
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else if (type == RECENTCOURSE_TYPE_GROUP) { // 小组
- MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
- detailVC.courseType = MUTIL_COURSE_TYPE_GROUP;
- 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
|