HomeViewController.m 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  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. [self refreshView];
  363. }];
  364. }
  365. - (void)refreshSource:(BOOL)checkSubject {
  366. if (checkSubject) {
  367. if ([NSString isEmptyString:self.mineInfo.subjectName]) {
  368. [self showInstrumentView:YES];
  369. }
  370. else {
  371. [self requestData];
  372. }
  373. }
  374. else { // 刷新老师数据
  375. [self refreshTalentAndRefresh];
  376. }
  377. }
  378. - (void)showInstrumentView:(BOOL)hideBackButton {
  379. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  380. MJWeakSelf;
  381. [ctrl chooseCallback:^{
  382. [weakSelf requestUserInfo:NO];
  383. [weakSelf requestData];
  384. }];
  385. if (hideBackButton) {
  386. ctrl.isModalPresent = YES;
  387. CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
  388. navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
  389. [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
  390. }
  391. else {
  392. [self.navigationController pushViewController:ctrl animated:YES];
  393. }
  394. }
  395. - (void)requestNewsList {
  396. dispatch_group_enter(self.requestGroup);
  397. [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  398. dispatch_group_leave(self.requestGroup);
  399. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  400. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  401. // banner
  402. NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
  403. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  404. for (NSDictionary *parm in bannerArray) {
  405. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  406. [bannerInfoArray addObject:model];
  407. }
  408. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  409. // button
  410. NSArray *buttonArray = [result ks_arrayValueForKey:@"appMenu"];
  411. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  412. for (NSDictionary *parm in buttonArray) {
  413. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  414. [buttonInfoArray addObject:model];
  415. }
  416. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  417. // news
  418. NSArray *flashArray = [result ks_arrayValueForKey:@"flashPage"];
  419. if (flashArray.count) {
  420. self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
  421. }
  422. // 首页悬浮按钮
  423. NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
  424. if (suspensionArray.count) {
  425. self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
  426. }
  427. else {
  428. self.buttonModel = nil;
  429. }
  430. }
  431. else {
  432. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  433. }
  434. } faliure:^(NSError * _Nonnull error) {
  435. dispatch_group_leave(self.requestGroup);
  436. }];
  437. }
  438. - (void)requestStatistics {
  439. dispatch_group_enter(self.requestGroup);
  440. [KSNetworkingManager homeSummaryRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  441. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  442. [self.countView configWithSource:[dic ks_dictionaryValueForKey:@"data"]];
  443. }
  444. dispatch_group_leave(self.requestGroup);
  445. } faliure:^(NSError * _Nonnull error) {
  446. dispatch_group_leave(self.requestGroup);
  447. }];
  448. }
  449. - (void)requestCourseInfo {
  450. dispatch_group_enter(self.requestGroup);
  451. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  452. dispatch_group_leave(self.requestGroup);
  453. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  454. NSDictionary *sourceDic = [dic ks_dictionaryValueForKey:@"data"];
  455. NSArray *videoList = [sourceDic ks_arrayValueForKey:@"videoList"];
  456. NSMutableArray *videoCourse = [NSMutableArray array];
  457. for (NSDictionary *parm in videoList) {
  458. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  459. [videoCourse addObject:model];
  460. }
  461. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  462. // 最近课程
  463. NSDictionary *parm = [sourceDic ks_dictionaryValueForKey:@"recentCourses"];
  464. if (parm == nil) {
  465. self.recentCourseModel = nil;
  466. }
  467. else {
  468. self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
  469. }
  470. }
  471. else {
  472. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  473. }
  474. } faliure:^(NSError * _Nonnull error) {
  475. dispatch_group_leave(self.requestGroup);
  476. }];
  477. }
  478. - (void)requestNotice {
  479. dispatch_group_enter(self.requestGroup);
  480. [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  481. dispatch_group_leave(self.requestGroup);
  482. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  483. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  484. if (sourceArray.count) {
  485. NSDictionary *parm = [sourceArray firstObject];
  486. NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
  487. [self.noticeArray addObject:bannerModel];
  488. [self.noticeTitleArray addObject:bannerModel.title];
  489. }
  490. else {
  491. self.noticeArray = [NSMutableArray array];
  492. self.noticeTitleArray = [NSMutableArray array];
  493. }
  494. }
  495. else {
  496. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  497. }
  498. } faliure:^(NSError * _Nonnull error) {
  499. dispatch_group_leave(self.requestGroup);
  500. }];
  501. }
  502. - (void)requestTalentSource {
  503. dispatch_group_enter(self.requestGroup);
  504. [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  505. dispatch_group_leave(self.requestGroup);
  506. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  507. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  508. NSMutableArray *talentArray = [NSMutableArray array];
  509. for (NSDictionary *parm in sourceArray) {
  510. TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
  511. [talentArray addObject:model];
  512. }
  513. self.talentArray = [NSMutableArray arrayWithArray:talentArray];
  514. }
  515. else {
  516. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  517. }
  518. } faliure:^(NSError * _Nonnull error) {
  519. dispatch_group_leave(self.requestGroup);
  520. }];
  521. }
  522. - (void)refreshTalentAndRefresh {
  523. [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  524. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  525. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  526. NSMutableArray *talentArray = [NSMutableArray array];
  527. for (NSDictionary *parm in sourceArray) {
  528. TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
  529. [talentArray addObject:model];
  530. }
  531. self.talentArray = [NSMutableArray arrayWithArray:talentArray];
  532. }
  533. else {
  534. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  535. }
  536. [self refreshTalentView];
  537. } faliure:^(NSError * _Nonnull error) {
  538. }];
  539. }
  540. - (void)requestLiveList {
  541. dispatch_group_enter(self.requestGroup);
  542. [KSNetworkingManager queryTeacherLivingListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  543. dispatch_group_leave(self.requestGroup);
  544. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  545. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  546. NSMutableArray *liveListArray = [NSMutableArray array];
  547. for (NSDictionary *parm in sourceArray) {
  548. HomeTeacherLiveModel *model = [[HomeTeacherLiveModel alloc] initWithDictionary:parm];
  549. [liveListArray addObject:model];
  550. }
  551. self.liveListArray = [NSMutableArray arrayWithArray:liveListArray];
  552. }
  553. else {
  554. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  555. }
  556. } faliure:^(NSError * _Nonnull error) {
  557. dispatch_group_leave(self.requestGroup);
  558. }];
  559. }
  560. - (void)requestInformationList {
  561. dispatch_group_enter(self.requestGroup);
  562. [KSNetworkingManager informationListRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  563. dispatch_group_leave(self.requestGroup);
  564. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  565. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  566. NSMutableArray *informationInfoArray = [NSMutableArray array];
  567. for (NSDictionary *parm in sourceArray) {
  568. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  569. [informationInfoArray addObject:model];
  570. }
  571. self.informationArray = [NSMutableArray arrayWithArray:informationInfoArray];
  572. }
  573. else {
  574. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  575. }
  576. } faliure:^(NSError * _Nonnull error) {
  577. dispatch_group_leave(self.requestGroup);
  578. }];
  579. }
  580. - (void)requestData {
  581. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  582. [self requestNewsList];
  583. [self requestStatistics];
  584. [self requestNotice];
  585. [self requestCourseInfo];
  586. // 老师
  587. [self requestTalentSource];
  588. [self requestLiveList];
  589. [self requestInformationList];
  590. if ([self checkHasShowAwardAlert] == NO) {
  591. [self requestAwardMessage];
  592. }
  593. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  594. [LOADING_MANAGER removeCustomLoading];
  595. [self.pagerView.mainTableView.mj_header endRefreshing];
  596. [self refreshView];
  597. });
  598. }
  599. - (void)refreshView {
  600. [self refreshBannaerView];
  601. [self showButtonMessage];
  602. [self refreshNotice];
  603. [self refreshCourseView:self.recentCourseModel];
  604. // 老师
  605. [self refreshTalentView];
  606. // 课程
  607. [self refreshCourseView];
  608. [self refreshHeadHeight];
  609. [self refreshPageView];
  610. if (self.isCheck && [self checkHasShowAwardAlert] == NO) {
  611. [self checkShowAwardAlert];
  612. }
  613. else {
  614. if (self.flashModel) {
  615. [self showNewsWithSource:self.flashModel];
  616. }
  617. }
  618. // 悬浮按钮
  619. if (self.buttonModel) {
  620. [self showFloatingWindow];
  621. }
  622. else {
  623. [self removeFloatWindow];
  624. }
  625. }
  626. - (void)removeFloatWindow {
  627. if ([self.view.subviews containsObject:self.suspendButton]) {
  628. [self.suspendButton removeFromSuperview];
  629. }
  630. }
  631. // 显示悬浮窗
  632. - (void)showFloatingWindow {
  633. if (![self.view.subviews containsObject:self.suspendButton]) {
  634. [self.view addSubview:self.suspendButton];
  635. }
  636. [self.view bringSubviewToFront:self.suspendButton];
  637. [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
  638. }
  639. - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
  640. // 登录之后才弹窗
  641. if ([self checkIsLoginToLoginView:NO]) {
  642. [self displayAlert:sourceModel];
  643. }
  644. }
  645. - (void)displayAlert:(HomeMessageModel *)sourceModel {
  646. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  647. if (appDelegate.isShowMemoAlert) {
  648. return;
  649. }
  650. if (USER_MANAGER.hasShowFlash) {
  651. return;
  652. }
  653. if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
  654. return;
  655. }
  656. KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
  657. MJWeakSelf;
  658. [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
  659. appDelegate.isShowFlashAlert = NO;
  660. if (isSure) {
  661. if (![NSString isEmptyString:linkUrl]) {
  662. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  663. webCtrl.url = [linkUrl getUrlEndcodeString];
  664. [weakSelf.navigationController pushViewController:webCtrl animated:YES];
  665. }
  666. }
  667. [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
  668. }];
  669. [newAlert showAlert];
  670. appDelegate.isShowFlashAlert = YES;
  671. USER_MANAGER.hasShowFlash = YES; // 已展示过flash
  672. }
  673. - (void)refreshPageView {
  674. for (NSInteger i = 0; i < self.listViewArray.count; i++) {
  675. id view = self.listViewArray[i];
  676. if ([view isKindOfClass:[HomeInformationBodyView class]]) {
  677. HomeInformationBodyView *informationView = (HomeInformationBodyView *)view;
  678. informationView.informationArray = [self.informationArray mutableCopy];
  679. [informationView beginFirstRefresh];
  680. }
  681. }
  682. }
  683. - (void)refreshTalentView {
  684. if (self.talentArray.count) {
  685. self.talentViewHeight = [HomeHotTalentView getViewHeight];
  686. self.talentView.hidden = NO;
  687. }
  688. else {
  689. self.talentViewHeight = CGFLOAT_MIN;
  690. self.talentView.hidden = YES;
  691. }
  692. [self.talentView mas_updateConstraints:^(MASConstraintMaker *make) {
  693. make.height.mas_equalTo(self.talentViewHeight);
  694. }];
  695. [self.talentCollectionView reloadData];
  696. }
  697. - (void)refreshBannaerView {
  698. if (self.bannerArray.count > 0) {
  699. self.bannerViewHeight = [HomeBannerView getViewHeight];
  700. self.bannerView.hidden = NO;
  701. }
  702. else {
  703. self.bannerViewHeight = CGFLOAT_MIN;
  704. self.bannerView.hidden = YES;
  705. }
  706. if (self.bannerArray.count > 1) {
  707. self.bannerScroll.autoScrollInterval = 3.0f;
  708. [self.bannerScroll addSubview:self.pageControl];
  709. }
  710. else {
  711. self.bannerScroll.autoScrollInterval = 0;
  712. [self.pageControl removeFromSuperview];
  713. }
  714. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  715. make.height.mas_equalTo(self.bannerViewHeight);
  716. }];
  717. _pageControl.numberOfPages = self.bannerArray.count;
  718. [self.bannerScroll reloadData];
  719. }
  720. - (void)showButtonMessage {
  721. [self.buttonContainer.buttonContentView removeAllSubViews];
  722. CGFloat buttonSpace = (KPortraitWidth - BUTTON_ROWCOUNT * HOME_BUTTONWIDTH) / (BUTTON_ROWCOUNT /*+ 1*/);
  723. // 添加按钮
  724. if (self.buttonArray.count) {
  725. self.buttonContainer.hidden = NO;
  726. CGFloat xSpace = 0.0f;
  727. CGFloat ySpace = 0.0f;
  728. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  729. xSpace = buttonSpace / 2 + (i % BUTTON_ROWCOUNT) * (HOME_BUTTONWIDTH + buttonSpace);
  730. ySpace = (i / BUTTON_ROWCOUNT) * (HOME_BUTTONHEIGHT + HOME_BUTTON_VERTICAL_SPACE);
  731. HomeMessageModel *model = self.buttonArray[i];
  732. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  733. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  734. buttonView.buttonTitle.text = model.title;
  735. buttonView.frame = CGRectMake(xSpace, ySpace, HOME_BUTTONWIDTH, HOME_BUTTONHEIGHT);
  736. buttonView.actionButton.tag = 3000 + i;
  737. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  738. [self.buttonContainer.buttonContentView addSubview:buttonView];
  739. }
  740. }
  741. else {
  742. self.buttonContainer.hidden = YES;
  743. }
  744. // 高度
  745. CGFloat buttonViewDefaultHeight = [HomeButtonView getViewHeight:self.buttonArray.count];
  746. self.buttonViewHeight = buttonViewDefaultHeight;
  747. [self.buttonContainer mas_updateConstraints:^(MASConstraintMaker *make) {
  748. make.height.mas_equalTo(buttonViewDefaultHeight);
  749. }];
  750. }
  751. - (void)HomeTopButtonAction:(UIButton *)sender {
  752. NSInteger index = sender.tag - 3000;
  753. if ([self checkIsLoginToLoginView:YES]) {
  754. HomeMessageModel *model = self.buttonArray[index];
  755. if (![NSString isEmptyString:model.linkUrl]) {
  756. if ([model.linkUrl isEqualToString:@"native-metronome"]) {
  757. ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
  758. [self.navigationController pushViewController:ctrl animated:YES];
  759. }
  760. else if ([model.linkUrl isEqualToString:@"native-bookVip"]) {
  761. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  762. [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
  763. [self.navigationController pushViewController:ctrl animated:YES];
  764. }
  765. else if ([model.linkUrl isEqualToString:@"native-bookAccompany"]) {
  766. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  767. [ctrl displayWithIndex:DISPLAY_INDEX_FIRST];
  768. [self.navigationController pushViewController:ctrl animated:YES];
  769. }
  770. else if ([model.linkUrl isEqualToString:@"native-bookLive"]) {
  771. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  772. [ctrl displayWithIndex:DISPLAY_INDEX_LIVE];
  773. [self.navigationController pushViewController:ctrl animated:YES];
  774. }
  775. else if ([model.linkUrl isEqualToString:@"native-bookVideo"]) {
  776. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  777. [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
  778. [self.navigationController pushViewController:ctrl animated:YES];
  779. }
  780. else {
  781. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  782. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  783. [self.navigationController pushViewController:webCtrl animated:YES];
  784. }
  785. }
  786. }
  787. }
  788. - (void)refreshNotice {
  789. if (self.noticeTitleArray.count) {
  790. self.noticeView.hidden = NO;
  791. CGFloat height = [PublicNoticeView getViewHeight];
  792. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  793. make.height.mas_equalTo(height);
  794. }];
  795. self.noticeViewHeight = height;
  796. }
  797. else {
  798. self.noticeView.hidden = YES;
  799. self.noticeViewHeight = CGFLOAT_MIN;
  800. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  801. make.height.mas_equalTo(CGFLOAT_MIN);
  802. }];
  803. }
  804. self.noticeScrollView.titlesGroup = self.noticeTitleArray;
  805. }
  806. - (void)refreshCourseView:(RecentCourseModel *)model {
  807. if (model) {
  808. [self.courseView configCourseMessage:model];
  809. self.courseView.hidden = NO;
  810. self.courseViewHeight = [HomeRecentCourseView getViewHeight];
  811. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  812. make.height.mas_equalTo(self.courseViewHeight);
  813. }];
  814. }
  815. else {
  816. self.courseView.hidden = YES;
  817. self.courseViewHeight = CGFLOAT_MIN;
  818. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  819. make.height.mas_equalTo(self.courseViewHeight);
  820. }];
  821. }
  822. }
  823. - (void)refreshCourseView {
  824. if (self.videoCourseArray.count) {
  825. self.videoViewHeight = [HomeHotVideoCourseView getViewHeight];
  826. self.videoCourseView.hidden = NO;
  827. }
  828. else {
  829. self.videoViewHeight = CGFLOAT_MIN;
  830. self.videoCourseView.hidden = YES;
  831. }
  832. [self.videoCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  833. make.height.mas_equalTo(self.videoViewHeight);
  834. }];
  835. [self.videoCollectionView reloadData];
  836. }
  837. #pragma mark - JXPagerViewDelegate
  838. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  839. return self.headView;
  840. }
  841. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  842. return self.headViewHeight;
  843. }
  844. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  845. return self.categoryView;
  846. }
  847. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  848. return self.headheight;
  849. }
  850. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  851. //和categoryView的item数量一致
  852. return self.titles.count;
  853. }
  854. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  855. HomeInformationBodyView *listView = [[HomeInformationBodyView alloc] init];
  856. listView.naviController = self.navigationController;
  857. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  858. self.listViewArray[index] = listView;
  859. listView.selectIndex = index;
  860. listView.informationArray = [self.informationArray mutableCopy];
  861. [listView beginFirstRefresh];
  862. return listView;
  863. }
  864. #pragma mark - JXCategoryViewDelegate
  865. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  866. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  867. if (self.listViewArray.count > index) {
  868. id value = self.listViewArray[index];
  869. if ([value isKindOfClass:[KSJXBodyView class]]) {
  870. KSJXBodyView *listView = (KSJXBodyView *)value;
  871. [listView beginFirstRefresh];
  872. }
  873. }
  874. }
  875. #pragma mark - JXPagerMainTableViewGestureDelegate
  876. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  877. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  878. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  879. return NO;
  880. }
  881. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  882. }
  883. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  884. NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y);
  885. NSInteger height = self.headViewHeight;
  886. CGFloat space = scrollView.contentOffset.y;
  887. if (space > 0) {
  888. self.navView.lineView.hidden = NO;
  889. }
  890. else {
  891. self.navView.lineView.hidden = YES;
  892. }
  893. if (space >= height) {
  894. self.categoryView.backgroundColor = [UIColor whiteColor];
  895. }
  896. else {
  897. self.categoryView.backgroundColor = [UIColor clearColor];
  898. }
  899. }
  900. #pragma mark - TYCyclePagerViewDataSource代理
  901. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  902. return self.bannerArray.count;
  903. }
  904. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  905. HomeMessageModel *model = self.bannerArray[index];
  906. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  907. [cell configCellWithModel:model];
  908. return cell;
  909. }
  910. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  911. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  912. layout.itemSize = CGSizeMake(KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
  913. layout.itemSpacing = 0;
  914. return layout;
  915. }
  916. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  917. if (pageView == self.bannerScroll) {
  918. [self.pageControl setCurrentPage:toIndex animate:YES];
  919. }
  920. }
  921. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  922. HomeMessageModel *model = self.bannerArray[index];
  923. if (![NSString isEmptyString:model.linkUrl]) {
  924. if ([model.linkType isEqualToString:@"OUT"]) {
  925. // 外部浏览器打开
  926. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  927. }
  928. else {
  929. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  930. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  931. [self.navigationController pushViewController:webCtrl animated:YES];
  932. }
  933. }
  934. }
  935. #pragma mark ---- collection data source
  936. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  937. return 1;
  938. }
  939. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  940. if (collectionView == self.talentCollectionView) { // 推荐老师
  941. return self.talentArray.count;
  942. }
  943. else/* if (collectionView == self.videoCollectionView)*/ { // 视频课
  944. return self.videoCourseArray.count;
  945. }
  946. }
  947. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  948. if (collectionView == self.talentCollectionView) {
  949. TalentTeacherModel *talentModel = self.talentArray[indexPath.item];
  950. HomeHotTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotTalentCell" forIndexPath:indexPath];
  951. MJWeakSelf;
  952. [cell configWithSource:talentModel callback:^(NSString *teacherId) {
  953. [weakSelf followTalentTeacher:teacherId];
  954. }];
  955. return cell;
  956. }
  957. else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
  958. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.item];
  959. HomeHotVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotVideoCell" forIndexPath:indexPath];
  960. [cell configWithSource:model];
  961. return cell;
  962. }
  963. }
  964. - (void)followTalentTeacher:(NSString *)teacherId {
  965. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  966. [KSNetworkingManager starOrUnStarRequest:KS_GET userId:teacherId starStatus:@"1" success:^(NSDictionary * _Nonnull dic) {
  967. [LOADING_MANAGER removeCustomLoading];
  968. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  969. [LOADING_MANAGER KSShowMsg:@"关注成功" promptCompletion:^{
  970. [self requestData];
  971. }];
  972. }
  973. else {
  974. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  975. }
  976. } faliure:^(NSError * _Nonnull error) {
  977. [LOADING_MANAGER removeCustomLoading];
  978. }];
  979. }
  980. - (void)displaySongDetail:(NSString *)songId {
  981. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  982. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  983. [self.navigationController pushViewController:ctrl animated:YES];
  984. }
  985. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  986. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  987. } confirm:^{
  988. [self openSettingView];
  989. }];
  990. }
  991. - (void)openSettingView {
  992. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  993. }
  994. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  995. if (collectionView == self.talentCollectionView) { // 老师风采
  996. TalentTeacherModel *model = self.talentArray[indexPath.item];
  997. [self displayTeacherDetail:[NSString stringWithFormat:@"%.0f",model.userId]];
  998. }
  999. else /*if (collectionView == self.videoCollectionView)*/ { // 视频课
  1000. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  1001. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  1002. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1003. ctrl.url = url;
  1004. [self.navigationController pushViewController:ctrl animated:YES];
  1005. }
  1006. }
  1007. // 老师风采
  1008. - (void)displayTeacherDetail:(NSString *)teacherId {
  1009. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1010. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  1011. [self.navigationController pushViewController:ctrl animated:YES];
  1012. }
  1013. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  1014. if (collectionView == self.talentCollectionView) {
  1015. return CGSizeMake(104, 146);
  1016. }
  1017. else if (collectionView == self.videoCollectionView) {
  1018. if (IS_IPAD) {
  1019. return CGSizeMake(205, 158);
  1020. }
  1021. return CGSizeMake(168, 158);
  1022. }
  1023. else {
  1024. return CGSizeMake(168, 158);
  1025. }
  1026. }
  1027. #pragma mark ----- SDCycleScrollViewDelegate
  1028. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  1029. NoticeSourceModel *noticeModel = self.noticeArray[index];
  1030. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1031. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
  1032. [self.navigationController pushViewController:webCtrl animated:YES];
  1033. }
  1034. #pragma mark ------- lazying
  1035. - (HomeNavSearchView *)navView {
  1036. if (!_navView) {
  1037. _navView = [HomeNavSearchView shareInstance];
  1038. MJWeakSelf;
  1039. [_navView homeNavSearchAction:^(HOMENAV_TAG action) {
  1040. [weakSelf homeNavAction:action];
  1041. }];
  1042. }
  1043. return _navView;
  1044. }
  1045. - (void)homeNavAction:(HOMENAV_TAG)action {
  1046. switch (action) {
  1047. case HOMENAV_TAG_SCAN: // 扫一扫
  1048. {
  1049. [self showScanView];
  1050. }
  1051. break;
  1052. case HOMENAV_TAG_MESSAGE: // 消息
  1053. {
  1054. NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
  1055. [self.navigationController pushViewController:ctrl animated:YES];
  1056. }
  1057. break;
  1058. default:
  1059. break;
  1060. }
  1061. }
  1062. - (void)showScanView {
  1063. // 判断是否有权限
  1064. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  1065. if (type == PREMISSIONTYPE_YES) {
  1066. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  1067. [self.navigationController pushViewController:ctrl animated:YES];
  1068. }
  1069. else {
  1070. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  1071. }
  1072. }];
  1073. }
  1074. - (dispatch_group_t)requestGroup {
  1075. if (!_requestGroup) {
  1076. _requestGroup = dispatch_group_create();
  1077. }
  1078. return _requestGroup;
  1079. }
  1080. - (UIView *)headView {
  1081. if (!_headView) {
  1082. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, CGFLOAT_MIN)];
  1083. _headView.backgroundColor = [UIColor clearColor];
  1084. }
  1085. return _headView;
  1086. }
  1087. - (NSMutableArray *)listViewArray {
  1088. if (!_listViewArray) {
  1089. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]];
  1090. }
  1091. return _listViewArray;
  1092. }
  1093. - (HomeBannerView *)bannerView {
  1094. if (!_bannerView) {
  1095. _bannerView = [HomeBannerView shareInstance];
  1096. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  1097. }
  1098. return _bannerView;
  1099. }
  1100. #pragma mark --- banner
  1101. - (TYCyclePagerView *)bannerScroll {
  1102. if (!_bannerScroll) {
  1103. _bannerScroll = [[TYCyclePagerView alloc] init];
  1104. _bannerScroll.backgroundColor = [UIColor clearColor];
  1105. _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth, (KPortraitWidth - 28) / 347 * 132);
  1106. _bannerScroll.isInfiniteLoop = YES;
  1107. _bannerScroll.autoScrollInterval = 3.0f;
  1108. _bannerScroll.reloadDataNeedResetIndex = YES;
  1109. _bannerScroll.dataSource = self;
  1110. _bannerScroll.delegate = self;
  1111. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  1112. if (@available(iOS 11.0, *)) {
  1113. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1114. } else {
  1115. // Fallback on earlier versions
  1116. if (@available(iOS 13.0, *)) {
  1117. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1118. } else {
  1119. // Fallback on earlier versions
  1120. }
  1121. }
  1122. }
  1123. return _bannerScroll;
  1124. }
  1125. - (TYPageControl *)pageControl {
  1126. if (!_pageControl) {
  1127. _pageControl = [[TYPageControl alloc] init];
  1128. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  1129. _pageControl.pageIndicatorSpaing = 4.0f;
  1130. _pageControl.frame = CGRectMake(0, (KPortraitWidth - 28) * 132 / 347 - 20, KPortraitWidth-28 - 12, 12);
  1131. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  1132. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  1133. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  1134. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  1135. }
  1136. return _pageControl;
  1137. }
  1138. - (NSMutableArray *)bannerArray {
  1139. if (!_bannerArray) {
  1140. _bannerArray = [NSMutableArray array];
  1141. }
  1142. return _bannerArray;
  1143. }
  1144. #pragma mark ---- scroll view delegate
  1145. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1146. }
  1147. #pragma mark ---- countView
  1148. - (HomeCountView *)countView {
  1149. if (!_countView) {
  1150. _countView = [HomeCountView sharedInstance];
  1151. MJWeakSelf;
  1152. [_countView countActionCallback:^(BOOL showCourseTable) {
  1153. [weakSelf homeStatisticsAction:showCourseTable];
  1154. }];
  1155. }
  1156. return _countView;
  1157. }
  1158. - (void)homeStatisticsAction:(BOOL)showCourseTable {
  1159. if (showCourseTable) {
  1160. [(KSTabBarViewController *)self.tabBarController tabBarSelectedWithIndex:2];
  1161. }
  1162. else {
  1163. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1164. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
  1165. [self.navigationController pushViewController:ctrl animated:YES];
  1166. }
  1167. }
  1168. #pragma mark ---- button container
  1169. - (HomeButtonView *)buttonContainer {
  1170. if (!_buttonContainer) {
  1171. _buttonContainer = [HomeButtonView shareInstance];
  1172. }
  1173. return _buttonContainer;
  1174. }
  1175. #pragma mark ---- notice view
  1176. - (UIView *)headBgView {
  1177. if (!_headBgView) {
  1178. _headBgView = [[UIView alloc] init];
  1179. _headBgView.backgroundColor = [UIColor whiteColor];
  1180. }
  1181. return _headBgView;
  1182. }
  1183. - (PublicNoticeView *)noticeView {
  1184. if (!_noticeView) {
  1185. _noticeView = [PublicNoticeView shareInstance];
  1186. MJWeakSelf;
  1187. [_noticeView moreCallback:^{
  1188. [weakSelf moreNotice];
  1189. }];
  1190. }
  1191. return _noticeView;
  1192. }
  1193. - (NSMutableArray *)noticeArray {
  1194. if (!_noticeArray) {
  1195. _noticeArray = [NSMutableArray array];
  1196. }
  1197. return _noticeArray;
  1198. }
  1199. - (NSMutableArray *)noticeTitleArray {
  1200. if (!_noticeTitleArray) {
  1201. _noticeTitleArray = [NSMutableArray array];
  1202. }
  1203. return _noticeTitleArray;
  1204. }
  1205. - (void)moreNotice {
  1206. if (self.noticeArray.count) {
  1207. NoticeSourceModel *bannerModel = self.noticeArray[0];
  1208. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1209. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  1210. [self.navigationController pushViewController:webCtrl animated:YES];
  1211. }
  1212. }
  1213. - (SDCycleScrollView *)noticeScrollView {
  1214. if (!_noticeScrollView) {
  1215. _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
  1216. _noticeScrollView.onlyDisplayText = YES;
  1217. _noticeScrollView.autoScroll = NO;
  1218. _noticeScrollView.scrollEnabled = NO;
  1219. _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
  1220. _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
  1221. _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor];
  1222. _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
  1223. _noticeScrollView.titlesGroup = self.noticeTitleArray;
  1224. }
  1225. return _noticeScrollView;
  1226. }
  1227. - (HomeRecentCourseView *)courseView {
  1228. if (!_courseView) {
  1229. _courseView = [HomeRecentCourseView shareInstance];
  1230. MJWeakSelf;
  1231. [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
  1232. [weakSelf joinRoomAction:type courseMessage:courseModel];
  1233. }];
  1234. }
  1235. return _courseView;
  1236. }
  1237. - (void)joinRoomAction:(RECENTCOURSE_TYPE)type courseMessage:(RecentCourseModel *)courseModel {
  1238. if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
  1239. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  1240. detailVC.courseId = courseModel.courseId;
  1241. detailVC.courseGroupId = courseModel.courseGroupId;
  1242. [self.navigationController pushViewController:detailVC animated:YES];
  1243. }
  1244. else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
  1245. MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
  1246. detailVC.courseId = courseModel.courseId;
  1247. detailVC.courseGroupId = courseModel.courseGroupId;
  1248. [self.navigationController pushViewController:detailVC animated:YES];
  1249. }
  1250. else if (type == RECENTCOURSE_TYPE_VIP) { // VIP
  1251. VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
  1252. detailVC.courseId = courseModel.courseId;
  1253. detailVC.courseGroupId = courseModel.courseGroupId;
  1254. [self.navigationController pushViewController:detailVC animated:YES];
  1255. }
  1256. else {
  1257. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1258. NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId];
  1259. ctrl.url = url;
  1260. [self.navigationController pushViewController:ctrl animated:YES];
  1261. }
  1262. }
  1263. #pragma mark ---- talent view
  1264. - (HomeHotTalentView *)talentView {
  1265. if (!_talentView) {
  1266. _talentView = [HomeHotTalentView shareInstance];
  1267. [_talentView.talentContentView addSubview:self.talentCollectionView];
  1268. MJWeakSelf;
  1269. [_talentView homeTalentMore:^{
  1270. [weakSelf teacherMoreIntorduce];
  1271. }];
  1272. [self.talentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1273. make.left.right.bottom.top.mas_equalTo(_talentView.talentContentView);
  1274. }];
  1275. }
  1276. return _talentView;
  1277. }
  1278. - (void)teacherMoreIntorduce { // 约课-VIP定制
  1279. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  1280. [ctrl displayWithIndex:DISPLAY_INDEX_VIP];
  1281. [self.navigationController pushViewController:ctrl animated:YES];
  1282. }
  1283. - (UICollectionView *)talentCollectionView {
  1284. if (!_talentCollectionView) {
  1285. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1286. layout.sectionInset = UIEdgeInsetsMake(0, 14, 0, 14);
  1287. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1288. _talentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1289. _talentCollectionView.backgroundColor = [UIColor clearColor];
  1290. _talentCollectionView.delegate = self;
  1291. _talentCollectionView.dataSource = self;
  1292. _talentCollectionView.showsVerticalScrollIndicator = NO;
  1293. _talentCollectionView.showsHorizontalScrollIndicator = NO;
  1294. if (@available(iOS 11.0, *)) {
  1295. _talentCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1296. } else {
  1297. // Fallback on earlier versions
  1298. if (@available(iOS 13.0, *)) {
  1299. _talentCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1300. } else {
  1301. // Fallback on earlier versions
  1302. }
  1303. }
  1304. [_talentCollectionView registerNib:[UINib nibWithNibName:@"HomeHotTalentCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotTalentCell"];
  1305. }
  1306. return _talentCollectionView;
  1307. }
  1308. #pragma mark ----- video course
  1309. - (HomeHotVideoCourseView *)videoCourseView {
  1310. if (!_videoCourseView) {
  1311. _videoCourseView = [HomeHotVideoCourseView shareInstance];
  1312. MJWeakSelf;
  1313. [_videoCourseView homeVideoMore:^{
  1314. [weakSelf toVideoMorePage];
  1315. }];
  1316. [_videoCourseView.videoContentView addSubview:self.videoCollectionView];
  1317. [self.videoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1318. make.left.right.bottom.top.mas_equalTo(_videoCourseView.videoContentView);
  1319. }];
  1320. }
  1321. return _videoCourseView;
  1322. }
  1323. - (UICollectionView *)videoCollectionView {
  1324. if (!_videoCollectionView) {
  1325. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1326. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1327. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1328. _videoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1329. _videoCollectionView.backgroundColor = [UIColor clearColor];
  1330. _videoCollectionView.delegate = self;
  1331. _videoCollectionView.dataSource = self;
  1332. _videoCollectionView.showsVerticalScrollIndicator = NO;
  1333. _videoCollectionView.showsHorizontalScrollIndicator = NO;
  1334. if (@available(iOS 11.0, *)) {
  1335. _videoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1336. } else {
  1337. // Fallback on earlier versions
  1338. if (@available(iOS 13.0, *)) {
  1339. _videoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1340. } else {
  1341. // Fallback on earlier versions
  1342. }
  1343. }
  1344. [_videoCollectionView registerNib:[UINib nibWithNibName:@"HomeHotVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotVideoCell"];
  1345. }
  1346. return _videoCollectionView;
  1347. }
  1348. - (void)toVideoMorePage { // 约课-视频
  1349. HomeArrangeCourseController *ctrl = [[HomeArrangeCourseController alloc] init];
  1350. [ctrl displayWithIndex:DISPLAY_INDEX_VIDEO];
  1351. [self.navigationController pushViewController:ctrl animated:YES];
  1352. }
  1353. - (NSMutableArray *)informationArray {
  1354. if (!_informationArray) {
  1355. _informationArray = [NSMutableArray array];
  1356. }
  1357. return _informationArray;
  1358. }
  1359. - (NSMutableArray *)liveListArray {
  1360. if (!_liveListArray) {
  1361. _liveListArray = [NSMutableArray array];
  1362. }
  1363. return _liveListArray;
  1364. }
  1365. - (HomeDragButton *)suspendButton {
  1366. if (!_suspendButton) {
  1367. _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
  1368. MJWeakSelf;
  1369. [_suspendButton clickAction:^{
  1370. [weakSelf showDragWindowDetail];
  1371. }];
  1372. }
  1373. return _suspendButton;
  1374. }
  1375. - (void)showDragWindowDetail {
  1376. NSString *linkUrl = self.buttonModel.linkUrl;
  1377. if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
  1378. // 外部浏览器打开
  1379. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  1380. }
  1381. else {
  1382. if (![NSString isEmptyString:linkUrl]) {
  1383. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1384. webCtrl.url = linkUrl;
  1385. [self.navigationController pushViewController:webCtrl animated:YES];
  1386. }
  1387. }
  1388. }
  1389. /*
  1390. #pragma mark - Navigation
  1391. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1392. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1393. // Get the new view controller using [segue destinationViewController].
  1394. // Pass the selected object to the new view controller.
  1395. }
  1396. */
  1397. @end