HomeViewController.m 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. //
  2. // HomeViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "HomeViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "InstrumentChooseViewController.h"
  10. #import "NotiferMessageViewController.h"
  11. #import "HomeNavSearchView.h"
  12. #import "KSScanViewController.h"
  13. #import "HomeBannerView.h"
  14. #import <UIButton+WebCache.h>
  15. #import "TYCyclePagerView.h"
  16. #import "TYPageControl.h"
  17. #import "HomeBannerCell.h"
  18. #import "HomeButtonView.h"
  19. #import "KSHomeButton.h"
  20. #import "PublicNoticeView.h"
  21. #import <SDCycleScrollView.h>
  22. #import "NoticeSourceModel.h"
  23. #import "AppDelegate.h"
  24. #import "KSNewsAlert.h"
  25. #import "UserInfo.h"
  26. #import "UserInfoManager.h"
  27. #import "HomeRecentCourseView.h"
  28. #import "AccompanyDetailViewController.h"
  29. #import "MusicRoomDetailViewController.h"
  30. #import "VipCouseDetailViewController.h"
  31. #import "HomeHotAlbumView.h"
  32. #import "HomeAlbumModel.h"
  33. #import "HomeHotAlbumCell.h"
  34. #import "HomeHotMusicView.h"
  35. #import "HomeHotMusicCollectionCell.h"
  36. #import "KSPremissionAlert.h"
  37. #import <RecordCheckManager.h>
  38. #import "HomeHotTalentView.h"
  39. #import "HomeHotTalentCell.h"
  40. #import "TalentTeacherModel.h"
  41. #import "HomeHotVideoCourseView.h"
  42. #import "HomeHotVideoCell.h"
  43. #import "HomeVideoGroupModel.h"
  44. #import "HomeHotLiveCourseView.h"
  45. #import "HomeHotLiveCell.h"
  46. #import "HomeLiveGroupModel.h"
  47. #import "JXCategoryView.h"
  48. #import "JXPagerListRefreshView.h"
  49. #import "HomeInformationBodyView.h"
  50. #import "HomeTeacherLiveModel.h"
  51. #import "ToneTuningViewController.h"
  52. #import "KSAwardAlertView.h"
  53. #import "HomeNewMusicView.h"
  54. #import "HomeRecommendMusicView.h"
  55. #import "HomeMusicModel.h"
  56. #import "HomeDragButton.h"
  57. #import "HomeMusicSheetLayout.h"
  58. #import "HomeArrangeCourseController.h"
  59. #import "HomeCountView.h"
  60. #import "KSTabBarViewController.h"
  61. #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
  62. #define COLLECTION_HEIGHT (320)
  63. @interface HomeViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate,SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  64. @property (nonatomic, strong) UserInfo *mineInfo;
  65. @property (nonatomic, strong) HomeNavSearchView *navView;
  66. @property (nonatomic, strong) HomeMessageModel *flashModel;
  67. @property (nonatomic, assign) BOOL isFirstLoad;
  68. // banner
  69. @property (nonatomic, strong) TYPageControl *pageControl;
  70. @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
  71. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  72. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  73. @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
  74. // 统计
  75. @property (nonatomic, strong) HomeCountView *countView;
  76. @property (nonatomic, assign) CGFloat countViewHeight;
  77. // 按钮
  78. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  79. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  80. @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
  81. // 公告
  82. @property (nonatomic, strong) PublicNoticeView *noticeView;
  83. @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
  84. @property (nonatomic, strong) NSMutableArray *noticeArray; // notice数据
  85. @property (nonatomic, strong) NSMutableArray *noticeTitleArray; // 标题数组
  86. @property (nonatomic, assign) CGFloat noticeViewHeight;
  87. // 最近课程
  88. @property (nonatomic, strong) HomeRecentCourseView *courseView;
  89. @property (nonatomic, assign) CGFloat courseViewHeight;
  90. @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
  91. // 推荐老师
  92. @property (nonatomic, strong) HomeHotTalentView *talentView;
  93. @property (nonatomic, strong) UICollectionView *talentCollectionView; // 推荐老师容器
  94. @property (nonatomic, strong) NSMutableArray *talentArray; // 推荐老师数据
  95. @property (nonatomic, assign) CGFloat talentViewHeight; // talent 高度
  96. // 视频课
  97. @property (nonatomic, strong) HomeHotVideoCourseView *videoCourseView;
  98. @property (nonatomic, strong) UICollectionView *videoCollectionView; // 视频课容器
  99. @property (nonatomic, strong) NSMutableArray *videoCourseArray; // 视频课数据
  100. @property (nonatomic, assign) CGFloat videoViewHeight; // video 高度
  101. @property (nonatomic, strong) dispatch_group_t requestGroup;
  102. // 顶部数据容器
  103. @property (nonatomic, strong) UIView *headView;
  104. @property (nonatomic, strong) JXCategoryTitleView *myCategoryView;
  105. @property (nonatomic, assign) NSInteger currentIndex;
  106. @property (nonatomic, strong) NSMutableArray *listViewArray;
  107. @property (nonatomic, assign) NSInteger headViewHeight;
  108. @property (nonatomic, strong) NSMutableArray *liveListArray;
  109. @property (nonatomic, strong) NSMutableArray *informationArray;
  110. @property (nonatomic, strong) UIView *headBgView;
  111. @property (nonatomic, assign) BOOL isCheck;
  112. @property (nonatomic, strong) HomeMessageModel *buttonModel;
  113. @property (nonatomic, strong) HomeDragButton *suspendButton;
  114. @property (nonatomic, assign) CGFloat headheight;
  115. @end
  116. @implementation HomeViewController
  117. - (void)viewDidLoad {
  118. [super viewDidLoad];
  119. // Do any additional setup after loading the view.
  120. self.ks_prefersNavigationBarHidden = YES;
  121. _titles = @[@""];
  122. self.isFirstLoad = YES;
  123. [self configNavView];
  124. [self configUI];
  125. }
  126. - (void)requestTrackAuth {
  127. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  128. [appDelegate appTrackActionAuth];
  129. }
  130. - (void)configNavView {
  131. [self.scrollView removeFromSuperview];
  132. [self.view addSubview:self.navView];
  133. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.right.top.mas_equalTo(self.view);
  135. make.height.mas_equalTo(kNaviBarHeight);
  136. }];
  137. [self.view bringSubviewToFront:self.navView];
  138. }
  139. - (void)configHeadView {
  140. [self.headView addSubview:self.headBgView];
  141. // banner
  142. [self.headView addSubview:self.bannerView];
  143. self.bannerViewHeight = CGFLOAT_MIN;
  144. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.top.mas_equalTo(self.headView.mas_top).offset(12);
  146. make.left.right.mas_equalTo(self.headView);
  147. make.height.mas_equalTo(self.bannerViewHeight);
  148. }];
  149. self.bannerView.hidden = YES;
  150. // 统计
  151. [self.headView addSubview:self.countView];
  152. self.countViewHeight = [HomeCountView getViewHeight];
  153. [self.countView mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.left.right.mas_equalTo(self.headView);
  155. make.top.mas_equalTo(self.bannerView.mas_bottom);
  156. make.height.mas_equalTo(self.countViewHeight);
  157. }];
  158. // 最近课程
  159. [self.headView addSubview:self.courseView];
  160. self.courseViewHeight = CGFLOAT_MIN;
  161. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  162. make.left.right.mas_equalTo(self.headView);
  163. make.top.mas_equalTo(self.countView.mas_bottom);
  164. make.height.mas_equalTo(CGFLOAT_MIN);
  165. }];
  166. self.courseView.hidden = YES;
  167. // 公告
  168. [self.headView addSubview:self.noticeView];
  169. self.noticeViewHeight = CGFLOAT_MIN;
  170. [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.right.mas_equalTo(self.headView);
  172. make.top.mas_equalTo(self.courseView.mas_bottom);
  173. make.height.mas_equalTo(CGFLOAT_MIN);
  174. }];
  175. [self.noticeView.adView addSubview:self.noticeScrollView];
  176. [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.top.left.right.bottom.mas_equalTo(self.noticeView.adView);
  178. }];
  179. self.noticeView.hidden = YES;
  180. // 按钮
  181. [self.headView addSubview:self.buttonContainer];
  182. self.buttonViewHeight = CGFLOAT_MIN;
  183. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.left.right.mas_equalTo(self.headView);
  185. make.top.mas_equalTo(self.noticeView.mas_bottom);
  186. make.height.mas_equalTo(CGFLOAT_MIN);
  187. }];
  188. self.buttonContainer.hidden = YES;
  189. // 找老师
  190. [self.headView addSubview:self.talentView];
  191. self.talentViewHeight = CGFLOAT_MIN;
  192. [self.talentView mas_makeConstraints:^(MASConstraintMaker *make) {
  193. make.left.right.mas_equalTo(self.headView);
  194. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  195. make.height.mas_equalTo(self.talentViewHeight);
  196. }];
  197. self.talentView.hidden = YES;
  198. // 视频课
  199. [self.headView addSubview:self.videoCourseView];
  200. self.videoViewHeight = CGFLOAT_MIN;
  201. [self.videoCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.left.right.mas_equalTo(self.headView);
  203. make.top.mas_equalTo(self.talentView.mas_bottom);
  204. make.height.mas_equalTo(self.videoViewHeight);
  205. }];
  206. self.videoCourseView.hidden = YES;
  207. [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.left.right.mas_equalTo(self.headView);
  209. make.top.mas_equalTo(self.headView.mas_top);
  210. make.bottom.mas_equalTo(self.buttonContainer.mas_bottom);
  211. }];
  212. self.headBgView.layer.masksToBounds = YES;
  213. self.headBgView.layer.cornerRadius = 18.0f;
  214. self.headBgView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
  215. [self refreshHeadHeight];
  216. }
  217. - (void)refreshHeadHeight {
  218. CGFloat headSpace = 12.0f;
  219. CGFloat bottomSpace = 0.0f;
  220. self.headViewHeight = headSpace + self.bannerViewHeight + self.countViewHeight + self.courseViewHeight + self.noticeViewHeight + self.buttonViewHeight + self.talentViewHeight + self.videoViewHeight + bottomSpace;
  221. self.headView.frame = CGRectMake(0, 0, KPortraitWidth, self.headViewHeight);
  222. [self.pagerView resizeTableHeaderViewHeightWithAnimatable:NO duration:0.3f curve:UIViewAnimationCurveEaseInOut];
  223. }
  224. - (void)configUI {
  225. [self configHeadView];
  226. self.headheight = CGFLOAT_MIN;
  227. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNaviBarHeight, KPortraitWidth, self.headheight)];
  228. self.categoryView.backgroundColor = [UIColor clearColor];
  229. self.categoryView.titles = self.titles;
  230. self.categoryView.delegate = self;
  231. self.categoryView.titleFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
  232. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
  233. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  234. self.categoryView.titleColor = HexRGB(0x999999);
  235. self.categoryView.titleColorGradientEnabled = YES;
  236. self.categoryView.cellWidth = 90.0f;
  237. self.categoryView.cellSpacing = 16.0f;
  238. self.categoryView.averageCellSpacingEnabled = NO;
  239. _pagerView = [self preferredPagingView];
  240. self.pagerView.frame = CGRectMake(0, kNaviBarHeight, KPortraitWidth, KPortraitHeight - kNaviBarHeight - kTabBarHeight);
  241. self.pagerView.mainTableView.gestureDelegate = self;
  242. [self.view addSubview:self.pagerView];
  243. self.pagerView.backgroundColor = [UIColor clearColor];
  244. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  245. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  246. // 头部刷新
  247. MJWeakSelf;
  248. self.pagerView.mainTableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  249. [weakSelf requestData];
  250. }];
  251. }
  252. - (void)viewDidAppear:(BOOL)animated {
  253. [super viewDidAppear:animated];
  254. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  255. }
  256. - (JXPagerView *)preferredPagingView {
  257. return [[JXPagerView alloc] initWithDelegate:self];
  258. }
  259. - (void)viewWillAppear:(BOOL)animated {
  260. [super viewWillAppear:animated];
  261. if (self.isFirstLoad == YES) {
  262. [self requestUserInfo:YES]; // 获取声部
  263. [self requestTrackAuth];
  264. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  265. [appDelegate handleNotiferSource];
  266. }
  267. else {
  268. [self requestUserInfo:NO];
  269. }
  270. [self requestUnreadCount];
  271. }
  272. - (void)requestAwardMessage {
  273. self.isCheck = NO;
  274. dispatch_group_enter(self.requestGroup);
  275. [KSNetworkingManager checkReceiveRewardRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  276. dispatch_group_leave(self.requestGroup);
  277. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  278. BOOL isCheck = [[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"check"];
  279. self.isCheck = isCheck;
  280. }
  281. } faliure:^(NSError * _Nonnull error) {
  282. dispatch_group_leave(self.requestGroup);
  283. }];
  284. }
  285. - (BOOL)checkHasShowAwardAlert {
  286. NSDictionary *awardAlertDic = UserDefaultObjectForKey(@"awardAlertConfig");
  287. NSDate *currendDate = [NSDate date];
  288. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  289. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  290. NSString *todayString = [dateFormatter stringFromDate:currendDate];
  291. if (awardAlertDic) {
  292. NSString *awardAlertTime = [awardAlertDic ks_stringValueForKey:@"time"];
  293. if (![NSString isEmptyString:awardAlertTime]) {
  294. NSString *userId = [awardAlertDic ks_stringValueForKey:@"userId"];
  295. if ([todayString isEqualToString:awardAlertTime] && [userId isEqualToString:UserDefaultObjectForKey(UIDKey)]) {
  296. return YES;
  297. }
  298. }
  299. }
  300. return NO;
  301. }
  302. - (void)checkShowAwardAlert {
  303. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  304. if (appDelegate.isShowMemoAlert) {
  305. return;
  306. }
  307. if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
  308. return;
  309. }
  310. KSAwardAlertView *alert = [KSAwardAlertView shareInstance];
  311. MJWeakSelf;
  312. [alert awardActionCallback:^(BOOL isSure) {
  313. if (isSure) {
  314. [weakSelf displayAwardList];
  315. }
  316. }];
  317. [alert showAlert];
  318. NSDate *currendDate = [NSDate date];
  319. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  320. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  321. NSString *todayString = [dateFormatter stringFromDate:currendDate];
  322. NSDictionary *saveDic = @{@"time" :todayString , @"userId" : UserDefaultObjectForKey(UIDKey)};
  323. UserDefaultSetObjectForKey(saveDic, @"awardAlertConfig");
  324. }
  325. - (void)displayAwardList {
  326. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  327. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
  328. [self.navigationController pushViewController:webCtrl animated:YES];
  329. }
  330. - (void)requestUnreadCount {
  331. [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  332. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  333. NSArray *countArray = [dic ks_arrayValueForKey:@"data"];
  334. NSInteger courseCount = 0;
  335. NSInteger sysCount = 0;
  336. for (NSDictionary *parm in countArray) {
  337. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
  338. courseCount = [parm ks_integerValueForKey:@"value"];
  339. }
  340. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
  341. sysCount = [parm ks_integerValueForKey:@"value"];
  342. }
  343. }
  344. if (courseCount != 0 || sysCount != 0) {
  345. self.navView.dotView.hidden = NO;
  346. }
  347. else {
  348. self.navView.dotView.hidden = YES;
  349. }
  350. }
  351. else {
  352. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  353. }
  354. } faliure:^(NSError * _Nonnull error) {
  355. }];
  356. }
  357. - (void)requestUserInfo:(BOOL)checkSubject {
  358. self.isFirstLoad = NO;
  359. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  360. self.mineInfo = userInfo;
  361. [self refreshSource:checkSubject];
  362. }];
  363. }
  364. - (void)refreshSource:(BOOL)checkSubject {
  365. if (checkSubject) {
  366. if ([NSString isEmptyString:self.mineInfo.subjectName]) {
  367. [self showInstrumentView:YES];
  368. }
  369. else {
  370. [self requestData];
  371. }
  372. }
  373. else { // 刷新老师数据
  374. [self refreshTalentAndRefresh];
  375. }
  376. }
  377. - (void)showInstrumentView:(BOOL)hideBackButton {
  378. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  379. MJWeakSelf;
  380. [ctrl chooseCallback:^{
  381. [weakSelf requestUserInfo:NO];
  382. [weakSelf requestData];
  383. }];
  384. if (hideBackButton) {
  385. ctrl.isModalPresent = YES;
  386. CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
  387. navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
  388. [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
  389. }
  390. else {
  391. [self.navigationController pushViewController:ctrl animated:YES];
  392. }
  393. }
  394. - (void)requestNewsList {
  395. dispatch_group_enter(self.requestGroup);
  396. [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  397. dispatch_group_leave(self.requestGroup);
  398. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  399. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  400. // banner
  401. NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
  402. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  403. for (NSDictionary *parm in bannerArray) {
  404. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  405. [bannerInfoArray addObject:model];
  406. }
  407. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  408. // button
  409. NSArray *buttonArray = [result ks_arrayValueForKey:@"appMenu"];
  410. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  411. for (NSDictionary *parm in buttonArray) {
  412. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  413. [buttonInfoArray addObject:model];
  414. }
  415. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  416. // news
  417. NSArray *flashArray = [result ks_arrayValueForKey:@"flashPage"];
  418. if (flashArray.count) {
  419. self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
  420. }
  421. // 首页悬浮按钮
  422. NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
  423. if (suspensionArray.count) {
  424. self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
  425. }
  426. else {
  427. self.buttonModel = nil;
  428. }
  429. }
  430. else {
  431. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  432. }
  433. } faliure:^(NSError * _Nonnull error) {
  434. dispatch_group_leave(self.requestGroup);
  435. }];
  436. }
  437. - (void)requestStatistics {
  438. dispatch_group_enter(self.requestGroup);
  439. [KSNetworkingManager homeSummaryRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  440. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  441. [self.countView configWithSource:[dic ks_dictionaryValueForKey:@"data"]];
  442. }
  443. dispatch_group_leave(self.requestGroup);
  444. } faliure:^(NSError * _Nonnull error) {
  445. dispatch_group_leave(self.requestGroup);
  446. }];
  447. }
  448. - (void)requestCourseInfo {
  449. dispatch_group_enter(self.requestGroup);
  450. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  451. dispatch_group_leave(self.requestGroup);
  452. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  453. NSDictionary *sourceDic = [dic ks_dictionaryValueForKey:@"data"];
  454. NSArray *videoList = [sourceDic ks_arrayValueForKey:@"videoList"];
  455. NSMutableArray *videoCourse = [NSMutableArray array];
  456. for (NSDictionary *parm in videoList) {
  457. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  458. [videoCourse addObject:model];
  459. }
  460. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  461. // 最近课程
  462. NSDictionary *parm = [sourceDic ks_dictionaryValueForKey:@"recentCourses"];
  463. if (parm == nil) {
  464. self.recentCourseModel = nil;
  465. }
  466. else {
  467. self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
  468. }
  469. }
  470. else {
  471. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  472. }
  473. } faliure:^(NSError * _Nonnull error) {
  474. dispatch_group_leave(self.requestGroup);
  475. }];
  476. }
  477. - (void)requestNotice {
  478. dispatch_group_enter(self.requestGroup);
  479. [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  480. dispatch_group_leave(self.requestGroup);
  481. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  482. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  483. if (sourceArray.count) {
  484. NSDictionary *parm = [sourceArray firstObject];
  485. NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
  486. [self.noticeArray addObject:bannerModel];
  487. [self.noticeTitleArray addObject:bannerModel.title];
  488. }
  489. else {
  490. self.noticeArray = [NSMutableArray array];
  491. self.noticeTitleArray = [NSMutableArray array];
  492. }
  493. }
  494. else {
  495. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  496. }
  497. } faliure:^(NSError * _Nonnull error) {
  498. dispatch_group_leave(self.requestGroup);
  499. }];
  500. }
  501. - (void)requestTalentSource {
  502. dispatch_group_enter(self.requestGroup);
  503. [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  504. dispatch_group_leave(self.requestGroup);
  505. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  506. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  507. NSMutableArray *talentArray = [NSMutableArray array];
  508. for (NSDictionary *parm in sourceArray) {
  509. TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
  510. [talentArray addObject:model];
  511. }
  512. self.talentArray = [NSMutableArray arrayWithArray:talentArray];
  513. }
  514. else {
  515. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  516. }
  517. } faliure:^(NSError * _Nonnull error) {
  518. dispatch_group_leave(self.requestGroup);
  519. }];
  520. }
  521. - (void)refreshTalentAndRefresh {
  522. [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  523. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  524. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  525. NSMutableArray *talentArray = [NSMutableArray array];
  526. for (NSDictionary *parm in sourceArray) {
  527. TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
  528. [talentArray addObject:model];
  529. }
  530. self.talentArray = [NSMutableArray arrayWithArray:talentArray];
  531. }
  532. else {
  533. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  534. }
  535. [self refreshTalentView];
  536. } faliure:^(NSError * _Nonnull error) {
  537. }];
  538. }
  539. - (void)requestLiveList {
  540. dispatch_group_enter(self.requestGroup);
  541. [KSNetworkingManager queryTeacherLivingListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  542. dispatch_group_leave(self.requestGroup);
  543. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  544. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  545. NSMutableArray *liveListArray = [NSMutableArray array];
  546. for (NSDictionary *parm in sourceArray) {
  547. HomeTeacherLiveModel *model = [[HomeTeacherLiveModel alloc] initWithDictionary:parm];
  548. [liveListArray addObject:model];
  549. }
  550. self.liveListArray = [NSMutableArray arrayWithArray:liveListArray];
  551. }
  552. else {
  553. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  554. }
  555. } faliure:^(NSError * _Nonnull error) {
  556. dispatch_group_leave(self.requestGroup);
  557. }];
  558. }
  559. - (void)requestInformationList {
  560. dispatch_group_enter(self.requestGroup);
  561. [KSNetworkingManager informationListRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  562. dispatch_group_leave(self.requestGroup);
  563. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  564. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  565. NSMutableArray *informationInfoArray = [NSMutableArray array];
  566. for (NSDictionary *parm in sourceArray) {
  567. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  568. [informationInfoArray addObject:model];
  569. }
  570. self.informationArray = [NSMutableArray arrayWithArray:informationInfoArray];
  571. }
  572. else {
  573. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  574. }
  575. } faliure:^(NSError * _Nonnull error) {
  576. dispatch_group_leave(self.requestGroup);
  577. }];
  578. }
  579. - (void)requestData {
  580. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  581. [self requestNewsList];
  582. [self requestStatistics];
  583. [self requestNotice];
  584. [self requestCourseInfo];
  585. // 老师
  586. [self requestTalentSource];
  587. [self requestLiveList];
  588. [self requestInformationList];
  589. if ([self checkHasShowAwardAlert] == NO) {
  590. [self requestAwardMessage];
  591. }
  592. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  593. [LOADING_MANAGER removeCustomLoading];
  594. [self.pagerView.mainTableView.mj_header endRefreshing];
  595. [self refreshView];
  596. });
  597. }
  598. - (void)refreshView {
  599. [self refreshBannaerView];
  600. [self showButtonMessage];
  601. [self refreshNotice];
  602. [self refreshCourseView:self.recentCourseModel];
  603. // 老师
  604. [self refreshTalentView];
  605. // 课程
  606. [self refreshCourseView];
  607. [self refreshHeadHeight];
  608. [self refreshPageView];
  609. if (self.isCheck && [self checkHasShowAwardAlert] == NO) {
  610. [self checkShowAwardAlert];
  611. }
  612. else {
  613. if (self.flashModel) {
  614. [self showNewsWithSource:self.flashModel];
  615. }
  616. }
  617. // 悬浮按钮
  618. if (self.buttonModel) {
  619. [self showFloatingWindow];
  620. }
  621. else {
  622. [self removeFloatWindow];
  623. }
  624. }
  625. - (void)removeFloatWindow {
  626. if ([self.view.subviews containsObject:self.suspendButton]) {
  627. [self.suspendButton removeFromSuperview];
  628. }
  629. }
  630. // 显示悬浮窗
  631. - (void)showFloatingWindow {
  632. if (![self.view.subviews containsObject:self.suspendButton]) {
  633. [self.view addSubview:self.suspendButton];
  634. }
  635. [self.view bringSubviewToFront:self.suspendButton];
  636. [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
  637. }
  638. - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
  639. // 登录之后才弹窗
  640. if ([self checkIsLoginToLoginView:NO]) {
  641. [self displayAlert:sourceModel];
  642. }
  643. }
  644. - (void)displayAlert:(HomeMessageModel *)sourceModel {
  645. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  646. if (appDelegate.isShowMemoAlert) {
  647. return;
  648. }
  649. if (USER_MANAGER.hasShowFlash) {
  650. return;
  651. }
  652. if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
  653. return;
  654. }
  655. KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
  656. MJWeakSelf;
  657. [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
  658. appDelegate.isShowFlashAlert = NO;
  659. if (isSure) {
  660. if (![NSString isEmptyString:linkUrl]) {
  661. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  662. webCtrl.url = [linkUrl getUrlEndcodeString];
  663. [weakSelf.navigationController pushViewController:webCtrl animated:YES];
  664. }
  665. }
  666. [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
  667. }];
  668. [newAlert showAlert];
  669. appDelegate.isShowFlashAlert = YES;
  670. USER_MANAGER.hasShowFlash = YES; // 已展示过flash
  671. }
  672. - (void)refreshPageView {
  673. for (NSInteger i = 0; i < self.listViewArray.count; i++) {
  674. id view = self.listViewArray[i];
  675. if ([view isKindOfClass:[HomeInformationBodyView class]]) {
  676. HomeInformationBodyView *informationView = (HomeInformationBodyView *)view;
  677. informationView.informationArray = [self.informationArray mutableCopy];
  678. [informationView beginFirstRefresh];
  679. }
  680. }
  681. }
  682. - (void)refreshTalentView {
  683. if (self.talentArray.count) {
  684. self.talentViewHeight = [HomeHotTalentView getViewHeight];
  685. self.talentView.hidden = NO;
  686. }
  687. else {
  688. self.talentViewHeight = CGFLOAT_MIN;
  689. self.talentView.hidden = YES;
  690. }
  691. [self.talentView mas_updateConstraints:^(MASConstraintMaker *make) {
  692. make.height.mas_equalTo(self.talentViewHeight);
  693. }];
  694. [self.talentCollectionView reloadData];
  695. }
  696. - (void)refreshBannaerView {
  697. if (self.bannerArray.count > 0) {
  698. self.bannerViewHeight = [HomeBannerView getViewHeight];
  699. self.bannerView.hidden = NO;
  700. }
  701. else {
  702. self.bannerViewHeight = CGFLOAT_MIN;
  703. self.bannerView.hidden = YES;
  704. }
  705. if (self.bannerArray.count > 1) {
  706. self.bannerScroll.autoScrollInterval = 3.0f;
  707. [self.bannerScroll addSubview:self.pageControl];
  708. }
  709. else {
  710. self.bannerScroll.autoScrollInterval = 0;
  711. [self.pageControl removeFromSuperview];
  712. }
  713. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  714. make.height.mas_equalTo(self.bannerViewHeight);
  715. }];
  716. _pageControl.numberOfPages = self.bannerArray.count;
  717. [self.bannerScroll reloadData];
  718. }
  719. - (void)showButtonMessage {
  720. [self.buttonContainer.buttonContentView removeAllSubViews];
  721. CGFloat buttonSpace = (KPortraitWidth - BUTTON_ROWCOUNT * HOME_BUTTONWIDTH) / (BUTTON_ROWCOUNT /*+ 1*/);
  722. // 添加按钮
  723. if (self.buttonArray.count) {
  724. self.buttonContainer.hidden = NO;
  725. CGFloat xSpace = 0.0f;
  726. CGFloat ySpace = 0.0f;
  727. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  728. xSpace = buttonSpace / 2 + (i % BUTTON_ROWCOUNT) * (HOME_BUTTONWIDTH + buttonSpace);
  729. ySpace = (i / BUTTON_ROWCOUNT) * (HOME_BUTTONHEIGHT + HOME_BUTTON_VERTICAL_SPACE);
  730. HomeMessageModel *model = self.buttonArray[i];
  731. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  732. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  733. buttonView.buttonTitle.text = model.title;
  734. buttonView.frame = CGRectMake(xSpace, ySpace, HOME_BUTTONWIDTH, HOME_BUTTONHEIGHT);
  735. buttonView.actionButton.tag = 3000 + i;
  736. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  737. [self.buttonContainer.buttonContentView addSubview:buttonView];
  738. }
  739. }
  740. else {
  741. self.buttonContainer.hidden = YES;
  742. }
  743. // 高度
  744. CGFloat buttonViewDefaultHeight = [HomeButtonView getViewHeight:self.buttonArray.count];
  745. self.buttonViewHeight = buttonViewDefaultHeight;
  746. [self.buttonContainer mas_updateConstraints:^(MASConstraintMaker *make) {
  747. make.height.mas_equalTo(buttonViewDefaultHeight);
  748. }];
  749. }
  750. - (void)HomeTopButtonAction:(UIButton *)sender {
  751. NSInteger index = sender.tag - 3000;
  752. if ([self checkIsLoginToLoginView:YES]) {
  753. HomeMessageModel *model = self.buttonArray[index];
  754. if (![NSString isEmptyString:model.linkUrl]) {
  755. if ([model.linkUrl isEqualToString:@"native-metronome"]) {
  756. ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
  757. [self.navigationController pushViewController:ctrl animated:YES];
  758. }
  759. else if ([model.linkUrl isEqualToString:@"native-bookVip"]) {
  760. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  761. [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
  762. [self.navigationController pushViewController:ctrl animated:YES];
  763. }
  764. else if ([model.linkUrl isEqualToString:@"native-bookAccompany"]) {
  765. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  766. [ctrl displayWithIndex:DISPLAY_INDEX_FIRST];
  767. [self.navigationController pushViewController:ctrl animated:YES];
  768. }
  769. else if ([model.linkUrl isEqualToString:@"native-bookGroup"]) {
  770. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  771. [ctrl displayWithIndex:DISPLAY_INDEX_GROUP];
  772. [self.navigationController pushViewController:ctrl animated:YES];
  773. }
  774. else if ([model.linkUrl isEqualToString:@"native-bookLive"]) {
  775. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  776. [ctrl displayWithIndex:DISPLAY_INDEX_LIVE];
  777. [self.navigationController pushViewController:ctrl animated:YES];
  778. }
  779. else if ([model.linkUrl isEqualToString:@"native-bookVideo"]) {
  780. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  781. [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
  782. [self.navigationController pushViewController:ctrl animated:YES];
  783. }
  784. else {
  785. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  786. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  787. [self.navigationController pushViewController:webCtrl animated:YES];
  788. }
  789. }
  790. }
  791. }
  792. - (void)refreshNotice {
  793. if (self.noticeTitleArray.count) {
  794. self.noticeView.hidden = NO;
  795. CGFloat height = [PublicNoticeView getViewHeight];
  796. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  797. make.height.mas_equalTo(height);
  798. }];
  799. self.noticeViewHeight = height;
  800. }
  801. else {
  802. self.noticeView.hidden = YES;
  803. self.noticeViewHeight = CGFLOAT_MIN;
  804. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  805. make.height.mas_equalTo(CGFLOAT_MIN);
  806. }];
  807. }
  808. self.noticeScrollView.titlesGroup = self.noticeTitleArray;
  809. }
  810. - (void)refreshCourseView:(RecentCourseModel *)model {
  811. if (model) {
  812. [self.courseView configCourseMessage:model];
  813. self.courseView.hidden = NO;
  814. self.courseViewHeight = [HomeRecentCourseView getViewHeight];
  815. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  816. make.height.mas_equalTo(self.courseViewHeight);
  817. }];
  818. }
  819. else {
  820. self.courseView.hidden = YES;
  821. self.courseViewHeight = CGFLOAT_MIN;
  822. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  823. make.height.mas_equalTo(self.courseViewHeight);
  824. }];
  825. }
  826. }
  827. - (void)refreshCourseView {
  828. if (self.videoCourseArray.count) {
  829. self.videoViewHeight = [HomeHotVideoCourseView getViewHeight];
  830. self.videoCourseView.hidden = NO;
  831. }
  832. else {
  833. self.videoViewHeight = CGFLOAT_MIN;
  834. self.videoCourseView.hidden = YES;
  835. }
  836. [self.videoCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  837. make.height.mas_equalTo(self.videoViewHeight);
  838. }];
  839. [self.videoCollectionView reloadData];
  840. }
  841. #pragma mark - JXPagerViewDelegate
  842. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  843. return self.headView;
  844. }
  845. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  846. return self.headViewHeight;
  847. }
  848. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  849. return self.categoryView;
  850. }
  851. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  852. return self.headheight;
  853. }
  854. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  855. //和categoryView的item数量一致
  856. return self.titles.count;
  857. }
  858. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  859. HomeInformationBodyView *listView = [[HomeInformationBodyView alloc] init];
  860. listView.naviController = self.navigationController;
  861. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  862. self.listViewArray[index] = listView;
  863. listView.selectIndex = index;
  864. listView.informationArray = [self.informationArray mutableCopy];
  865. [listView beginFirstRefresh];
  866. return listView;
  867. }
  868. #pragma mark - JXCategoryViewDelegate
  869. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  870. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  871. if (self.listViewArray.count > index) {
  872. id value = self.listViewArray[index];
  873. if ([value isKindOfClass:[KSJXBodyView class]]) {
  874. KSJXBodyView *listView = (KSJXBodyView *)value;
  875. [listView beginFirstRefresh];
  876. }
  877. }
  878. }
  879. #pragma mark - JXPagerMainTableViewGestureDelegate
  880. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  881. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  882. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  883. return NO;
  884. }
  885. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  886. }
  887. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  888. NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y);
  889. NSInteger height = self.headViewHeight;
  890. CGFloat space = scrollView.contentOffset.y;
  891. if (space > 0) {
  892. self.navView.lineView.hidden = NO;
  893. }
  894. else {
  895. self.navView.lineView.hidden = YES;
  896. }
  897. if (space >= height) {
  898. self.categoryView.backgroundColor = [UIColor whiteColor];
  899. }
  900. else {
  901. self.categoryView.backgroundColor = [UIColor clearColor];
  902. }
  903. }
  904. #pragma mark - TYCyclePagerViewDataSource代理
  905. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  906. return self.bannerArray.count;
  907. }
  908. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  909. HomeMessageModel *model = self.bannerArray[index];
  910. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  911. [cell configCellWithModel:model];
  912. return cell;
  913. }
  914. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  915. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  916. layout.itemSize = CGSizeMake(KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
  917. layout.itemSpacing = 0;
  918. return layout;
  919. }
  920. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  921. if (pageView == self.bannerScroll) {
  922. [self.pageControl setCurrentPage:toIndex animate:YES];
  923. }
  924. }
  925. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  926. HomeMessageModel *model = self.bannerArray[index];
  927. if (![NSString isEmptyString:model.linkUrl]) {
  928. if ([model.linkType isEqualToString:@"OUT"]) {
  929. // 外部浏览器打开
  930. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  931. }
  932. else {
  933. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  934. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  935. [self.navigationController pushViewController:webCtrl animated:YES];
  936. }
  937. }
  938. }
  939. #pragma mark ---- collection data source
  940. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  941. return 1;
  942. }
  943. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  944. if (collectionView == self.talentCollectionView) { // 推荐老师
  945. return self.talentArray.count;
  946. }
  947. else/* if (collectionView == self.videoCollectionView)*/ { // 视频课
  948. return self.videoCourseArray.count;
  949. }
  950. }
  951. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  952. if (collectionView == self.talentCollectionView) {
  953. TalentTeacherModel *talentModel = self.talentArray[indexPath.item];
  954. HomeHotTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotTalentCell" forIndexPath:indexPath];
  955. MJWeakSelf;
  956. [cell configWithSource:talentModel callback:^(NSString *teacherId) {
  957. [weakSelf followTalentTeacher:teacherId];
  958. }];
  959. return cell;
  960. }
  961. else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
  962. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.item];
  963. HomeHotVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotVideoCell" forIndexPath:indexPath];
  964. [cell configWithSource:model];
  965. return cell;
  966. }
  967. }
  968. - (void)followTalentTeacher:(NSString *)teacherId {
  969. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  970. [KSNetworkingManager starOrUnStarRequest:KS_GET userId:teacherId starStatus:@"1" success:^(NSDictionary * _Nonnull dic) {
  971. [LOADING_MANAGER removeCustomLoading];
  972. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  973. [LOADING_MANAGER KSShowMsg:@"关注成功" promptCompletion:^{
  974. [self requestData];
  975. }];
  976. }
  977. else {
  978. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  979. }
  980. } faliure:^(NSError * _Nonnull error) {
  981. [LOADING_MANAGER removeCustomLoading];
  982. }];
  983. }
  984. - (void)displaySongDetail:(NSString *)songId {
  985. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  986. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  987. [self.navigationController pushViewController:ctrl animated:YES];
  988. }
  989. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  990. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  991. } confirm:^{
  992. [self openSettingView];
  993. }];
  994. }
  995. - (void)openSettingView {
  996. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  997. }
  998. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  999. if (collectionView == self.talentCollectionView) { // 老师风采
  1000. TalentTeacherModel *model = self.talentArray[indexPath.item];
  1001. [self displayTeacherDetail:[NSString stringWithFormat:@"%.0f",model.userId]];
  1002. }
  1003. else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
  1004. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  1005. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  1006. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1007. ctrl.url = url;
  1008. [self.navigationController pushViewController:ctrl animated:YES];
  1009. }
  1010. }
  1011. // 老师风采
  1012. - (void)displayTeacherDetail:(NSString *)teacherId {
  1013. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1014. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  1015. [self.navigationController pushViewController:ctrl animated:YES];
  1016. }
  1017. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  1018. if (collectionView == self.talentCollectionView) {
  1019. return CGSizeMake(104, 146);
  1020. }
  1021. else if (collectionView == self.videoCollectionView) {
  1022. if (IS_IPAD) {
  1023. return CGSizeMake(205, 158);
  1024. }
  1025. return CGSizeMake(168, 158);
  1026. }
  1027. else {
  1028. return CGSizeMake(168, 158);
  1029. }
  1030. }
  1031. #pragma mark ----- SDCycleScrollViewDelegate
  1032. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  1033. NoticeSourceModel *noticeModel = self.noticeArray[index];
  1034. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1035. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
  1036. [self.navigationController pushViewController:webCtrl animated:YES];
  1037. }
  1038. #pragma mark ------- lazying
  1039. - (HomeNavSearchView *)navView {
  1040. if (!_navView) {
  1041. _navView = [HomeNavSearchView shareInstance];
  1042. MJWeakSelf;
  1043. [_navView homeNavSearchAction:^(HOMENAV_TAG action) {
  1044. [weakSelf homeNavAction:action];
  1045. }];
  1046. }
  1047. return _navView;
  1048. }
  1049. - (void)homeNavAction:(HOMENAV_TAG)action {
  1050. switch (action) {
  1051. case HOMENAV_TAG_SCAN: // 扫一扫
  1052. {
  1053. [self showScanView];
  1054. }
  1055. break;
  1056. case HOMENAV_TAG_MESSAGE: // 消息
  1057. {
  1058. NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
  1059. [self.navigationController pushViewController:ctrl animated:YES];
  1060. }
  1061. break;
  1062. case HOMENAV_TAG_SMALLTOOL: // 小工具
  1063. {
  1064. ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
  1065. [self.navigationController pushViewController:ctrl animated:YES];
  1066. }
  1067. break;
  1068. default:
  1069. break;
  1070. }
  1071. }
  1072. - (void)showScanView {
  1073. // 判断是否有权限
  1074. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  1075. if (type == PREMISSIONTYPE_YES) {
  1076. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  1077. [self.navigationController pushViewController:ctrl animated:YES];
  1078. }
  1079. else {
  1080. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  1081. }
  1082. }];
  1083. }
  1084. - (dispatch_group_t)requestGroup {
  1085. if (!_requestGroup) {
  1086. _requestGroup = dispatch_group_create();
  1087. }
  1088. return _requestGroup;
  1089. }
  1090. - (UIView *)headView {
  1091. if (!_headView) {
  1092. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, CGFLOAT_MIN)];
  1093. _headView.backgroundColor = [UIColor clearColor];
  1094. }
  1095. return _headView;
  1096. }
  1097. - (NSMutableArray *)listViewArray {
  1098. if (!_listViewArray) {
  1099. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]];
  1100. }
  1101. return _listViewArray;
  1102. }
  1103. - (HomeBannerView *)bannerView {
  1104. if (!_bannerView) {
  1105. _bannerView = [HomeBannerView shareInstance];
  1106. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  1107. }
  1108. return _bannerView;
  1109. }
  1110. #pragma mark --- banner
  1111. - (TYCyclePagerView *)bannerScroll {
  1112. if (!_bannerScroll) {
  1113. _bannerScroll = [[TYCyclePagerView alloc] init];
  1114. _bannerScroll.backgroundColor = [UIColor clearColor];
  1115. _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
  1116. _bannerScroll.isInfiniteLoop = YES;
  1117. _bannerScroll.autoScrollInterval = 3.0f;
  1118. _bannerScroll.reloadDataNeedResetIndex = YES;
  1119. _bannerScroll.dataSource = self;
  1120. _bannerScroll.delegate = self;
  1121. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  1122. if (@available(iOS 11.0, *)) {
  1123. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1124. } else {
  1125. // Fallback on earlier versions
  1126. if (@available(iOS 13.0, *)) {
  1127. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1128. } else {
  1129. // Fallback on earlier versions
  1130. }
  1131. }
  1132. }
  1133. return _bannerScroll;
  1134. }
  1135. - (TYPageControl *)pageControl {
  1136. if (!_pageControl) {
  1137. _pageControl = [[TYPageControl alloc] init];
  1138. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  1139. _pageControl.pageIndicatorSpaing = 4.0f;
  1140. _pageControl.frame = CGRectMake(0, (KPortraitWidth - 28) * 132 / 347 - 20, KPortraitWidth-28 - 12, 12);
  1141. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  1142. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  1143. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  1144. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  1145. }
  1146. return _pageControl;
  1147. }
  1148. - (NSMutableArray *)bannerArray {
  1149. if (!_bannerArray) {
  1150. _bannerArray = [NSMutableArray array];
  1151. }
  1152. return _bannerArray;
  1153. }
  1154. #pragma mark ---- scroll view delegate
  1155. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1156. }
  1157. #pragma mark ---- countView
  1158. - (HomeCountView *)countView {
  1159. if (!_countView) {
  1160. _countView = [HomeCountView sharedInstance];
  1161. MJWeakSelf;
  1162. [_countView countActionCallback:^(BOOL showCourseTable) {
  1163. [weakSelf homeStatisticsAction:showCourseTable];
  1164. }];
  1165. }
  1166. return _countView;
  1167. }
  1168. - (void)homeStatisticsAction:(BOOL)showCourseTable {
  1169. if (showCourseTable) {
  1170. [(KSTabBarViewController *)self.tabBarController tabBarSelectedWithIndex:2];
  1171. }
  1172. else {
  1173. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1174. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
  1175. [self.navigationController pushViewController:ctrl animated:YES];
  1176. }
  1177. }
  1178. #pragma mark ---- button container
  1179. - (HomeButtonView *)buttonContainer {
  1180. if (!_buttonContainer) {
  1181. _buttonContainer = [HomeButtonView shareInstance];
  1182. }
  1183. return _buttonContainer;
  1184. }
  1185. #pragma mark ---- notice view
  1186. - (UIView *)headBgView {
  1187. if (!_headBgView) {
  1188. _headBgView = [[UIView alloc] init];
  1189. _headBgView.backgroundColor = [UIColor whiteColor];
  1190. }
  1191. return _headBgView;
  1192. }
  1193. - (PublicNoticeView *)noticeView {
  1194. if (!_noticeView) {
  1195. _noticeView = [PublicNoticeView shareInstance];
  1196. MJWeakSelf;
  1197. [_noticeView moreCallback:^{
  1198. [weakSelf moreNotice];
  1199. }];
  1200. }
  1201. return _noticeView;
  1202. }
  1203. - (NSMutableArray *)noticeArray {
  1204. if (!_noticeArray) {
  1205. _noticeArray = [NSMutableArray array];
  1206. }
  1207. return _noticeArray;
  1208. }
  1209. - (NSMutableArray *)noticeTitleArray {
  1210. if (!_noticeTitleArray) {
  1211. _noticeTitleArray = [NSMutableArray array];
  1212. }
  1213. return _noticeTitleArray;
  1214. }
  1215. - (void)moreNotice {
  1216. if (self.noticeArray.count) {
  1217. NoticeSourceModel *bannerModel = self.noticeArray[0];
  1218. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1219. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  1220. [self.navigationController pushViewController:webCtrl animated:YES];
  1221. }
  1222. }
  1223. - (SDCycleScrollView *)noticeScrollView {
  1224. if (!_noticeScrollView) {
  1225. _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
  1226. _noticeScrollView.onlyDisplayText = YES;
  1227. _noticeScrollView.autoScroll = NO;
  1228. _noticeScrollView.scrollEnabled = NO;
  1229. _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
  1230. _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
  1231. _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor];
  1232. _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
  1233. _noticeScrollView.titlesGroup = self.noticeTitleArray;
  1234. }
  1235. return _noticeScrollView;
  1236. }
  1237. - (HomeRecentCourseView *)courseView {
  1238. if (!_courseView) {
  1239. _courseView = [HomeRecentCourseView shareInstance];
  1240. MJWeakSelf;
  1241. [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
  1242. [weakSelf joinRoomAction:type courseMessage:courseModel];
  1243. }];
  1244. }
  1245. return _courseView;
  1246. }
  1247. - (void)joinRoomAction:(RECENTCOURSE_TYPE)type courseMessage:(RecentCourseModel *)courseModel {
  1248. if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
  1249. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  1250. detailVC.courseId = courseModel.courseId;
  1251. detailVC.courseGroupId = courseModel.courseGroupId;
  1252. [self.navigationController pushViewController:detailVC animated:YES];
  1253. }
  1254. else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
  1255. MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
  1256. detailVC.courseType = MUTIL_COURSE_TYPE_MUSIC;
  1257. detailVC.courseId = courseModel.courseId;
  1258. detailVC.courseGroupId = courseModel.courseGroupId;
  1259. [self.navigationController pushViewController:detailVC animated:YES];
  1260. }
  1261. else if (type == RECENTCOURSE_TYPE_GROUP) { // 小组
  1262. MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
  1263. detailVC.courseType = MUTIL_COURSE_TYPE_GROUP;
  1264. detailVC.courseId = courseModel.courseId;
  1265. detailVC.courseGroupId = courseModel.courseGroupId;
  1266. [self.navigationController pushViewController:detailVC animated:YES];
  1267. }
  1268. else if (type == RECENTCOURSE_TYPE_VIP) { // VIP
  1269. VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
  1270. detailVC.courseId = courseModel.courseId;
  1271. detailVC.courseGroupId = courseModel.courseGroupId;
  1272. [self.navigationController pushViewController:detailVC animated:YES];
  1273. }
  1274. else {
  1275. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1276. NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId];
  1277. ctrl.url = url;
  1278. [self.navigationController pushViewController:ctrl animated:YES];
  1279. }
  1280. }
  1281. #pragma mark ---- talent view
  1282. - (HomeHotTalentView *)talentView {
  1283. if (!_talentView) {
  1284. _talentView = [HomeHotTalentView shareInstance];
  1285. [_talentView.talentContentView addSubview:self.talentCollectionView];
  1286. MJWeakSelf;
  1287. [_talentView homeTalentMore:^{
  1288. [weakSelf teacherMoreIntorduce];
  1289. }];
  1290. [self.talentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1291. make.left.right.bottom.top.mas_equalTo(_talentView.talentContentView);
  1292. }];
  1293. }
  1294. return _talentView;
  1295. }
  1296. - (void)teacherMoreIntorduce { // 约课-VIP定制
  1297. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  1298. [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
  1299. [self.navigationController pushViewController:ctrl animated:YES];
  1300. }
  1301. - (UICollectionView *)talentCollectionView {
  1302. if (!_talentCollectionView) {
  1303. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1304. layout.sectionInset = UIEdgeInsetsMake(0, 14, 0, 14);
  1305. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1306. _talentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1307. _talentCollectionView.backgroundColor = [UIColor clearColor];
  1308. _talentCollectionView.delegate = self;
  1309. _talentCollectionView.dataSource = self;
  1310. _talentCollectionView.showsVerticalScrollIndicator = NO;
  1311. _talentCollectionView.showsHorizontalScrollIndicator = NO;
  1312. if (@available(iOS 11.0, *)) {
  1313. _talentCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1314. } else {
  1315. // Fallback on earlier versions
  1316. if (@available(iOS 13.0, *)) {
  1317. _talentCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1318. } else {
  1319. // Fallback on earlier versions
  1320. }
  1321. }
  1322. [_talentCollectionView registerNib:[UINib nibWithNibName:@"HomeHotTalentCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotTalentCell"];
  1323. }
  1324. return _talentCollectionView;
  1325. }
  1326. #pragma mark ----- video course
  1327. - (HomeHotVideoCourseView *)videoCourseView {
  1328. if (!_videoCourseView) {
  1329. _videoCourseView = [HomeHotVideoCourseView shareInstance];
  1330. MJWeakSelf;
  1331. [_videoCourseView homeVideoMore:^{
  1332. [weakSelf toVideoMorePage];
  1333. }];
  1334. [_videoCourseView.videoContentView addSubview:self.videoCollectionView];
  1335. [self.videoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1336. make.left.right.bottom.top.mas_equalTo(_videoCourseView.videoContentView);
  1337. }];
  1338. }
  1339. return _videoCourseView;
  1340. }
  1341. - (UICollectionView *)videoCollectionView {
  1342. if (!_videoCollectionView) {
  1343. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1344. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1345. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1346. _videoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1347. _videoCollectionView.backgroundColor = [UIColor clearColor];
  1348. _videoCollectionView.delegate = self;
  1349. _videoCollectionView.dataSource = self;
  1350. _videoCollectionView.showsVerticalScrollIndicator = NO;
  1351. _videoCollectionView.showsHorizontalScrollIndicator = NO;
  1352. if (@available(iOS 11.0, *)) {
  1353. _videoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1354. } else {
  1355. // Fallback on earlier versions
  1356. if (@available(iOS 13.0, *)) {
  1357. _videoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1358. } else {
  1359. // Fallback on earlier versions
  1360. }
  1361. }
  1362. [_videoCollectionView registerNib:[UINib nibWithNibName:@"HomeHotVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotVideoCell"];
  1363. }
  1364. return _videoCollectionView;
  1365. }
  1366. - (void)toVideoMorePage { // 约课-视频
  1367. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  1368. [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
  1369. [self.navigationController pushViewController:ctrl animated:YES];
  1370. }
  1371. - (NSMutableArray *)informationArray {
  1372. if (!_informationArray) {
  1373. _informationArray = [NSMutableArray array];
  1374. }
  1375. return _informationArray;
  1376. }
  1377. - (NSMutableArray *)liveListArray {
  1378. if (!_liveListArray) {
  1379. _liveListArray = [NSMutableArray array];
  1380. }
  1381. return _liveListArray;
  1382. }
  1383. - (HomeDragButton *)suspendButton {
  1384. if (!_suspendButton) {
  1385. _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
  1386. MJWeakSelf;
  1387. [_suspendButton clickAction:^{
  1388. [weakSelf showDragWindowDetail];
  1389. }];
  1390. }
  1391. return _suspendButton;
  1392. }
  1393. - (void)showDragWindowDetail {
  1394. NSString *linkUrl = self.buttonModel.linkUrl;
  1395. if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
  1396. // 外部浏览器打开
  1397. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  1398. }
  1399. else {
  1400. if (![NSString isEmptyString:linkUrl]) {
  1401. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1402. webCtrl.url = linkUrl;
  1403. [self.navigationController pushViewController:webCtrl animated:YES];
  1404. }
  1405. }
  1406. }
  1407. /*
  1408. #pragma mark - Navigation
  1409. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1410. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1411. // Get the new view controller using [segue destinationViewController].
  1412. // Pass the selected object to the new view controller.
  1413. }
  1414. */
  1415. @end