HomeViewController.m 60 KB

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