12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "KSBaseWKWebViewController.h"
- #import "NotiferMessageViewController.h"
- #import "SubjectChooseViewController.h"
- #import "HomeNavView.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "HomeBannerView.h"
- #import "HomeBannerCell.h"
- #import "HomeButtonView.h"
- #import "KSHomeButton.h"
- #import "HomeHotAlbumView.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeAlbumModel.h"
- #import "HomeHotCourseView.h"
- #import "HomeIntroduceView.h"
- #import "TeacherShowCell.h"
- #import "HotInformationHeadView.h"
- #import "TeacherStyleModel.h"
- #import "HomeInformationCell.h"
- #import "HomeMessageModel.h"
- #import "StudentInfoModel.h"
- #import "UserInfoManager.h"
- #import "HomeCourseTipsView.h"
- #import "HomeLiveCouseCell.h"
- #import "HomeLiveGroupModel.h"
- #import "HomeVideoCourseCell.h"
- #import "HomeVideoGroupModel.h"
- #import "WMPlayer.h" // 播放相关
- #import "AppDelegate.h"
- #import "KSNewsAlert.h"
- #import "RecentCourseModel.h"
- #import "AccompanyDetailViewController.h"
- #define BUTTONWIDTH (65)
- #define BUTTONHEIGHT (80)
- @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,WMPlayerDelegate>
- {
- WMPlayer *_wmPlayer;
- CGRect _playerFrame;
- }
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, assign) BOOL isRatation;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) HomeNavView *navView;
- @property (nonatomic, strong) UIView *tableHeaderView; // headView;
- @property (nonatomic, strong) TYPageControl *pageControl;
- @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
- @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
- @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
- @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
- @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
- @property (nonatomic, strong) UIScrollView *buttonScrollView;
- @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
- @property (nonatomic, assign) NSInteger buttonDotWidth;
- @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
- @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
- @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
- @property (nonatomic, strong) HomeHotCourseView *courseView; // course container
- @property (nonatomic, strong) UIScrollView *courseScroll; // 课程scroll
- @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
- @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
- @property (nonatomic, strong) NSMutableArray *videoCourseArray;
- @property (nonatomic, strong) NSMutableArray *liveCourseArray;
- @property (nonatomic, assign) CGFloat courseViewHeight;
- @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
- @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
- @property (nonatomic, strong) NSMutableArray *teacherArray;
- @property (nonatomic, assign) CGFloat teachViewHeight;
- @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
- @property (nonatomic, assign) CGFloat informationHeight;
- @property (nonatomic, strong) StudentInfoModel *mineInfo;
- @property (nonatomic, assign) BOOL hasCourseTips;
- @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
- @property (nonatomic, assign) CGFloat tipsViewHeight;
- @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
- @property (nonatomic, assign) NSInteger courseCount;
- @property (nonatomic, assign) BOOL isFirstLoad;
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- self.isChooseLive = YES;
- self.isFirstLoad = YES;
- [self configNavView];
- [self configUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.isFirstLoad == YES) {
- [self requestUserInfo:YES]; // 获取声部
-
- }
- else {
- [self requestUserInfo:NO];
- }
-
- [self requestUnreadCount];
- }
- - (void)requestUnreadCount {
- [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *countArray = [dic arrayValueForKey:@"data"];
- NSInteger courseCount = 0;
- NSInteger sysCount = 0;
- NSInteger noticeCount = 0;
- for (NSDictionary *parm in countArray) {
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
- courseCount = [parm integerValueForKey:@"value"];
- }
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
- sysCount = [parm integerValueForKey:@"value"];
- }
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"NOTICE"]) {
- noticeCount = [parm integerValueForKey:@"value"];
- }
- }
- if (courseCount != 0 || sysCount != 0 || noticeCount != 0) {
- self.navView.dotView.hidden = NO;
- }
- else {
- self.navView.dotView.hidden = YES;
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)configNavView {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- }];
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.tableHeaderView = self.tableHeaderView;
- MJWeakSelf;
- self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
-
- // 配置 首页显示
- [self addDisplayView];
- }
- - (void)addDisplayView {
- CGFloat tableHeaderHeight = 0.0f;
- [self.tableHeaderView addSubview:self.bannerView];
- // banner
- self.bannerViewHeight = [HomeBannerView getViewHeight];
- tableHeaderHeight += self.bannerViewHeight;
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top);
- make.height.mas_equalTo(self.bannerViewHeight);
- }];
- // button
- [self.tableHeaderView addSubview:self.buttonContainer];
- self.buttonViewHeight = [HomeButtonView getViewHeight];
- [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(self.buttonViewHeight);
- }];
- tableHeaderHeight += self.buttonViewHeight;
-
- // 课程提醒
- [self.tableHeaderView addSubview:self.tipsCourseView];
- self.tipsViewHeight = CGFLOAT_MIN;
- self.tipsCourseView.hidden = YES;
- [self.tipsCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.buttonContainer.mas_bottom);
- make.height.mas_equalTo(self.tipsViewHeight);
- }];
- tableHeaderHeight += self.tipsViewHeight;
- // 专辑
- [self.tableHeaderView addSubview:self.albumView];
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tipsCourseView.mas_bottom);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- tableHeaderHeight += self.albumViewHeight;
-
- // 课程
- [self.tableHeaderView addSubview:self.courseView];
- self.courseViewHeight = [self.courseView getViewHeightWithCount:10];
- [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(self.courseViewHeight);
- }];
- self.courseScroll.contentSize = CGSizeMake(KPortraitWidth * 2, self.courseViewHeight - 59);
- [self.courseScroll addSubview:self.liveCourseTable];
- [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.courseScroll);
- make.top.bottom.mas_equalTo(self.courseView.courseContainer);
- make.width.mas_equalTo(KPortraitWidth);
- }];
- [self.courseScroll addSubview:self.videoCourseTable];
- [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(_courseScroll.mas_left).offset(KPortraitWidth);
- make.top.bottom.mas_equalTo(self.courseView.courseContainer);
- make.width.mas_equalTo(KPortraitWidth);
- }];
- tableHeaderHeight += self.courseViewHeight;
-
- // 老师风采
- [self.tableHeaderView addSubview:self.teacherView];
- self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:4];
-
- [self.teacherView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.courseView.mas_bottom);
- make.height.mas_equalTo(self.teachViewHeight);
- }];
- tableHeaderHeight += self.teachViewHeight;
-
- [self.tableHeaderView addSubview:self.informationHeadView];
- self.informationHeight = [HotInformationHeadView getViewHeight];
- [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.teacherView.mas_bottom);
- make.height.mas_equalTo(self.informationHeight);
- }];
- tableHeaderHeight += self.informationHeight;
- self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
- [self.tableView reloadData];
- }
- - (void)refreshTableHeadHeight {
- CGFloat tableHeaderHeight = self.bannerViewHeight + self.buttonViewHeight + self.tipsViewHeight + self.albumViewHeight + self.courseViewHeight + self.teachViewHeight + self.informationHeight;
- self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
- [self.tableView reloadData];
- }
- - (void)requestData {
- [self requestNewsList]; //
- [self requestCourseInfo];
- [self requestTeacherStyle];
- [self requestHotAlbum];
- }
- - (void)requestNewsList {
- [KSNetworkingManager homeNewsList:KS_POST success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *result = [dic dictionaryValueForKey:@"data"];
- // banner
- NSArray *bannerArray = [result arrayValueForKey:@"banner"];
- NSMutableArray *bannerInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in bannerArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [bannerInfoArray addObject:model];
- }
- self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
- [self.bannerScroll reloadData];
-
- // button
- NSArray *buttonArray = [result arrayValueForKey:@"appMenu"];
- NSMutableArray *buttonInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in buttonArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [buttonInfoArray addObject:model];
- }
- self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
- [self showButtonMessage];
-
- // news
- NSArray *flashArray = [result arrayValueForKey:@"flashPage"];
- if (flashArray.count) {
- HomeMessageModel *newsModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
- [self showNewsWithSource:newsModel];
- }
-
- // information
- NSArray *information = [result arrayValueForKey:@"information"];
- NSMutableArray *informationInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in information) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [informationInfoArray addObject:model];
- }
- self.dataArray = [NSMutableArray arrayWithArray:informationInfoArray];
- [self.tableView reloadData];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestHotAlbum {
- [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- NSMutableArray *albumArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
- [albumArray addObject:model];
- }
- self.albumArray = [NSMutableArray arrayWithArray:albumArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self refreshAlbumView];
-
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)refreshAlbumView {
- if (self.albumArray.count) {
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- self.albumView.hidden = NO;
- }
- else {
- self.albumViewHeight = CGFLOAT_MIN;
- self.albumView.hidden = YES;
- }
- [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- [self.albumCollectionView reloadData];
- [self refreshTableHeadHeight];
- }
- - (void)requestCourseInfo {
- [self showhud];
- [KSNetworkingManager homeQueryLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- [self.tableView.mj_header endRefreshing];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
- NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
- NSMutableArray *liveCourse = [NSMutableArray array];
- for (NSDictionary *parm in liveList) {
- HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
- [liveCourse addObject:model];
- }
- self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
-
- NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
- NSMutableArray *videoCourse = [NSMutableArray array];
- for (NSDictionary *parm in videoList) {
- HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
- [videoCourse addObject:model];
- }
- self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
-
- // 最近课程
- NSDictionary *parm = [sourceDic dictionaryValueForKey:@"recentCourses"];
- if (parm == nil) {
- [self refreshCourseView:nil];
- }
- else {
- RecentCourseModel *model = [[RecentCourseModel alloc] initWithDictionary:parm];
- [self refreshCourseView:model];
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self refreshCourseView];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- [self.tableView.mj_header endRefreshing];
- }];
- }
- - (void)refreshCourseView:(RecentCourseModel *)model {
- if (model) {
- self.tipsViewHeight = 80.0f;
- [self.tipsCourseView configWithCourseMessage:model];
- self.tipsCourseView.hidden = NO;
- [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(80.0f);
- }];
- }
- else {
- self.tipsViewHeight = CGFLOAT_MIN;
- self.tipsCourseView.hidden = YES;
- [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- [self refreshTableHeadHeight];
- }
- - (void)refreshCourseView {
- // 课程
- if (self.liveCourseArray.count && self.videoCourseArray.count) {
- self.courseCount = self.liveCourseArray.count >= self.videoCourseArray.count ? self.videoCourseArray.count : self.liveCourseArray.count;
- // 根据课程返回数据显示高度
- self.courseViewHeight = [self.courseView getViewHeightWithCount:self.courseCount];
- }
- else {
- self.courseViewHeight = CGFLOAT_MIN;
- }
- [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.courseViewHeight);
- }];
-
- [self.liveCourseTable reloadData];
- [self.videoCourseTable reloadData];
- [self refreshTableHeadHeight];
- }
- - (void)requestUserInfo:(BOOL)checkSubject {
- self.isFirstLoad = NO;
- [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
- NSString *rongToken = UserDefault(RongTokenKey);
- if ([NSString isEmptyString:rongToken]) {
- [USER_MANAGER queryUserInfoConnectRongCloud:YES];
- }
- [self refreshNavView:checkSubject];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestTeacherStyle {
-
- [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
-
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- NSMutableArray *styleArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm];
- [styleArray addObject:model];
- }
- self.teacherArray = [NSMutableArray arrayWithArray:styleArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- // 回调
- [self refreshTeachView];
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)refreshTeachView {
- if (self.teacherArray.count) {
- self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
- self.teacherView.hidden = NO;
- }
- else {
- self.teachViewHeight = CGFLOAT_MIN;
- self.teacherView.hidden = YES;
- }
- [self.teacherView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.teachViewHeight);
- }];
- [self.infoCollectionView reloadData];
- [self refreshTableHeadHeight];
- }
- - (void)refreshNavView:(BOOL)checkSubject {
- if (checkSubject) {
- if ([NSString isEmptyString:self.mineInfo.subjectName]) {
- [self showInstrumentView:YES];
- }
- else {
- [self requestData];
- }
- }
-
- [self.navView.userAvatal sd_setImageWithURL:[NSURL URLWithString:[self.mineInfo.heardUrl getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- NSString *userName = @"";
- if ([NSString isEmptyString:self.mineInfo.username]) {
- userName = [NSString stringWithFormat:@"游客%@",self.mineInfo.userId];
- }
- else {
- userName = self.mineInfo.username;
- }
- self.navView.userName.text = userName;
- }
- - (void)refreshBannaerView {
- if (self.bannerArray.count > 1) {
- self.bannerScroll.autoScrollInterval = 3.0f;
- [self.bannerScroll addSubview:self.pageControl];
- }
- else {
- self.bannerScroll.autoScrollInterval = 0;
- [self.pageControl removeFromSuperview];
- }
- _pageControl.numberOfPages = self.bannerArray.count;
- [self.bannerScroll reloadData];
- }
- - (void)showButtonMessage {
- // 添加按钮
- if (self.buttonArray.count > 5) { // 大于4个显示底部滚动视图
- self.buttonContainer.buttonPageCtrl.hidden = NO;
- self.buttonContainer.buttonDotLeft.constant = 0;
- NSInteger addPage = (self.buttonArray.count % 5) > 0 ? 1 : 0;
- NSInteger pageCount = self.buttonArray.count / 5 + addPage;
- self.buttonDotWidth = 36 / pageCount;
- self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
- self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
- }
- else {
- self.buttonContainer.buttonPageCtrl.hidden = YES;
- self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
- }
-
- self.buttonScrollView.contentOffset = CGPointMake(0, 0);
- [self.buttonScrollView removeAllSubViews];
- CGFloat buttonSpace = (kScreenWidth - 5 * BUTTONWIDTH) / 6;
- for (NSInteger i = 0; i < self.buttonArray.count; i++) {
- HomeMessageModel *model = self.buttonArray[i];
- KSHomeButton *buttonView = [KSHomeButton shareInstance];
-
- [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
- buttonView.buttonTitle.text = model.title;
- buttonView.frame = CGRectMake(buttonSpace + (i % 5) * (BUTTONWIDTH + buttonSpace) + (i / 5) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
- buttonView.actionButton.tag = 3000 + i;
- [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.buttonScrollView addSubview:buttonView];
- }
- }
- - (void)HomeTopButtonAction:(UIButton *)sender {
- NSInteger index = sender.tag - 3000;
- if ([self checkIsLoginToLoginView:YES]) {
- HomeMessageModel *model = self.buttonArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = model.linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- #pragma mark - TYCyclePagerViewDataSource代理
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.bannerArray.count;
- }
- - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- HomeMessageModel *model = self.bannerArray[index];
- HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
- [cell configCellWithModel:model];
- return cell;
- }
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
- layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
- layout.itemSpacing = 0;
- return layout;
-
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
- if (pageView == self.bannerScroll) {
- [self.pageControl setCurrentPage:toIndex animate:YES];
- }
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
-
- HomeMessageModel *model = self.bannerArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = model.linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- #pragma mark ----- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (tableView == self.tableView) { // 资讯
- return self.dataArray.count;
- }
- else if (tableView == self.liveCourseTable) { // 直播课列表
- return self.courseCount;
- }
- else { // 视频课列表
- return self.courseCount;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (tableView == self.tableView) {
- HomeMessageModel *model = self.dataArray[indexPath.row];
- HomeInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeInformationCell"];
- ROWINDEX rowIndex = ROWINDEX_MIDDLE;
- if (indexPath.row == 0) {
- rowIndex = ROWINDEX_TOP;
- }
- else if (indexPath.row == self.dataArray.count - 1) {
- rowIndex = ROWINDEX_BOTTOM;
- }
- [cell configCellWithSource:model rowIndex:rowIndex];
- return cell;
- }
- else if (tableView == self.liveCourseTable) {
- HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
- HomeLiveCouseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLiveCouseCell"];
- [cell configWithSource:model];
- return cell;
- }
- else {
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
- HomeVideoCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoCourseCell"];
- [cell configWithSource:model];
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (tableView == self.tableView) {
- HomeMessageModel *model = self.dataArray[indexPath.row];
- if (![NSString isEmptyString:model.linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = model.linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- else {
- // 跳转
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@%@",WEBHOST,@"/#/specialdetail?id=",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- else if (tableView == self.liveCourseTable) { // 直播课详情
- HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if (tableView == self.videoCourseTable) { //
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ---- collection data source
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (collectionView == self.albumCollectionView) {
- return self.albumArray.count;
- }
- else { // 老师风采
- return self.teacherArray.count;
- }
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
- [cell configWithAlbumModel:model];
- return cell;
- }
- else {
- TeacherStyleModel *model = self.teacherArray[indexPath.item];
- TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
- MJWeakSelf;
- [showCell configWithStyleModel:model callback:^(NSString *videoUrl) {
- [weakSelf playVideo:videoUrl];
- }];
- return showCell;
- }
- }
- - (void)playVideo:(NSString *)videoUrl {
- if ([NSString isEmptyString:videoUrl]) {
- return;
- }
- // 播放视频
- [self playVideoWithUrl:videoUrl];
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) { // 专辑详情
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else { // 老师风采详情
- TeacherStyleModel *model = self.teacherArray[indexPath.item];
- [self displayTeacherDetail:model.userId];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- return CGSizeMake(110, 140);
- }
- else {
- return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 164);
- }
- }
- // 老师风采
- - (void)displayTeacherDetail:(NSString *)teacherId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- scroll view delegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView == self.buttonScrollView) {
- NSInteger index = (NSInteger)(scrollView.contentOffset.x / kScreenWidth);
-
- [UIView animateWithDuration:0.3f animations:^{
- self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
- }];
- }
- else if (scrollView == self.courseScroll) {
-
- }
- }
-
- #pragma mark ---- lazying
- - (NSMutableArray *)buttonArray {
- if (!_buttonArray) {
- _buttonArray = [NSMutableArray array];
- }
- return _buttonArray;
- }
- - (NSMutableArray *)bannerArray {
- if (!_bannerArray) {
- _bannerArray = [NSMutableArray array];
- }
- return _bannerArray;
- }
- - (NSMutableArray *)albumArray {
- if (!_albumArray) {
- _albumArray = [NSMutableArray array];
- }
- return _albumArray;
- }
- - (NSMutableArray *)liveCourseArray {
- if (!_liveCourseArray) {
- _liveCourseArray = [NSMutableArray array];
- }
- return _liveCourseArray;
- }
- - (NSMutableArray *)videoCourseArray {
- if (!_videoCourseArray) {
- _videoCourseArray = [NSMutableArray array];
- }
- return _videoCourseArray;
- }
- - (NSMutableArray *)teacherArray {
- if (!_teacherArray) {
- _teacherArray = [NSMutableArray array];
- }
- return _teacherArray;
- }
- #pragma mark ----- 最近上课
- - (HomeCourseTipsView *)tipsCourseView {
- if (!_tipsCourseView) {
- _tipsCourseView = [HomeCourseTipsView shareInstance];
- MJWeakSelf;
- [_tipsCourseView joinRoomCallback:^(COURSETYPE type, RecentCourseModel * _Nonnull courseModel) {
- [weakSelf joinRoomAction:type courseMessage:courseModel];
- }];
- }
- return _tipsCourseView;
- }
- - (void)joinRoomAction:(COURSETYPE)type courseMessage:(RecentCourseModel *)courseModel {
- if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
- AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- detailVC.teacherId = courseModel.teacherId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else { // 直播课详情
-
- }
- }
- #pragma mark ----- 专辑
- - (HomeHotAlbumView *)albumView {
- if (!_albumView) {
- _albumView = [HomeHotAlbumView shareInstance];
- MJWeakSelf;
- [_albumView homeAlbumMore:^{
- [weakSelf moreAlbumDetail];
- }];
- [_albumView.albumContentView addSubview:self.albumCollectionView];
- [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
- }];
- }
- return _albumView;
- }
- - (UICollectionView *)albumCollectionView {
- if (!_albumCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _albumCollectionView.backgroundColor = [UIColor clearColor];
- _albumCollectionView.delegate = self;
- _albumCollectionView.dataSource = self;
- _albumCollectionView.showsVerticalScrollIndicator = NO;
- _albumCollectionView.showsHorizontalScrollIndicator = NO;
- [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
- }
- return _albumCollectionView;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ------ 推荐课程
- - (HomeHotCourseView *)courseView {
- if (!_courseView) {
- _courseView = [HomeHotCourseView shareInstance];
- MJWeakSelf;
- [_courseView courseActionCallback:^(COURSE_ACTION action) {
- [weakSelf homeCourseChooseAction:action];
- }];
- [_courseView.courseContainer addSubview:self.courseScroll];
- [self.courseScroll mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_courseView.courseContainer);
- }];
- }
- return _courseView;
- }
- - (UIScrollView *)courseScroll {
- if (!_courseScroll) {
- _courseScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
- _courseScroll.pagingEnabled = YES;
- _courseScroll.scrollEnabled = NO;
- _courseScroll.showsHorizontalScrollIndicator = NO;
- _courseScroll.showsVerticalScrollIndicator = NO;
- _courseScroll.delegate = self;
- }
- return _courseScroll;
- }
- - (UITableView *)liveCourseTable {
- if (!_liveCourseTable) {
- _liveCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _liveCourseTable.delegate = self;
- _liveCourseTable.dataSource = self;
- _liveCourseTable.rowHeight = 126;
- _liveCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
- _liveCourseTable.backgroundColor = [UIColor clearColor];
- _liveCourseTable.showsVerticalScrollIndicator = NO;
- [_liveCourseTable registerNib:[UINib nibWithNibName:@"HomeLiveCouseCell" bundle:nil] forCellReuseIdentifier:@"HomeLiveCouseCell"];
- _liveCourseTable.scrollEnabled = NO;
- }
- return _liveCourseTable;
- }
- - (UITableView *)videoCourseTable {
- if (!_videoCourseTable) {
- _videoCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _videoCourseTable.delegate = self;
- _videoCourseTable.dataSource = self;
- _videoCourseTable.rowHeight = 126;
- _videoCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
- _videoCourseTable.backgroundColor = [UIColor clearColor];
- _videoCourseTable.showsVerticalScrollIndicator = NO;
- [_videoCourseTable registerNib:[UINib nibWithNibName:@"HomeVideoCourseCell" bundle:nil] forCellReuseIdentifier:@"HomeVideoCourseCell"];
- _videoCourseTable.scrollEnabled = NO;
- }
- return _videoCourseTable;
- }
- - (void)homeCourseChooseAction:(COURSE_ACTION)action {
- switch (action) {
- case COURSE_ACTION_LIVE:
- {
- if (self.isChooseLive == YES) {
- return;
- }
- self.isChooseLive = YES;
- }
- break;
- case COURSE_ACTION_VIDEO:
- {
- if (self.isChooseLive == NO) {
- return;
- }
- self.isChooseLive = NO;
- }
- break;
- case COURSE_ACTION_MORE: // 更多
- {
- NSString *url = @"";
- if (self.isChooseLive) { // 直播课 列表
- url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
- }
- else { // 视频课列表
- url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
- }
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (void)setIsChooseLive:(BOOL)isChooseLive {
- _isChooseLive = isChooseLive;
- // 切换
- [UIView animateWithDuration:0.3f animations:^{
- if (isChooseLive) {
- [self.courseScroll setContentOffset:CGPointZero animated:YES];
- }
- else {
- [self.courseScroll setContentOffset:CGPointMake(KPortraitWidth, 0) animated:YES];
- }
- }];
- }
- #pragma mark --- 老师风采
- - (HomeIntroduceView *)teacherView {
- if (!_teacherView) {
- _teacherView = [HomeIntroduceView shareInstance];
- MJWeakSelf;
- [_teacherView introduceMore:^{
- [weakSelf teacherMoreIntorduce];
- }];
- [_teacherView.teacherContainer addSubview:self.infoCollectionView];
- [self.infoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.top.mas_equalTo(_teacherView.teacherContainer);
- make.left.mas_equalTo(_teacherView.mas_left).offset(14);
- make.right.mas_equalTo(_teacherView.mas_right).offset(-14);
- }];
- }
- return _teacherView;
- }
- - (void)teacherMoreIntorduce {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherElegant"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)infoCollectionView {
- if (!_infoCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- _infoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _infoCollectionView.backgroundColor = [UIColor clearColor];
- _infoCollectionView.delegate = self;
- _infoCollectionView.dataSource = self;
- _infoCollectionView.showsVerticalScrollIndicator = NO;
- _infoCollectionView.showsHorizontalScrollIndicator = NO;
- [_infoCollectionView registerNib:[UINib nibWithNibName:@"TeacherShowCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TeacherShowCell"];
- }
- return _infoCollectionView;
- }
- #pragma mark ---- button container
- - (HomeButtonView *)buttonContainer {
- if (!_buttonContainer) {
- _buttonContainer = [HomeButtonView shareInstance];
- [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
- }
- return _buttonContainer;
- }
- - (UIScrollView *)buttonScrollView {
- if (!_buttonScrollView) {
- _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
- _buttonScrollView.backgroundColor = [UIColor clearColor];
- _buttonScrollView.pagingEnabled = YES;
- _buttonScrollView.showsHorizontalScrollIndicator = NO;
- _buttonScrollView.showsVerticalScrollIndicator = NO;
- _buttonScrollView.delegate = self;
- }
- return _buttonScrollView;
- }
- - (UIView *)tableHeaderView {
- if (!_tableHeaderView) {
- _tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableHeaderView.backgroundColor = [UIColor clearColor];
- }
- return _tableHeaderView;
- }
- - (HomeBannerView *)bannerView {
- if (!_bannerView) {
- _bannerView = [HomeBannerView shareInstance];
- [_bannerView.bannerContentView addSubview:self.bannerScroll];
- }
- return _bannerView;
- }
- - (TYCyclePagerView *)bannerScroll {
- if (!_bannerScroll) {
- _bannerScroll = [[TYCyclePagerView alloc] init];
- _bannerScroll.backgroundColor = [UIColor clearColor];
- _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
- _bannerScroll.isInfiniteLoop = YES;
- _bannerScroll.autoScrollInterval = 3.0f;
- _bannerScroll.reloadDataNeedResetIndex = YES;
- _bannerScroll.dataSource = self;
- _bannerScroll.delegate = self;
- [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
- }
- return _bannerScroll;
- }
- #pragma mark ---- 更多资讯
- - (HotInformationHeadView *)informationHeadView {
- if (!_informationHeadView) {
- _informationHeadView = [HotInformationHeadView shareInstance];
-
- MJWeakSelf;
- [_informationHeadView moreInformationCallback:^{
- [weakSelf moreInformation];
- }];
- }
- return _informationHeadView;
- }
- - (void)moreInformation {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/special"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = 108;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.showsVerticalScrollIndicator = NO;
- [_tableView registerNib:[UINib nibWithNibName:@"HomeInformationCell" bundle:nil] forCellReuseIdentifier:@"HomeInformationCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = [UIColor clearColor];
- _tableView.tableFooterView = bottomView;
- }
- return _tableView;
- }
- - (HomeNavView *)navView {
- if (!_navView) {
- _navView = [HomeNavView shareInstance];
- MJWeakSelf;
- [_navView homeNavAction:^(NAVACTION action) {
- [weakSelf navAction:action];
- }];
- }
- return _navView;
- }
- - (void)navAction:(NAVACTION)action {
- if (action == NAVACTION_SUBJECT) {
- [self showInstrumentView:NO];
- }
- else { // 消息中心
- NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (void)showInstrumentView:(BOOL)hideBackButton {
- SubjectChooseViewController *ctrl = [[SubjectChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseSubjectCallback:^{
- [weakSelf requestUserInfo:NO];
- [weakSelf requestData];
- }];
- if (hideBackButton) {
- ctrl.isModalPresent = YES;
- CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
- navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
- }
- else {
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ------ WMPlayer
- - (void)playVideoWithUrl:(NSString *)fileUrl {
- fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
- WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
- playModel.videoURL = [NSURL URLWithString:fileUrl];
- _wmPlayer.playerModel = playModel;
- _wmPlayer.delegate = self;
- _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- _bgView.backgroundColor = [UIColor blackColor];
- [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
- [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
-
- [_wmPlayer play];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
- [wmplayer removePlayer];
- [_bgView removeFromSuperview];
- [self setNeedsStatusBarAppearanceUpdate];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
- self.isRatation = !self.isRatation;
-
- if (self.isRatation) {
- [wmplayer removeFromSuperview];
- [UIView animateWithDuration:1.0f animations:^{
- wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- else {
- [wmplayer removeFromSuperview];
-
- [UIView animateWithDuration:1.0f animations:^{
- // 复原
- wmplayer.transform = CGAffineTransformIdentity;
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
- // 登录之后才弹窗
- if ([self checkIsLoginToLoginView:NO]) {
- NSString *useId = UserDefault(UIDKey);
- NSMutableArray *newArray = UserDefault(useId);
- if (newArray.count) {
- if ([newArray containsObject:sourceModel.coverImage]) {
- return;
- }
- else {
- [self displayAlert:sourceModel];
- }
- }
- else {
- [self displayAlert:sourceModel];
- }
- }
- }
- - (void)displayAlert:(HomeMessageModel *)sourceModel {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.isShowMemoAlert) {
- return;
- }
- NSString *useId = UserDefault(UIDKey);
- UserDefaultRemoveObjectForKey(useId);
- NSMutableArray *sourceArray = [NSMutableArray arrayWithArray:UserDefault(useId)];
- [sourceArray addObject:sourceModel.coverImage];
- UserDefaultSetObjectForKey(sourceArray, useId);
- KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
- MJWeakSelf;
- [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
- appDelegate.isShowFlashAlert = NO;
- if (isSure) {
- if (![NSString isEmptyString:linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [linkUrl getUrlEndcodeString];
- [weakSelf.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
- }];
- [newAlert showAlert];
- appDelegate.isShowFlashAlert = YES;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|