HomeViewController.m 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. //
  2. // HomeViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "HomeViewController.h"
  8. #import "HomeNavView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "MyMusicViewController.h"
  11. #import "HomeworkListViewController.h"
  12. #import "EvaluateCourseListViewController.h"
  13. #import "NotiferMessageViewController.h"
  14. #import "UserInfoManager.h"
  15. #import "MyIncomeViewController.h"
  16. #import "ReceiveEvaluateListController.h"
  17. #import "PublicNoticeView.h"
  18. #import <SDCycleScrollView.h>
  19. #import "NoticeSourceModel.h"
  20. #import "HomeRecentCourseView.h"
  21. #import "AccompanyDetailViewController.h"
  22. #import "VipCouseDetailViewController.h"
  23. #import "RecentCourseModel.h"
  24. #import "AppDelegate.h"
  25. #import "MusicRoomViewController.h"
  26. #import "KSScanViewController.h"
  27. #import "KSPremissionAlert.h"
  28. #import <RecordCheckManager.h>
  29. #import "UserSettingViewController.h"
  30. #import "HomeMessageModel.h"
  31. #import "HomeButtonView.h"
  32. #import "KSHomeButton.h"
  33. #import "HomeNewHeadView.h"
  34. #import "HomeAlbumView.h"
  35. #import "HomeAlbumModel.h"
  36. #import "HomeHotAlbumCell.h"
  37. #import "HomeHotMusicView.h"
  38. #import "HomeHotMusicCollectionCell.h"
  39. #import "HomeBannerView.h"
  40. #import <UIButton+WebCache.h>
  41. #import "TYCyclePagerView.h"
  42. #import "TYPageControl.h"
  43. #import "HomeBannerCell.h"
  44. #import "HomeAuthAlertView.h"
  45. #import "KSAwardAlertView.h"
  46. #import "HomeNewMusicView.h"
  47. #import "HomeRecommendMusicView.h"
  48. #import "HomeMusicModel.h"
  49. #import "HomeDragButton.h"
  50. #import "ToneTuningViewController.h"
  51. #import "InstrumentChooseViewController.h"
  52. #import "HomeTenantView.h"
  53. #import "HomeTenantPageView.h"
  54. #import "HomeMusicSheetLayout.h"
  55. #import "MinePageViewController.h"
  56. #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
  57. #define COLLECTION_HEIGHT (320)
  58. @interface HomeViewController ()<SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  59. @property (nonatomic, strong) HomeNavView *navView;
  60. @property (nonatomic, strong) HomeNewHeadView *headView;
  61. @property (nonatomic, strong) UIView *headBgView;
  62. @property (nonatomic, strong) UserInfo *mineInfo;
  63. @property (nonatomic, strong) PublicNoticeView *noticeView;
  64. @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
  65. @property (nonatomic, strong) NSMutableArray *noticeArray; // 公告数据
  66. @property (nonatomic, strong) NSMutableArray *titleArray; // 标题数组
  67. @property (nonatomic, strong) HomeBannerView *bannerView; // banner
  68. @property (nonatomic, strong) NSMutableArray *bannerArray; //
  69. @property (nonatomic, strong) TYPageControl *pageControl;
  70. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  71. @property (nonatomic, strong) HomeRecentCourseView *courseView;
  72. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  73. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  74. @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
  75. @property (nonatomic, assign) BOOL isFirstLoad;
  76. @property (nonatomic, strong) HomeAlbumView *albumView;
  77. @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
  78. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  79. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  80. @property (nonatomic, strong) dispatch_group_t requestGroup;
  81. @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
  82. // 热门曲目
  83. @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
  84. @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
  85. @property (nonatomic, assign) CGFloat hotMusicHeight; // music 高度
  86. // 推荐曲目
  87. @property (nonatomic, strong) HomeRecommendMusicView *recommendMusicView;
  88. @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
  89. @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
  90. @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
  91. // 最新曲目
  92. @property (nonatomic, strong) HomeNewMusicView *newestMusicView;
  93. @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
  94. @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
  95. @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
  96. @property (nonatomic, strong) HomeAuthAlertView *authAlertView;
  97. @property (nonatomic, assign) BOOL isCheck;
  98. @property (nonatomic, strong) HomeMessageModel *buttonModel;
  99. @property (nonatomic, strong) HomeDragButton *suspendButton;
  100. @property (nonatomic, assign) BOOL isSettingSubject;
  101. // 机构名称
  102. @property (nonatomic, strong) HomeTenantView *tenantNameView;
  103. @end
  104. @implementation HomeViewController
  105. - (void)viewDidLoad {
  106. [super viewDidLoad];
  107. // Do any additional setup after loading the view.
  108. self.ks_prefersNavigationBarHidden = YES;
  109. self.isFirstLoad = YES;
  110. [self configUI];
  111. }
  112. - (void)requestUserInfo {
  113. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  114. self.mineInfo = userInfo;
  115. [self requestData];
  116. }];
  117. }
  118. - (void)requestAwardMessage {
  119. self.isCheck = NO;
  120. dispatch_group_enter(self.requestGroup);
  121. [KSNetworkingManager checkReceiveRewardRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  122. dispatch_group_leave(self.requestGroup);
  123. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  124. BOOL isCheck = [[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"check"];
  125. self.isCheck = isCheck;
  126. }
  127. } faliure:^(NSError * _Nonnull error) {
  128. dispatch_group_leave(self.requestGroup);
  129. }];
  130. }
  131. - (void)requestNotice {
  132. dispatch_group_enter(self.requestGroup);
  133. [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  134. dispatch_group_leave(self.requestGroup);
  135. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  136. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  137. if (sourceArray.count) {
  138. NSDictionary *parm = [sourceArray firstObject];
  139. NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
  140. [self.noticeArray addObject:bannerModel];
  141. [self.titleArray addObject:bannerModel.title];
  142. }
  143. else {
  144. self.noticeArray = [NSMutableArray array];
  145. self.titleArray = [NSMutableArray array];
  146. }
  147. }
  148. else {
  149. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  150. }
  151. } faliure:^(NSError * _Nonnull error) {
  152. dispatch_group_leave(self.requestGroup);
  153. }];
  154. }
  155. - (void)requestRecentCourse {
  156. dispatch_group_enter(self.requestGroup);
  157. [KSNetworkingManager queryRecentLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
  158. dispatch_group_leave(self.requestGroup);
  159. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  160. NSDictionary *parm = [[dic ks_dictionaryValueForKey:@"data"] ks_dictionaryValueForKey:@"recentCourses"];
  161. if (parm == nil) {
  162. self.recentCourseModel = nil;
  163. }
  164. else {
  165. self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
  166. }
  167. }
  168. else {
  169. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  170. }
  171. } faliure:^(NSError * _Nonnull error) {
  172. dispatch_group_leave(self.requestGroup);
  173. }];
  174. }
  175. - (void)refreshCourseView:(RecentCourseModel *)model {
  176. if (model) {
  177. [self.courseView configCourseMessage:model];
  178. self.courseView.hidden = NO;
  179. CGFloat height = [HomeRecentCourseView getViewHeight];
  180. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  181. make.height.mas_equalTo(height);
  182. }];
  183. }
  184. else {
  185. self.courseView.hidden = YES;
  186. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  187. make.height.mas_equalTo(CGFLOAT_MIN);
  188. }];
  189. }
  190. }
  191. - (void)refreshNotice {
  192. if (self.titleArray.count) {
  193. self.noticeView.hidden = NO;
  194. CGFloat height = [PublicNoticeView getViewHeight];
  195. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  196. make.height.mas_equalTo(height);
  197. }];
  198. }
  199. else {
  200. self.noticeView.hidden = YES;
  201. [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
  202. make.height.mas_equalTo(CGFLOAT_MIN);
  203. }];
  204. }
  205. self.noticeScrollView.titlesGroup = self.titleArray;
  206. }
  207. - (void)refreshView {
  208. [self.navView configMessage:self.mineInfo];
  209. [self.headView configMessage:self.mineInfo];
  210. [self refreshTenantNameView];
  211. [self refreshBannerView];
  212. [self refreshNotice];
  213. [self refreshButtonView];
  214. [self refreshCourseView:self.recentCourseModel];
  215. [self refreshAlbumView];
  216. [self refreshMusicView];
  217. // 刷新排序
  218. if (self.isCheck) {
  219. [self checkShowAwardAlert];
  220. }
  221. // 悬浮按钮
  222. if (self.buttonModel) {
  223. [self showFloatingWindow];
  224. }
  225. else {
  226. [self removeFloatWindow];
  227. }
  228. }
  229. - (void)refreshTenantNameView {
  230. CGFloat tenantNameHeight = CGFLOAT_MIN;
  231. if (self.mineInfo.tenantId > 0) {
  232. tenantNameHeight = [HomeTenantView getViewHeight];
  233. self.tenantNameView.hidden = NO;
  234. }
  235. else {
  236. self.tenantNameView.hidden = YES;
  237. }
  238. [self.tenantNameView mas_updateConstraints:^(MASConstraintMaker *make) {
  239. make.height.mas_equalTo(tenantNameHeight);
  240. }];
  241. [self.tenantNameView configTenantName:self.mineInfo.tenantName];
  242. }
  243. - (void)removeFloatWindow {
  244. if ([self.view.subviews containsObject:self.suspendButton]) {
  245. [self.suspendButton removeFromSuperview];
  246. }
  247. }
  248. // 显示悬浮窗
  249. - (void)showFloatingWindow {
  250. if (![self.view.subviews containsObject:self.suspendButton]) {
  251. [self.view addSubview:self.suspendButton];
  252. }
  253. [self.view bringSubviewToFront:self.suspendButton];
  254. [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
  255. }
  256. - (void)checkShowAwardAlert {
  257. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  258. if (appDelegate.isShowMemoAlert) {
  259. return;
  260. }
  261. // 如果今日已提示过,就不再提醒
  262. NSDictionary *awardAlertDic = UserDefaultObjectForKey(@"awardAlertTime");
  263. NSString *awardAlertTime = [awardAlertDic ks_stringValueForKey:@"time"];
  264. NSDate *currendDate = [NSDate date];
  265. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  266. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  267. NSString *todayString = [dateFormatter stringFromDate:currendDate];
  268. if (![NSString isEmptyString:awardAlertTime]) {
  269. NSString *userId = [awardAlertDic ks_stringValueForKey:@"userId"];
  270. if ([todayString isEqualToString:awardAlertTime] && [userId isEqualToString:UserDefaultObjectForKey(UIDKey)]) {
  271. return;
  272. }
  273. }
  274. if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
  275. return;
  276. }
  277. KSAwardAlertView *alert = [KSAwardAlertView shareInstance];
  278. MJWeakSelf;
  279. [alert awardActionCallback:^(BOOL isSure) {
  280. if (isSure) {
  281. [weakSelf displayAwardList];
  282. }
  283. }];
  284. [alert showAlert];
  285. NSDictionary *saveDic = @{@"time" :todayString , @"userId" : UserDefaultObjectForKey(UIDKey)};
  286. UserDefaultSetObjectForKey(saveDic, @"awardAlertTime");
  287. }
  288. - (void)displayAwardList {
  289. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  290. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
  291. [self.navigationController pushViewController:webCtrl animated:YES];
  292. }
  293. - (void)refreshBannerView {
  294. if (self.bannerArray.count) {
  295. self.bannerView.hidden = NO;
  296. CGFloat bannerViewHeight = [HomeBannerView getViewHeight];
  297. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  298. make.height.mas_equalTo(bannerViewHeight);
  299. }];
  300. }
  301. else {
  302. self.bannerView.hidden = YES;
  303. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  304. make.height.mas_equalTo(CGFLOAT_MIN);
  305. }];
  306. }
  307. if (self.bannerArray.count > 1) {
  308. self.bannerScroll.autoScrollInterval = 3.0f;
  309. [self.bannerScroll addSubview:self.pageControl];
  310. }
  311. else {
  312. self.bannerScroll.autoScrollInterval = 0;
  313. [self.pageControl removeFromSuperview];
  314. }
  315. self.pageControl.numberOfPages = self.bannerArray.count;
  316. [self.bannerScroll reloadData];
  317. }
  318. - (void)requestHomeButton {
  319. dispatch_group_enter(self.requestGroup);
  320. [KSNetworkingManager homeButtonList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  321. dispatch_group_leave(self.requestGroup);
  322. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  323. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  324. // banner
  325. NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
  326. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  327. for (NSDictionary *parm in bannerArray) {
  328. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  329. [bannerInfoArray addObject:model];
  330. }
  331. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  332. // button
  333. NSArray *buttonArray = [result ks_arrayValueForKey:@"appMenu"];
  334. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  335. for (NSDictionary *parm in buttonArray) {
  336. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  337. [buttonInfoArray addObject:model];
  338. }
  339. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  340. // 首页悬浮按钮
  341. NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
  342. if (suspensionArray.count) {
  343. self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
  344. }
  345. else {
  346. self.buttonModel = nil;
  347. }
  348. }
  349. else {
  350. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  351. }
  352. } faliure:^(NSError * _Nonnull error) {
  353. dispatch_group_leave(self.requestGroup);
  354. }];
  355. }
  356. - (void)refreshButtonView {
  357. [self.buttonContainer.buttonContentView removeAllSubViews];
  358. // 添加机构专辑
  359. if (self.mineInfo.tenantAlbumStatus != 0 && [UserDefault(TENANT_ID) integerValue] > 0) {
  360. HomeMessageModel *buttonModel = [[HomeMessageModel alloc] init];
  361. buttonModel.title = @"机构教程";
  362. buttonModel.linkUrl = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/train-tool"];
  363. buttonModel.coverImage = @"tenantAlbum_button";
  364. buttonModel.isLocalButton = YES;
  365. [self.buttonArray addObject:buttonModel];
  366. }
  367. CGFloat buttonSpace = (KPortraitWidth - BUTTON_ROWCOUNT * HOME_BUTTONWIDTH) / (BUTTON_ROWCOUNT /*+ 1*/);
  368. // 添加按钮
  369. if (self.buttonArray.count) {
  370. self.buttonContainer.hidden = NO;
  371. CGFloat xSpace = 0.0f;
  372. CGFloat ySpace = 0.0f;
  373. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  374. xSpace = buttonSpace / 2 + (i % BUTTON_ROWCOUNT) * (HOME_BUTTONWIDTH + buttonSpace);
  375. ySpace = (i / BUTTON_ROWCOUNT) * (HOME_BUTTONHEIGHT + HOME_BUTTON_VERTICAL_SPACE);
  376. HomeMessageModel *model = self.buttonArray[i];
  377. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  378. if (model.isLocalButton) {
  379. [buttonView.buttonImage setImage:[UIImage imageNamed:model.coverImage]];
  380. }
  381. else {
  382. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  383. }
  384. buttonView.buttonTitle.text = model.title;
  385. buttonView.frame = CGRectMake(xSpace, ySpace, HOME_BUTTONWIDTH, HOME_BUTTONHEIGHT);
  386. buttonView.actionButton.tag = 3000 + i;
  387. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  388. [self.buttonContainer.buttonContentView addSubview:buttonView];
  389. }
  390. }
  391. else {
  392. self.buttonContainer.hidden = YES;
  393. }
  394. // 高度
  395. CGFloat buttonViewDefaultHeight = [HomeButtonView getViewHeight:self.buttonArray.count];
  396. self.buttonViewHeight = buttonViewDefaultHeight;
  397. [self.buttonContainer mas_updateConstraints:^(MASConstraintMaker *make) {
  398. make.height.mas_equalTo(buttonViewDefaultHeight);
  399. }];
  400. }
  401. - (void)HomeTopButtonAction:(UIButton *)sender {
  402. NSInteger index = sender.tag - 3000;
  403. if ([self checkIsLoginToLoginView:YES]) {
  404. HomeMessageModel *model = self.buttonArray[index];
  405. if (![NSString isEmptyString:model.linkUrl]) {
  406. if ([model.linkUrl isEqualToString:@"native-metronome"]) {
  407. ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
  408. [self.navigationController pushViewController:ctrl animated:YES];
  409. }
  410. else if ([model.linkUrl isEqualToString:@"native-homepage"]) {
  411. [self toMinePage];
  412. }
  413. else if ([model.linkUrl isEqualToString:@"native-homework"]) {
  414. HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
  415. [self.navigationController pushViewController:ctrl animated:YES];
  416. }
  417. else {
  418. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  419. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  420. [self.navigationController pushViewController:webCtrl animated:YES];
  421. }
  422. }
  423. }
  424. }
  425. - (void)toMinePage {
  426. if (![self.mineInfo.entryStatus isEqualToString:@"PASS"]) { // 跳转老师认证
  427. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  428. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  429. [self.navigationController pushViewController:webCtrl animated:YES];
  430. }
  431. else {
  432. MinePageViewController *pageCtrl = [[MinePageViewController alloc] init];
  433. [self.navigationController pushViewController:pageCtrl animated:YES];
  434. }
  435. }
  436. - (void)requestAlbumSource {
  437. dispatch_group_enter(self.requestGroup);
  438. [KSNetworkingManager HomeHotAlbumRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
  439. dispatch_group_leave(self.requestGroup);
  440. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  441. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  442. NSMutableArray *albumArray = [NSMutableArray array];
  443. for (NSDictionary *parm in sourceArray) {
  444. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  445. [albumArray addObject:model];
  446. }
  447. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  448. }
  449. else {
  450. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  451. }
  452. } faliure:^(NSError * _Nonnull error) {
  453. dispatch_group_leave(self.requestGroup);
  454. }];
  455. }
  456. - (void)refreshAlbumView {
  457. if (self.albumArray.count) {
  458. self.albumViewHeight = [HomeAlbumView getViewHeight];
  459. self.albumView.hidden = NO;
  460. }
  461. else {
  462. self.albumViewHeight = CGFLOAT_MIN;
  463. self.albumView.hidden = YES;
  464. }
  465. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  466. make.height.mas_equalTo(self.albumViewHeight);
  467. }];
  468. [self.albumCollectionView reloadData];
  469. }
  470. - (void)requestHomeMusicMessage {
  471. dispatch_group_enter(self.requestGroup);
  472. [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
  473. dispatch_group_leave(self.requestGroup);
  474. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  475. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  476. NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 热门曲目
  477. NSMutableArray *hotArray = [NSMutableArray array];
  478. for (NSDictionary *parm in hotMusicSheet) {
  479. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  480. [hotArray addObject:model];
  481. }
  482. self.dataArray = [NSMutableArray arrayWithArray:hotArray];
  483. NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
  484. NSMutableArray *newMusicArray = [NSMutableArray array];
  485. for (NSDictionary *parm in newMusicSheet) {
  486. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  487. [newMusicArray addObject:model];
  488. }
  489. self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
  490. NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
  491. NSMutableArray *topMusicArray = [NSMutableArray array];
  492. for (NSDictionary *parm in topMusicSheet) {
  493. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  494. [topMusicArray addObject:model];
  495. }
  496. self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
  497. }
  498. else {
  499. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  500. }
  501. } faliure:^(NSError * _Nonnull error) {
  502. dispatch_group_leave(self.requestGroup);
  503. }];
  504. }
  505. - (void)refreshMusicView {
  506. if (self.recommendMusicArray.count) {
  507. self.recommendMusicViewHeight = [HomeHotMusicView getViewHeight];
  508. self.recommendMusicView.hidden = NO;
  509. }
  510. else {
  511. self.recommendMusicViewHeight = CGFLOAT_MIN;
  512. self.recommendMusicView.hidden = YES;
  513. }
  514. [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  515. make.height.mas_equalTo(self.recommendMusicViewHeight);
  516. }];
  517. [self.recommendMusicCollectionView reloadData];
  518. if (self.newestMusicArray.count) {
  519. self.newestMusicViewHeight = [HomeHotMusicView getViewHeight];
  520. self.newestMusicView.hidden = NO;
  521. }
  522. else {
  523. self.newestMusicViewHeight = CGFLOAT_MIN;
  524. self.newestMusicView.hidden = YES;
  525. }
  526. [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  527. make.height.mas_equalTo(self.newestMusicViewHeight);
  528. }];
  529. [self.newestMusicCollectionView reloadData];
  530. if (self.dataArray.count) {
  531. self.hotMusicHeight = [HomeHotMusicView getViewHeight];
  532. self.hotMusicView.hidden = NO;
  533. }
  534. else {
  535. self.hotMusicHeight = CGFLOAT_MIN;
  536. self.hotMusicView.hidden = YES;
  537. }
  538. [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  539. make.height.mas_equalTo(self.hotMusicHeight);
  540. }];
  541. [self.musicCollectionView reloadData];
  542. }
  543. - (void)configUI {
  544. CGFloat navHeight = [HomeNavView getViewHeight];
  545. [self.view addSubview:self.navView];
  546. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  547. make.left.right.top.mas_equalTo(self.view);
  548. make.height.mas_equalTo(navHeight);
  549. }];
  550. [self.view bringSubviewToFront:self.navView];
  551. // 名称
  552. [self.view addSubview:self.tenantNameView];
  553. CGFloat tenantNameHeight = CGFLOAT_MIN;
  554. [self.tenantNameView mas_makeConstraints:^(MASConstraintMaker *make) {
  555. make.left.right.mas_equalTo(self.view);
  556. make.top.mas_equalTo(self.navView.mas_bottom);
  557. make.height.mas_equalTo(tenantNameHeight);
  558. }];
  559. self.tenantNameView.hidden = YES;
  560. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  561. make.left.right.mas_equalTo(self.view);
  562. make.top.mas_equalTo(self.tenantNameView.mas_bottom);
  563. make.bottom.mas_equalTo(self.view.mas_bottom);
  564. }];
  565. self.scrollView.backgroundColor = [UIColor clearColor];
  566. MJWeakSelf;
  567. self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  568. [weakSelf requestHomeMessage];
  569. }];
  570. // 背景
  571. [self.scrollView addSubview:self.headBgView];
  572. // header
  573. [self.scrollView addSubview:self.headView];
  574. CGFloat headHeight = [self.headView getViewHeight];
  575. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  576. make.left.right.mas_equalTo(self.view);
  577. make.top.mas_equalTo(self.scrollView.mas_top);
  578. make.height.mas_equalTo(headHeight);
  579. }];
  580. // 最近课程
  581. [self.scrollView addSubview:self.courseView];
  582. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  583. make.left.right.mas_equalTo(self.view);
  584. make.top.mas_equalTo(self.headView.mas_bottom);
  585. make.height.mas_equalTo(CGFLOAT_MIN);
  586. }];
  587. self.courseView.hidden = YES;
  588. // banner
  589. [self.scrollView addSubview:self.bannerView];
  590. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  591. make.left.right.mas_equalTo(self.view);
  592. make.top.mas_equalTo(self.courseView.mas_bottom);
  593. make.height.mas_equalTo(CGFLOAT_MIN);
  594. }];
  595. self.bannerView.hidden = YES;
  596. // 公告
  597. [self.scrollView addSubview:self.noticeView];
  598. [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
  599. make.left.right.mas_equalTo(self.view);
  600. make.top.mas_equalTo(self.bannerView.mas_bottom);
  601. make.height.mas_equalTo(CGFLOAT_MIN);
  602. }];
  603. [self.noticeView.adView addSubview:self.noticeScrollView];
  604. [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  605. make.top.left.right.bottom.mas_equalTo(self.noticeView.adView);
  606. }];
  607. self.noticeView.hidden = YES;
  608. // 按钮
  609. [self.scrollView addSubview:self.buttonContainer];
  610. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  611. make.left.right.mas_equalTo(self.view);
  612. make.top.mas_equalTo(self.noticeView.mas_bottom);
  613. make.height.mas_equalTo(CGFLOAT_MIN);
  614. }];
  615. self.buttonContainer.hidden = YES;
  616. [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  617. make.left.right.mas_equalTo(self.headView);
  618. make.top.mas_equalTo(self.headView.mas_top);
  619. make.bottom.mas_equalTo(self.buttonContainer.mas_bottom);
  620. }];
  621. self.headBgView.layer.masksToBounds = YES;
  622. self.headBgView.layer.cornerRadius = 18.0f;
  623. self.headBgView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
  624. [self.scrollView addSubview:self.albumView];
  625. self.albumViewHeight = [HomeAlbumView getViewHeight];
  626. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  627. make.left.right.mas_equalTo(self.view);
  628. make.top.mas_equalTo(self.headBgView.mas_bottom);
  629. make.height.mas_equalTo(self.albumViewHeight);
  630. }];
  631. [self.scrollView addSubview:self.recommendMusicView];
  632. CGFloat recommendMusicHeadHeight = [HomeRecommendMusicView getViewHeight];
  633. [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  634. make.left.right.mas_equalTo(self.view);
  635. make.top.mas_equalTo(self.albumView.mas_bottom);
  636. make.height.mas_equalTo(recommendMusicHeadHeight);
  637. }];
  638. [self.scrollView addSubview:self.newestMusicView];
  639. CGFloat newMusicHeight = [HomeNewMusicView getViewHeight];
  640. [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  641. make.left.right.mas_equalTo(self.view);
  642. make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
  643. make.height.mas_equalTo(newMusicHeight);
  644. }];
  645. [self.scrollView addSubview:self.hotMusicView];
  646. CGFloat musicHeadHeight = [HomeHotMusicView getViewHeight];
  647. [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  648. make.left.right.mas_equalTo(self.view);
  649. make.top.mas_equalTo(self.newestMusicView.mas_bottom);
  650. make.height.mas_equalTo(musicHeadHeight);
  651. make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
  652. }];
  653. }
  654. - (void)requestHomeMessage {
  655. [LOADING_MANAGER showHUD];
  656. [self requestUserInfo];
  657. }
  658. - (void)requestData {
  659. [self requestUnreadCount];
  660. [self requestHomeButton];
  661. [self requestRecentCourse];
  662. [self requestNotice];
  663. [self requestAlbumSource];
  664. [self requestHomeMusicMessage];
  665. [self requestAwardMessage];
  666. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  667. [LOADING_MANAGER removeHUD];
  668. [self.scrollView.mj_header endRefreshing];
  669. [self refreshView];
  670. });
  671. }
  672. - (void)viewWillAppear:(BOOL)animated {
  673. [super viewWillAppear:animated];
  674. if (self.isFirstLoad == YES) {
  675. self.isFirstLoad = NO;
  676. [self requestTrackAuth];
  677. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  678. [appDelegate handleNotiferSource];
  679. }
  680. if (self.isSettingSubject == NO) {
  681. [self requestHomeMessage];
  682. }
  683. self.isSettingSubject = NO;
  684. }
  685. // track
  686. - (void)requestTrackAuth {
  687. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  688. [appDelegate appTrackActionAuth];
  689. }
  690. - (void)requestUnreadCount {
  691. [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  692. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  693. NSArray *countArray = [dic ks_arrayValueForKey:@"data"];
  694. NSInteger courseCount = 0;
  695. NSInteger sysCount = 0;
  696. for (NSDictionary *parm in countArray) {
  697. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
  698. courseCount = [parm ks_integerValueForKey:@"value"];
  699. }
  700. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
  701. sysCount = [parm ks_integerValueForKey:@"value"];
  702. }
  703. }
  704. if (courseCount != 0 || sysCount != 0) {
  705. self.navView.dotView.hidden = NO;
  706. }
  707. else {
  708. self.navView.dotView.hidden = YES;
  709. }
  710. }
  711. else {
  712. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  713. }
  714. } faliure:^(NSError * _Nonnull error) {
  715. }];
  716. }
  717. #pragma mark ----- SDCycleScrollViewDelegate
  718. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  719. NoticeSourceModel *bannerModel = self.noticeArray[index];
  720. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  721. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  722. [self.navigationController pushViewController:webCtrl animated:YES];
  723. }
  724. #pragma mark ----- lazying
  725. - (UIView *)headBgView {
  726. if (!_headBgView) {
  727. _headBgView = [[UIView alloc] init];
  728. _headBgView.backgroundColor = [UIColor whiteColor];
  729. }
  730. return _headBgView;
  731. }
  732. - (HomeNavView *)navView {
  733. if (!_navView) {
  734. _navView = [HomeNavView shareInstance];
  735. MJWeakSelf;
  736. [_navView displayMessageCenter:^(HOMENAV_ACTION action) {
  737. if (action == HOMENAV_ACTION_MESSAGE) {
  738. [weakSelf toMessageCenter];
  739. }
  740. else {
  741. [weakSelf scanAction];
  742. }
  743. }];
  744. }
  745. return _navView;
  746. }
  747. - (void)scanAction {
  748. // 判断是否有权限
  749. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  750. if (type == PREMISSIONTYPE_YES) {
  751. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  752. [self.navigationController pushViewController:ctrl animated:YES];
  753. }
  754. else {
  755. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  756. }
  757. }];
  758. }
  759. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  760. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  761. } confirm:^{
  762. [self openSettingView];
  763. }];
  764. }
  765. - (void)openSettingView {
  766. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  767. }
  768. - (void)toMessageCenter {
  769. NotiferMessageViewController *messageCenter = [[NotiferMessageViewController alloc] init];
  770. [self.navigationController pushViewController:messageCenter animated:YES];
  771. }
  772. - (HomeNewHeadView *)headView {
  773. if (!_headView) {
  774. _headView = [HomeNewHeadView shareInstance];
  775. MJWeakSelf;
  776. [_headView authDetailAction:^(HOMEHEADACTION action) {
  777. [weakSelf headAction:action];
  778. }];
  779. }
  780. return _headView;
  781. }
  782. - (void)headAction:(HOMEHEADACTION)type {
  783. switch (type) {
  784. case HOMEHEADACTION_AUTH:
  785. {
  786. [self toAuthDetail];
  787. }
  788. break;
  789. case HOMEHEADACTION_EDUCATION:
  790. case HOMEHEADACTION_EDUCATIONFINISH:
  791. { // 不弹窗 直接跳转
  792. // [self showAuthEducationAlert];
  793. [self toAuthEducation];
  794. }
  795. break;
  796. case HOMEHEADACTION_SUBJECTCHOOSE:
  797. {
  798. [self showChooseSubjectView];
  799. }
  800. break;
  801. default:
  802. break;
  803. }
  804. }
  805. - (void)showChooseSubjectView {
  806. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  807. ctrl.isSingleChoose = YES;
  808. MJWeakSelf;
  809. [ctrl chooseCallback:^(NSMutableArray * _Nullable chooseArray) {
  810. NSDictionary *parm = [chooseArray firstObject];
  811. NSString *subjectId = [parm ks_stringValueForKey:@"subjectId"];
  812. NSString *subjectName = [parm ks_stringValueForKey:@"subjectName"];
  813. weakSelf.headView.subjectLabel.text = subjectName;
  814. [weakSelf setDefaultSubject:subjectId];
  815. }];
  816. self.isSettingSubject = YES;
  817. [self.navigationController pushViewController:ctrl animated:YES];
  818. }
  819. - (void)setDefaultSubject:(NSString *)subjectId {
  820. [LOADING_MANAGER showHUD];
  821. [KSNetworkingManager defaultSubjectRequest:KS_POST subjectId:subjectId success:^(NSDictionary * _Nonnull dic) {
  822. [LOADING_MANAGER removeHUD];
  823. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  824. // 请求数据
  825. [self requestHomeMessage];
  826. }
  827. else {
  828. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  829. }
  830. } faliure:^(NSError * _Nonnull error) {
  831. [LOADING_MANAGER removeHUD];
  832. }];
  833. }
  834. - (void)toAuthEducation {
  835. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  836. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCertUpdate"];
  837. [self.navigationController pushViewController:webCtrl animated:YES];
  838. }
  839. - (void)showAuthEducationAlert {
  840. BOOL hasDegreeAuth = self.mineInfo.degreeFlag;
  841. BOOL hasTeacherAuth = self.mineInfo.teacherFlag;
  842. self.authAlertView = [HomeAuthAlertView shareIntance];
  843. if (hasDegreeAuth) {
  844. [self.authAlertView.educationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
  845. [self.authAlertView.educationStatus setText:@"已认证"];
  846. [self.authAlertView.educationStatus setTextColor:HexRGB(0x999999)];
  847. }
  848. else {
  849. [self.authAlertView.educationImage setImage:[UIImage imageNamed:@""]];
  850. [self.authAlertView.educationStatus setText:@"未认证"];
  851. [self.authAlertView.educationStatus setTextColor:HexRGB(0xff0000)];
  852. }
  853. if (hasTeacherAuth) {
  854. [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
  855. [self.authAlertView.qualificationStatus setText:@"已认证"];
  856. [self.authAlertView.qualificationStatus setTextColor:HexRGB(0x999999)];
  857. }
  858. else {
  859. [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@""]];
  860. [self.authAlertView.qualificationStatus setText:@"未认证"];
  861. [self.authAlertView.qualificationStatus setTextColor:HexRGB(0xff0000)];
  862. }
  863. if (hasDegreeAuth && hasTeacherAuth) {
  864. self.authAlertView.isFinish = YES;
  865. self.authAlertView.rate = 1.0f;
  866. }
  867. else {
  868. self.authAlertView.isFinish = NO;
  869. if (hasDegreeAuth || hasTeacherAuth) {
  870. self.authAlertView.rate = 0.9f;
  871. }
  872. else {
  873. self.authAlertView.rate = 0.8f;
  874. }
  875. }
  876. MJWeakSelf;
  877. [self.authAlertView authEducationAction:^{
  878. [weakSelf toAuthEducation];
  879. }];
  880. [self.authAlertView showAlertView];
  881. }
  882. - (void)toUserCenter {
  883. UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
  884. [self.navigationController pushViewController:ctrl animated:YES];
  885. }
  886. - (void)toAuthDetail {
  887. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  888. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  889. [self.navigationController pushViewController:webCtrl animated:YES];
  890. }
  891. - (PublicNoticeView *)noticeView {
  892. if (!_noticeView) {
  893. _noticeView = [PublicNoticeView shareInstance];
  894. MJWeakSelf;
  895. [_noticeView moreCallback:^{
  896. [weakSelf moreNotice];
  897. }];
  898. }
  899. return _noticeView;
  900. }
  901. #pragma mark -- lazying
  902. - (dispatch_group_t)requestGroup {
  903. if (!_requestGroup) {
  904. _requestGroup = dispatch_group_create();
  905. }
  906. return _requestGroup;
  907. }
  908. - (SDCycleScrollView *)noticeScrollView {
  909. if (!_noticeScrollView) {
  910. _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
  911. _noticeScrollView.onlyDisplayText = YES;
  912. _noticeScrollView.autoScroll = NO;
  913. _noticeScrollView.scrollEnabled = NO;
  914. _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
  915. _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
  916. _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor];
  917. _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
  918. _noticeScrollView.titlesGroup = self.titleArray;
  919. }
  920. return _noticeScrollView;
  921. }
  922. - (NSMutableArray *)noticeArray {
  923. if (!_noticeArray) {
  924. _noticeArray = [NSMutableArray array];
  925. }
  926. return _noticeArray;
  927. }
  928. - (NSMutableArray *)titleArray {
  929. if (!_titleArray) {
  930. _titleArray = [NSMutableArray array];
  931. }
  932. return _titleArray;
  933. }
  934. - (void)moreNotice {
  935. if (self.noticeArray.count) {
  936. NoticeSourceModel *bannerModel = self.noticeArray[0];
  937. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  938. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  939. [self.navigationController pushViewController:webCtrl animated:YES];
  940. }
  941. }
  942. - (HomeRecentCourseView *)courseView {
  943. if (!_courseView) {
  944. _courseView = [HomeRecentCourseView shareInstance];
  945. MJWeakSelf;
  946. [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
  947. [weakSelf joinRoomAction:type roomId:courseModel];
  948. }];
  949. }
  950. return _courseView;
  951. }
  952. - (void)joinRoomAction:(RECENTCOURSE_TYPE)type roomId:(RecentCourseModel *)courseModel {
  953. if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
  954. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  955. detailVC.courseId = courseModel.courseId;
  956. detailVC.courseGroupId = courseModel.courseGroupId;
  957. detailVC.studentId = courseModel.studentId;
  958. [self.navigationController pushViewController:detailVC animated:YES];
  959. }
  960. else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
  961. MusicRoomViewController *ctrl = [[MusicRoomViewController alloc] init];
  962. ctrl.courseId = courseModel.courseId;
  963. ctrl.courseGroupId = courseModel.courseGroupId;
  964. [self.navigationController pushViewController:ctrl animated:YES];
  965. }
  966. else if (type == RECENTCOURSE_TYPE_VIP) { //VIP 定制课
  967. VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
  968. detailVC.courseId = courseModel.courseId;
  969. detailVC.courseGroupId = courseModel.courseGroupId;
  970. detailVC.studentId = courseModel.studentId;
  971. [self.navigationController pushViewController:detailVC animated:YES];
  972. }
  973. else {
  974. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  975. ctrl.url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST, courseModel.courseGroupId,courseModel.courseId];
  976. [self.navigationController pushViewController:ctrl animated:YES];
  977. }
  978. }
  979. - (void)displaySongDetail:(NSString *)songId {
  980. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  981. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  982. [self.navigationController pushViewController:ctrl animated:YES];
  983. }
  984. #pragma mark ---- scroll view delegate
  985. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  986. }
  987. #pragma mark ---- button container
  988. - (HomeButtonView *)buttonContainer {
  989. if (!_buttonContainer) {
  990. _buttonContainer = [HomeButtonView shareInstance];
  991. }
  992. return _buttonContainer;
  993. }
  994. #pragma mark ---- collection data source
  995. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  996. return 1;
  997. }
  998. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  999. if (collectionView == self.albumCollectionView) {
  1000. return self.albumArray.count;
  1001. }
  1002. else if (collectionView == self.recommendMusicCollectionView) {
  1003. NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
  1004. NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
  1005. return count;
  1006. }
  1007. else if (collectionView == self.newestMusicCollectionView) {
  1008. NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
  1009. NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
  1010. return count;
  1011. }
  1012. else {
  1013. NSInteger lastRowCount = (self.dataArray.count % 4) > 0 ? 1 : 0;
  1014. NSInteger count = self.dataArray.count / 4 + lastRowCount;
  1015. return count;
  1016. }
  1017. }
  1018. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  1019. if (collectionView == self.albumCollectionView) {
  1020. HomeAlbumModel *model = self.albumArray[indexPath.item];
  1021. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  1022. [cell configWithAlbumModel:model];
  1023. return cell;
  1024. }
  1025. else if (collectionView == self.recommendMusicCollectionView) {
  1026. NSMutableArray *songArray = [NSMutableArray array];
  1027. NSInteger length = indexPath.item * 4 + 4 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 4: 4;
  1028. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1029. songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
  1030. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1031. MJWeakSelf;
  1032. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1033. [weakSelf displaySongDetail:songId];
  1034. }];
  1035. return cell;
  1036. }
  1037. else if (collectionView == self.newestMusicCollectionView) {
  1038. NSMutableArray *songArray = [NSMutableArray array];
  1039. NSInteger length = indexPath.item * 4 + 4 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 4: 4;
  1040. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1041. songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
  1042. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1043. MJWeakSelf;
  1044. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1045. [weakSelf displaySongDetail:songId];
  1046. }];
  1047. return cell;
  1048. }
  1049. else {
  1050. NSMutableArray *songArray = [NSMutableArray array];
  1051. NSInteger length = indexPath.item * 4 + 4 > self.dataArray.count ? self.dataArray.count - indexPath.item * 4: 4;
  1052. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1053. songArray = [NSMutableArray arrayWithArray:[self.dataArray subarrayWithRange:range]];
  1054. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1055. MJWeakSelf;
  1056. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1057. [weakSelf displaySongDetail:songId];
  1058. }];
  1059. return cell;
  1060. }
  1061. }
  1062. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  1063. if (collectionView == self.albumCollectionView) {
  1064. HomeAlbumModel *model = self.albumArray[indexPath.item];
  1065. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1066. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  1067. [self.navigationController pushViewController:ctrl animated:YES];
  1068. }
  1069. }
  1070. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  1071. if (collectionView == self.albumCollectionView) {
  1072. return CGSizeMake(100, 134);
  1073. }
  1074. else {
  1075. return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
  1076. }
  1077. }
  1078. #pragma mark ----- 专辑
  1079. - (HomeAlbumView *)albumView {
  1080. if (!_albumView) {
  1081. _albumView = [HomeAlbumView shareInstance];
  1082. MJWeakSelf;
  1083. [_albumView homeAlbumMore:^{
  1084. [weakSelf moreAlbumDetail];
  1085. }];
  1086. [_albumView.albumContentView addSubview:self.albumCollectionView];
  1087. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1088. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  1089. }];
  1090. }
  1091. return _albumView;
  1092. }
  1093. - (UICollectionView *)albumCollectionView {
  1094. if (!_albumCollectionView) {
  1095. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1096. layout.sectionInset = UIEdgeInsetsMake(12, 11, 12, 14);
  1097. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1098. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1099. _albumCollectionView.backgroundColor = [UIColor clearColor];
  1100. _albumCollectionView.delegate = self;
  1101. _albumCollectionView.dataSource = self;
  1102. _albumCollectionView.showsVerticalScrollIndicator = NO;
  1103. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  1104. if (@available(iOS 11.0, *)) {
  1105. _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1106. } else {
  1107. // Fallback on earlier versions
  1108. if (@available(iOS 13.0, *)) {
  1109. _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1110. } else {
  1111. // Fallback on earlier versions
  1112. }
  1113. }
  1114. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  1115. }
  1116. return _albumCollectionView;
  1117. }
  1118. - (NSMutableArray *)albumArray {
  1119. if (!_albumArray) {
  1120. _albumArray = [NSMutableArray array];
  1121. }
  1122. return _albumArray;
  1123. }
  1124. - (void)moreAlbumDetail {
  1125. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1126. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
  1127. [self.navigationController pushViewController:ctrl animated:YES];
  1128. }
  1129. #pragma mark --- 推荐曲目
  1130. - (HomeRecommendMusicView *)recommendMusicView {
  1131. if (!_recommendMusicView) {
  1132. _recommendMusicView = [HomeRecommendMusicView shareInstance];
  1133. MJWeakSelf;
  1134. [_recommendMusicView homeMusicMore:^{
  1135. [weakSelf moreRecommendMusic];
  1136. }];
  1137. [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
  1138. [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1139. make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
  1140. }];
  1141. }
  1142. return _recommendMusicView;
  1143. }
  1144. - (UICollectionView *)recommendMusicCollectionView {
  1145. if (!_recommendMusicCollectionView) {
  1146. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  1147. _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1148. _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
  1149. _recommendMusicCollectionView.delegate = self;
  1150. _recommendMusicCollectionView.dataSource = self;
  1151. _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
  1152. _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
  1153. if (@available(iOS 11.0, *)) {
  1154. _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1155. } else {
  1156. // Fallback on earlier versions
  1157. if (@available(iOS 13.0, *)) {
  1158. _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1159. } else {
  1160. // Fallback on earlier versions
  1161. }
  1162. }
  1163. [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1164. }
  1165. return _recommendMusicCollectionView;
  1166. }
  1167. - (NSMutableArray *)recommendMusicArray {
  1168. if (!_recommendMusicArray) {
  1169. _recommendMusicArray = [NSMutableArray array];
  1170. }
  1171. return _recommendMusicArray;
  1172. }
  1173. - (void)moreRecommendMusic {
  1174. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1175. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1176. [self.navigationController pushViewController:ctrl animated:YES];
  1177. }
  1178. #pragma mark ---- 最新曲目
  1179. - (HomeNewMusicView *)newestMusicView {
  1180. if (!_newestMusicView) {
  1181. if (!_newestMusicView) {
  1182. _newestMusicView = [HomeNewMusicView shareInstance];
  1183. MJWeakSelf;
  1184. [_newestMusicView homeMusicMore:^{
  1185. [weakSelf moreNewMusic];
  1186. }];
  1187. [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
  1188. [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1189. make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
  1190. }];
  1191. }
  1192. return _newestMusicView;
  1193. }
  1194. return _newestMusicView;
  1195. }
  1196. - (UICollectionView *)newestMusicCollectionView {
  1197. if (!_newestMusicCollectionView) {
  1198. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  1199. _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1200. _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
  1201. _newestMusicCollectionView.delegate = self;
  1202. _newestMusicCollectionView.dataSource = self;
  1203. _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
  1204. _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
  1205. if (@available(iOS 11.0, *)) {
  1206. _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1207. } else {
  1208. // Fallback on earlier versions
  1209. if (@available(iOS 13.0, *)) {
  1210. _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1211. } else {
  1212. // Fallback on earlier versions
  1213. }
  1214. }
  1215. [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1216. }
  1217. return _newestMusicCollectionView;
  1218. }
  1219. - (NSMutableArray *)newestMusicArray {
  1220. if (!_newestMusicArray) {
  1221. _newestMusicArray = [NSMutableArray array];
  1222. }
  1223. return _newestMusicArray;
  1224. }
  1225. - (void)moreNewMusic {
  1226. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1227. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1228. [self.navigationController pushViewController:ctrl animated:YES];
  1229. }
  1230. #pragma mark ---- 更多曲目
  1231. - (HomeHotMusicView *)hotMusicView {
  1232. if (!_hotMusicView) {
  1233. _hotMusicView = [HomeHotMusicView shareInstance];
  1234. MJWeakSelf;
  1235. [_hotMusicView homeMusicMore:^{
  1236. [weakSelf moreHotMusic];
  1237. }];
  1238. [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
  1239. [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1240. make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
  1241. }];
  1242. }
  1243. return _hotMusicView;
  1244. }
  1245. - (void)moreHotMusic {
  1246. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1247. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1248. [self.navigationController pushViewController:ctrl animated:YES];
  1249. }
  1250. - (UICollectionView *)musicCollectionView {
  1251. if (!_musicCollectionView) {
  1252. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  1253. _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1254. _musicCollectionView.backgroundColor = [UIColor clearColor];
  1255. _musicCollectionView.delegate = self;
  1256. _musicCollectionView.dataSource = self;
  1257. _musicCollectionView.showsVerticalScrollIndicator = NO;
  1258. _musicCollectionView.showsHorizontalScrollIndicator = NO;
  1259. if (@available(iOS 11.0, *)) {
  1260. _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1261. } else {
  1262. // Fallback on earlier versions
  1263. if (@available(iOS 13.0, *)) {
  1264. _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1265. } else {
  1266. // Fallback on earlier versions
  1267. }
  1268. }
  1269. [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1270. }
  1271. return _musicCollectionView;
  1272. }
  1273. - (HomeBannerView *)bannerView {
  1274. if (!_bannerView) {
  1275. _bannerView = [HomeBannerView shareInstance];
  1276. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  1277. }
  1278. return _bannerView;
  1279. }
  1280. - (TYCyclePagerView *)bannerScroll {
  1281. if (!_bannerScroll) {
  1282. _bannerScroll = [[TYCyclePagerView alloc] init];
  1283. _bannerScroll.backgroundColor = [UIColor clearColor];
  1284. _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth, (kScreenWidth - 28) / 347 * 132);
  1285. _bannerScroll.isInfiniteLoop = YES;
  1286. _bannerScroll.autoScrollInterval = 3.0f;
  1287. _bannerScroll.reloadDataNeedResetIndex = YES;
  1288. _bannerScroll.dataSource = self;
  1289. _bannerScroll.delegate = self;
  1290. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  1291. if (@available(iOS 11.0, *)) {
  1292. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1293. } else {
  1294. // Fallback on earlier versions
  1295. if (@available(iOS 13.0, *)) {
  1296. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1297. } else {
  1298. // Fallback on earlier versions
  1299. }
  1300. }
  1301. }
  1302. return _bannerScroll;
  1303. }
  1304. - (TYPageControl *)pageControl {
  1305. if (!_pageControl) {
  1306. _pageControl = [[TYPageControl alloc] init];
  1307. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  1308. _pageControl.pageIndicatorSpaing = 4.0f;
  1309. _pageControl.frame = CGRectMake(0, (kScreenWidth - 28) * 132 / 347 - 20, kScreenWidth-28 - 12, 12);
  1310. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  1311. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  1312. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  1313. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  1314. }
  1315. return _pageControl;
  1316. }
  1317. - (NSMutableArray *)bannerArray {
  1318. if (!_bannerArray) {
  1319. _bannerArray = [NSMutableArray array];
  1320. }
  1321. return _bannerArray;
  1322. }
  1323. #pragma mark - TYCyclePagerViewDataSource代理
  1324. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  1325. return self.bannerArray.count;
  1326. }
  1327. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  1328. HomeMessageModel *model = self.bannerArray[index];
  1329. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  1330. [cell configCellWithModel:model];
  1331. return cell;
  1332. }
  1333. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  1334. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  1335. layout.itemSize = CGSizeMake(kScreenWidth, (kScreenWidth - 28) / 347 * 132);
  1336. layout.itemSpacing = 0;
  1337. return layout;
  1338. }
  1339. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  1340. if (pageView == self.bannerScroll) {
  1341. [self.pageControl setCurrentPage:toIndex animate:YES];
  1342. }
  1343. }
  1344. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  1345. HomeMessageModel *model = self.bannerArray[index];
  1346. if (![NSString isEmptyString:model.linkUrl]) {
  1347. if ([model.linkType isEqualToString:@"OUT"]) {
  1348. // 外部浏览器打开
  1349. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  1350. }
  1351. else {
  1352. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1353. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  1354. [self.navigationController pushViewController:webCtrl animated:YES];
  1355. }
  1356. }
  1357. }
  1358. - (HomeDragButton *)suspendButton {
  1359. if (!_suspendButton) {
  1360. _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
  1361. MJWeakSelf;
  1362. [_suspendButton clickAction:^{
  1363. [weakSelf showDragWindowDetail];
  1364. }];
  1365. }
  1366. return _suspendButton;
  1367. }
  1368. - (void)showDragWindowDetail {
  1369. NSString *linkUrl = self.buttonModel.linkUrl;
  1370. if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
  1371. // 外部浏览器打开
  1372. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  1373. }
  1374. else {
  1375. if (![NSString isEmptyString:linkUrl]) {
  1376. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1377. webCtrl.url = [linkUrl getUrlEndcodeString];
  1378. [self.navigationController pushViewController:webCtrl animated:YES];
  1379. }
  1380. }
  1381. }
  1382. - (HomeTenantView *)tenantNameView {
  1383. if (!_tenantNameView) {
  1384. _tenantNameView = [HomeTenantView shareInstance];
  1385. }
  1386. return _tenantNameView;
  1387. }
  1388. /*
  1389. #pragma mark - Navigation
  1390. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1391. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1392. // Get the new view controller using [segue destinationViewController].
  1393. // Pass the selected object to the new view controller.
  1394. }
  1395. */
  1396. @end