|
@@ -6,13 +6,440 @@
|
|
|
//
|
|
|
|
|
|
#import "MinePageLiveCourseView.h"
|
|
|
+#import "MinePageCourseTipsView.h"
|
|
|
+#import "MineCourseSettingView.h"
|
|
|
+#import "MineLiveCourseGroupCell.h"
|
|
|
+#import "LiveCourseModel.h"
|
|
|
+#import "StateView.h"
|
|
|
+#import "Reachability.h"
|
|
|
+#import "KSBaseWKWebViewController.h"
|
|
|
+#import "AuthDisplayView.h"
|
|
|
|
|
|
-@interface MinePageLiveCourseView ()
|
|
|
+
|
|
|
+@interface MinePageLiveCourseView ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
|
+@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) StateView *promptView;
|
|
|
+@property (nonatomic, strong) UIView *promptPlaceView;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isLoadMore;
|
|
|
+@property (nonatomic, assign) NSInteger rows;
|
|
|
+@property (nonatomic, assign) NSInteger pages;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIView *headView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) MinePageCourseTipsView *tipsView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) MineCourseSettingView *settingView;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL hideTips; // 是否隐藏提示
|
|
|
+
|
|
|
+@property (nonatomic, strong) AuthDisplayView *authView;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation MinePageLiveCourseView
|
|
|
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+ self.backgroundColor = HexRGB(0xf8f9fc);
|
|
|
+ UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
+ layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
|
|
|
+
|
|
|
+ self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout];
|
|
|
+ self.collectionView.backgroundColor = HexRGB(0xf8f9fc);
|
|
|
+ self.collectionView.delegate = self;
|
|
|
+ self.collectionView.dataSource = self;
|
|
|
+ self.collectionView.showsVerticalScrollIndicator = NO;
|
|
|
+ self.collectionView.showsHorizontalScrollIndicator = NO;
|
|
|
+ [self.collectionView registerNib:[UINib nibWithNibName:@"MineLiveCourseGroupCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"MineLiveCourseGroupCell"];
|
|
|
+ [self addSubview:self.collectionView];
|
|
|
+ self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
+ MJWeakSelf;
|
|
|
+ self.collectionView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
|
|
|
+ [weakSelf resetParamenter];
|
|
|
+ [weakSelf requestData];
|
|
|
+ }];
|
|
|
+ self.collectionView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
|
|
|
+ if (weakSelf.isLoadMore) {
|
|
|
+ weakSelf.pages += 1;
|
|
|
+ [weakSelf requestData];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)endRefresh {
|
|
|
+ @weakObj(self);
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ @strongObj(self);
|
|
|
+ [self.collectionView.mj_header endRefreshing];
|
|
|
+ [self.collectionView.mj_footer endRefreshing];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)refreshAndRequestData {
|
|
|
+ [self resetParamenter];
|
|
|
+ [self requestData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetParamenter {
|
|
|
+ self.isLoadMore = YES;
|
|
|
+ self.pages = 1;
|
|
|
+ self.rows = 10;
|
|
|
+ self.dataArray = [NSMutableArray array];
|
|
|
+ [self.collectionView.mj_footer resetNoMoreData];
|
|
|
+ [self setPromptString:@"暂无内容" imageName:@"empty_course" inView:self.collectionView];
|
|
|
+ [self.collectionView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestData {
|
|
|
+ [KSNetworkingManager LiveCourseGroupRequest:KS_POST groupStatus:@"APPLY" page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self endRefresh];
|
|
|
+ if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
+ NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
|
|
|
+ for (NSDictionary *parm in sourceArray) {
|
|
|
+ LiveCourseModel *model = [[LiveCourseModel alloc] initWithDictionary:parm];
|
|
|
+ [self.dataArray addObject:model];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sourceArray.count < self.rows) {
|
|
|
+ self.isLoadMore = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ [self.collectionView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self endRefresh];
|
|
|
+ if (self.networkAvaiable == NO) {
|
|
|
+ [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.collectionView];
|
|
|
+ }
|
|
|
+ [self.dataArray removeAllObjects];
|
|
|
+ [self.collectionView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginRefreshImmediately {
|
|
|
+ [self.collectionView.mj_header beginRefreshing];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ if (self.lastSelectedIndexPath == indexPath) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (self.lastSelectedIndexPath != nil) {
|
|
|
+ UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:self.lastSelectedIndexPath];
|
|
|
+ [cell setSelected:NO];
|
|
|
+ }
|
|
|
+ UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
|
|
|
+ [cell setSelected:YES];
|
|
|
+ self.lastSelectedIndexPath = indexPath;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)layoutSubviews {
|
|
|
+ [super layoutSubviews];
|
|
|
+ CGFloat tipsHeight = [self.tipsView getViewHeight];
|
|
|
+ CGFloat settingHeight = [MineCourseSettingView getViewHeight];
|
|
|
+ CGFloat headHeight = 0.0f;
|
|
|
+ if (self.hideTips) {
|
|
|
+ headHeight = settingHeight + 12;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ headHeight = tipsHeight + settingHeight + 12;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (![self.subviews containsObject:self.headView]) {
|
|
|
+ [self addSubview:self.headView];
|
|
|
+ [self evaluateHeadView];
|
|
|
+ [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.top.mas_equalTo(self);
|
|
|
+ make.height.mas_equalTo(headHeight);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self.headView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(headHeight);
|
|
|
+ }];
|
|
|
+ if (self.hideTips) {
|
|
|
+ self.tipsView.hidden = YES;
|
|
|
+ [self.tipsView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(0);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.tipsView.hidden = NO;
|
|
|
+ [self.tipsView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(tipsHeight);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.bottom.mas_equalTo(self);
|
|
|
+ make.top.mas_equalTo(self.headView.mas_bottom);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)evaluateHeadView {
|
|
|
+
|
|
|
+ CGFloat tipsHeight = 0.0f;
|
|
|
+ if (self.hideTips == NO) {
|
|
|
+ tipsHeight = [self.tipsView getViewHeight];
|
|
|
+ }
|
|
|
+ CGFloat settingHeight = [MineCourseSettingView getViewHeight];
|
|
|
+ [self.headView addSubview:self.tipsView];
|
|
|
+ [self.tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.top.mas_equalTo(self.headView);
|
|
|
+ make.height.mas_equalTo(tipsHeight);
|
|
|
+ }];
|
|
|
+ [self.headView addSubview:self.settingView];
|
|
|
+ [self.settingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.mas_equalTo(self.headView);
|
|
|
+ make.bottom.mas_equalTo(self.headView.mas_bottom).offset(-12);
|
|
|
+ make.height.mas_equalTo(settingHeight);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginFirstRefresh {
|
|
|
+ if (!self.isHeaderRefreshed) {
|
|
|
+ [self beginRefreshImmediately];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark ----- collection view
|
|
|
+- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ MineLiveCourseGroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MineLiveCourseGroupCell" forIndexPath:indexPath];
|
|
|
+
|
|
|
+ LiveCourseModel *model = [self.dataArray objectAtIndex:indexPath.row];
|
|
|
+ [cell configCellWithSource:model groupStatus:COURSERSTATUS_APPLY hideStatusView:YES];
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ LiveCourseModel *model = self.dataArray[indexPath.row];
|
|
|
+ KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
|
|
|
+ NSString *url = [NSString stringWithFormat:@"%@%@%.0f", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
|
|
|
+ ctrl.url = url;
|
|
|
+ [self.naviController pushViewController:ctrl animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ CGFloat width = KPortraitWidth - 28;
|
|
|
+ if (IS_IPAD) {
|
|
|
+ width = (KPortraitWidth - 28 - 12 * 2 - 12) / 2.0f;
|
|
|
+ }
|
|
|
+ CGFloat height = (width - 12 * 2) / 16 * 9 + 143;
|
|
|
+ return CGSizeMake(width, height);
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark ----- lazying
|
|
|
+
|
|
|
+- (UIView *)headView {
|
|
|
+ if (!_headView) {
|
|
|
+ _headView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
+ _headView.backgroundColor = [UIColor clearColor];
|
|
|
+ }
|
|
|
+ return _headView;
|
|
|
+}
|
|
|
+
|
|
|
+- (AuthDisplayView *)authView {
|
|
|
+ if (!_authView) {
|
|
|
+ _authView = [AuthDisplayView shareInstance];
|
|
|
+ [_authView.imageView setImage:[UIImage imageNamed:[self getAuthDisplayImage]]];
|
|
|
+ MJWeakSelf;
|
|
|
+ [_authView sureCallback:^{
|
|
|
+ [weakSelf authAction];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _authView;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSString *)getAuthDisplayImage {
|
|
|
+ return @"authTeacher_Live";
|
|
|
+}
|
|
|
+
|
|
|
+- (MinePageCourseTipsView *)tipsView {
|
|
|
+ if (!_tipsView) {
|
|
|
+ _tipsView = [MinePageCourseTipsView shareIntance];
|
|
|
+ MJWeakSelf;
|
|
|
+ [_tipsView configWithTypeImage:@"minePage_course_introduce" headTitle:@"什么是直播课?" descMsg:@"直播课是老师根据教学目的精心编排的课程,按照固定时间进行直播授课。您可根据老师开放的课程内容,选择自己感兴趣的课程进行学习。如果您错过了直播,也不必担心,可以随时观看直播回放。" callback:^(COURSE_TIPS_ACTION action) {
|
|
|
+ [weakSelf courseTipsAction:action];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _tipsView;
|
|
|
+}
|
|
|
+
|
|
|
+- (MineCourseSettingView *)settingView {
|
|
|
+ if (!_settingView) {
|
|
|
+ _settingView = [MineCourseSettingView shareInstance];
|
|
|
+ MJWeakSelf;
|
|
|
+ [_settingView configWithCourseType:COURSE_TYPE_LIVE callback:^{
|
|
|
+ [weakSelf settingCourseAction];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _settingView;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)settingCourseAction {
|
|
|
+ // 设置
|
|
|
+ KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
|
|
|
+ webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveCreate"];
|
|
|
+ [self.naviController pushViewController:webCtrl animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)courseTipsAction:(COURSE_TIPS_ACTION)action {
|
|
|
+ switch (action) {
|
|
|
+ case COURSE_TIPS_ACTION_REMOVE:
|
|
|
+ {
|
|
|
+ self.hideTips = YES;
|
|
|
+ [self setNeedsLayout];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case COURSE_TIPS_ACTION_STOPREMIND:
|
|
|
+ {
|
|
|
+ self.hideTips = YES;
|
|
|
+ [self setNeedsLayout];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ 设置没有数据时的显示
|
|
|
+
|
|
|
+ @param promptString 提示语
|
|
|
+ @param imgName 图片名称
|
|
|
+ @param view 显示在什么地方
|
|
|
+ */
|
|
|
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
|
|
|
+ if (self.promptView != nil) {
|
|
|
+ [self.promptView removeFromSuperview];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.promptView = [[StateView alloc]init];
|
|
|
+ self.promptView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - 300);
|
|
|
+ }
|
|
|
+ _promptPlaceView = view;
|
|
|
+ //当请求不到数据时 ,自定义提示view 将会出现;
|
|
|
+ self.promptView.imageName = imgName;
|
|
|
+ self.promptView.alpha = 0.0f;
|
|
|
+ [self.promptView setText:promptString];
|
|
|
+ [view addSubview:self.promptView];
|
|
|
+}
|
|
|
+
|
|
|
+// 结束刷新后调用方法
|
|
|
+- (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
|
|
|
+ NSInteger count;
|
|
|
+ if (array.count) {
|
|
|
+ count = array.count;
|
|
|
+ } else {
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.1 animations:^{
|
|
|
+ [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
|
|
|
+ }] ;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)networkAvaiable {
|
|
|
+ return [self checkNetworkAvaiable];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)checkNetworkAvaiable {
|
|
|
+ BOOL isExistenceNetwork = YES;
|
|
|
+ Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
|
|
|
+ switch ([reach currentReachabilityStatus]) {
|
|
|
+ case NotReachable:
|
|
|
+ isExistenceNetwork = NO;
|
|
|
+ //NSLog(@"notReachable");
|
|
|
+ break;
|
|
|
+ case ReachableViaWiFi:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"WIFI");
|
|
|
+ break;
|
|
|
+ case ReachableViaWWAN:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"3G");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return isExistenceNetwork;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setLiveFlag:(BOOL)liveFlag {
|
|
|
+ _liveFlag = liveFlag;
|
|
|
+ if (liveFlag == NO) {
|
|
|
+ [self showAuthView];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self hideAuthView];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showAuthView {
|
|
|
+ [self configAuthDisplay];
|
|
|
+ if ([self.subviews containsObject:self.authView]) {
|
|
|
+ [self bringSubviewToFront:self.authView];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self addSubview:self.authView];
|
|
|
+ [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.top.bottom.right.mas_equalTo(self);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)hideAuthView {
|
|
|
+ if ([self.subviews containsObject:self.authView]) {
|
|
|
+ [self.authView removeFromSuperview];
|
|
|
+ self.authView = nil;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configAuthDisplay {
|
|
|
+ [self.authView configDisplayMessage:[self getAuthDisplayMessage]];
|
|
|
+ if (self.liveFlag == NO) {
|
|
|
+ [self.authView.sureButton setTitle:@"立即开通" forState:UIControlStateNormal];
|
|
|
+ self.authView.sureButton.userInteractionEnabled = YES;
|
|
|
+ self.authView.sureButton.hidden = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (NSString *)getAuthDisplayMessage {
|
|
|
+ if (self.liveFlag == NO) { // 如果达人认证通过
|
|
|
+ return @"您尚未开通直播服务,开通后即可创建直播课程~";
|
|
|
+ }
|
|
|
+ return @"";
|
|
|
+}
|
|
|
+
|
|
|
+// 开通直播
|
|
|
+- (void)authAction {
|
|
|
+ KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
|
|
|
+ webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/openLive"];
|
|
|
+ [self.naviController pushViewController:webCtrl animated:YES];
|
|
|
+}
|
|
|
/*
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
// An empty implementation adversely affects performance during animation.
|