MyVideoCourseBodyView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //
  2. // MyVideoCourseBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/18.
  6. //
  7. #import "MyVideoCourseBodyView.h"
  8. #import "VideoCourseCell.h"
  9. #import "VideoCourseModel.h"
  10. #import "KSBaseWKWebViewController.h"
  11. #import "AuthDisplayView.h"
  12. #import "MyVideoSearchView.h"
  13. #import "NewClassPopView.h"
  14. #import "KSChoosePicker.h"
  15. @interface MyVideoCourseBodyView ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  16. @property (nonatomic, strong) NSMutableArray *dataArray;
  17. @property (nonatomic, strong) StateView *promptView;
  18. @property (nonatomic, strong) UIView *promptPlaceView;
  19. @property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
  20. @property (nonatomic, assign) BOOL isLoadMore;
  21. @property (nonatomic, assign) NSInteger rows;
  22. @property (nonatomic, assign) NSInteger pages;
  23. @property (nonatomic, strong) NSString *audioStatus;
  24. @property (nonatomic, strong) NSString *searchKey;
  25. @property (nonatomic, strong) AuthDisplayView *authView;
  26. @property (nonatomic, copy) MyVideoSearchView *sortView;
  27. @property (nonatomic, strong) NewClassPopView *popView;
  28. @property (nonatomic, assign) BOOL authStatus;
  29. @end
  30. @implementation MyVideoCourseBodyView
  31. - (instancetype)initWithFrame:(CGRect)frame {
  32. self = [super initWithFrame:frame];
  33. if (self) {
  34. self.backgroundColor = HexRGB(0xf6f8f9);
  35. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  36. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  37. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout];
  38. self.collectionView.backgroundColor = HexRGB(0xf6f8f9);
  39. self.collectionView.delegate = self;
  40. self.collectionView.dataSource = self;
  41. self.collectionView.showsVerticalScrollIndicator = NO;
  42. self.collectionView.showsHorizontalScrollIndicator = NO;
  43. [self.collectionView registerNib:[UINib nibWithNibName:@"VideoCourseCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"VideoCourseCell"];
  44. [self addSubview:self.collectionView];
  45. MJWeakSelf;
  46. self.collectionView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  47. [weakSelf resetParamenter];
  48. [weakSelf requestData];
  49. }];
  50. self.collectionView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
  51. if (weakSelf.isLoadMore) {
  52. weakSelf.pages += 1;
  53. [weakSelf requestData];
  54. }
  55. else {
  56. [weakSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
  57. }
  58. }];
  59. }
  60. return self;
  61. }
  62. - (void)endRefresh {
  63. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  64. [self.collectionView.mj_header endRefreshing];
  65. [self.collectionView.mj_footer endRefreshing];
  66. });
  67. }
  68. - (void)refreshAndRequestData {
  69. [self resetParamenter];
  70. [self requestData];
  71. }
  72. - (void)resetParamenter {
  73. self.isLoadMore = YES;
  74. self.pages = 1;
  75. self.rows = 10;
  76. self.audioStatus = @"PASS";
  77. self.dataArray = [NSMutableArray array];
  78. [self.collectionView.mj_footer resetNoMoreData];
  79. [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.collectionView];
  80. [self.collectionView reloadData];
  81. }
  82. - (void)requestData {
  83. [KSNetworkingManager videoLessonListRequest:KS_POST lessonSubject:self.searchKey auditStatus:self.audioStatus pageNo:self.pages pageSize:self.rows success:^(NSDictionary * _Nonnull dic) {
  84. [self endRefresh];
  85. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  86. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  87. for (NSDictionary *parm in sourceArray) {
  88. VideoCourseModel *model = [[VideoCourseModel alloc] initWithDictionary:parm];
  89. [self.dataArray addObject:model];
  90. }
  91. if (sourceArray.count < self.rows) {
  92. self.isLoadMore = NO;
  93. }
  94. }
  95. else {
  96. [self MBPShow:MESSAGEKEY];
  97. }
  98. [self.collectionView reloadData];
  99. [self changePromptLabelStateWithArray:self.dataArray];
  100. } faliure:^(NSError * _Nonnull error) {
  101. [self endRefresh];
  102. if (self.networkAvaiable == NO) {
  103. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.collectionView];
  104. }
  105. [self.dataArray removeAllObjects];
  106. [self.collectionView reloadData];
  107. [self changePromptLabelStateWithArray:self.dataArray];
  108. }];
  109. }
  110. - (void)beginRefreshImmediately {
  111. [self.collectionView.mj_header beginRefreshing];
  112. }
  113. - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
  114. if (self.lastSelectedIndexPath == indexPath) {
  115. return;
  116. }
  117. if (self.lastSelectedIndexPath != nil) {
  118. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:self.lastSelectedIndexPath];
  119. [cell setSelected:NO];
  120. }
  121. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
  122. [cell setSelected:YES];
  123. self.lastSelectedIndexPath = indexPath;
  124. }
  125. - (void)layoutSubviews {
  126. [super layoutSubviews];
  127. CGFloat topHeight = 55.0f;
  128. self.collectionView.frame = CGRectMake(0, topHeight, self.bounds.size.width, self.bounds.size.height - topHeight);
  129. if (!_sortView) {
  130. _sortView = [MyVideoSearchView shareInstance];
  131. _sortView.frame = CGRectMake(0, 0, kScreenWidth, 55);
  132. MJWeakSelf;
  133. [_sortView sortAction:^{
  134. [weakSelf showSortView];
  135. }];
  136. [self addSubview:self.sortView];
  137. }
  138. if (self.authStatus == NO) {
  139. [self showAuthView];
  140. }
  141. else {
  142. [self hideAuthView];
  143. }
  144. }
  145. - (void)showSortView {
  146. if (self.subjectList.count) {
  147. NSMutableArray *nameArray = [NSMutableArray array];
  148. [nameArray addObject:@"全部"];
  149. for (NSDictionary *parm in self.subjectList) {
  150. [nameArray addObject:[parm stringValueForKey:@"subjectName"]];
  151. }
  152. MJWeakSelf;
  153. KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"声部筛选" sourceData:nameArray chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
  154. if (chooseIndex == 0) {
  155. weakSelf.sortView.sortTitleLabel.text = @"全部声部";
  156. weakSelf.searchKey = @"";
  157. }
  158. else {
  159. weakSelf.sortView.sortTitleLabel.text = returnValue;
  160. NSDictionary *parm = self.subjectList[chooseIndex-1];
  161. weakSelf.searchKey = [parm stringValueForKey:@"subjectId"];
  162. }
  163. self.sortView.arrowUp = NO;
  164. [weakSelf refreshAndRequestData];
  165. } cancel:^{
  166. self.sortView.arrowUp = NO;
  167. }];
  168. [picker showPicker];
  169. }
  170. else {
  171. [self MBPShow:@"无声部信息"];
  172. self.sortView.arrowUp = NO;
  173. }
  174. }
  175. - (void)beginFirstRefresh {
  176. if (!self.isHeaderRefreshed) {
  177. [self beginRefreshImmediately];
  178. }
  179. }
  180. #pragma mark ----- collection view
  181. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  182. return 1;
  183. }
  184. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  185. return self.dataArray.count;
  186. }
  187. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  188. VideoCourseCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCourseCell" forIndexPath:indexPath];
  189. VideoCourseModel *model = [self.dataArray objectAtIndex:indexPath.row];
  190. BOOL isCheck = self.selectIndex != 0;
  191. [cell configSourceModel:model isInCheck:isCheck];
  192. return cell;
  193. }
  194. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  195. VideoCourseModel *model = [self.dataArray objectAtIndex:indexPath.row];
  196. NSString *url = [NSString stringWithFormat:@"%@%@%.0f", WEBHOST, @"/#/videoDetail?groupId=",model.internalBaseClassIdentifier];
  197. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  198. ctrl.url = url;
  199. [self.naviController pushViewController:ctrl animated:YES];
  200. }
  201. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  202. return CGSizeMake((kScreenWidth - 28 - 11) / 2.0f, 200);
  203. }
  204. /**
  205. 设置没有数据时的显示
  206. @param promptString 提示语
  207. @param imgName 图片名称
  208. @param view 显示在什么地方
  209. */
  210. - (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
  211. if (self.promptView != nil) {
  212. [self.promptView removeFromSuperview];
  213. }
  214. else {
  215. self.promptView = [[StateView alloc]init];
  216. self.promptView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 300);
  217. }
  218. _promptPlaceView = view;
  219. //当请求不到数据时 ,自定义提示view 将会出现;
  220. self.promptView.imageName = imgName;
  221. self.promptView.alpha = 0.0f;
  222. [self.promptView setText:promptString];
  223. [view addSubview:self.promptView];
  224. }
  225. // 结束刷新后调用方法
  226. - (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
  227. NSInteger count;
  228. if (array.count) {
  229. count = array.count;
  230. } else {
  231. count = 0;
  232. }
  233. [UIView animateWithDuration:0.1 animations:^{
  234. [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
  235. }] ;
  236. }
  237. - (BOOL)networkAvaiable {
  238. return [self checkNetworkAvaiable];
  239. }
  240. - (BOOL)checkNetworkAvaiable {
  241. BOOL isExistenceNetwork = YES;
  242. Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
  243. switch ([reach currentReachabilityStatus]) {
  244. case NotReachable:
  245. isExistenceNetwork = NO;
  246. //NSLog(@"notReachable");
  247. break;
  248. case ReachableViaWiFi:
  249. isExistenceNetwork = YES;
  250. //NSLog(@"WIFI");
  251. break;
  252. case ReachableViaWWAN:
  253. isExistenceNetwork = YES;
  254. //NSLog(@"3G");
  255. break;
  256. }
  257. return isExistenceNetwork;
  258. }
  259. - (NSMutableArray *)dataArray {
  260. if (!_dataArray) {
  261. _dataArray = [NSMutableArray array];
  262. }
  263. return _dataArray;
  264. }
  265. - (void)setTeaherStatus:(NSString *)teaherStatus {
  266. _teaherStatus = teaherStatus;
  267. if ([teaherStatus isEqualToString:@"PASS"]) {
  268. self.authStatus = YES;
  269. }
  270. else {
  271. self.authStatus = NO;
  272. }
  273. if (self.authStatus == NO) {
  274. [self showAuthView];
  275. }
  276. else {
  277. [self hideAuthView];
  278. }
  279. }
  280. - (void)configAuthDisplay {
  281. [self.authView configDisplayMessage:[self getAuthDisplayMessage]];
  282. if ([self.teaherStatus isEqualToString:@"DOING"]) {
  283. self.authView.sureButton.userInteractionEnabled = NO;
  284. self.authView.sureButton.hidden = YES;
  285. }
  286. else {
  287. self.authView.sureButton.userInteractionEnabled = YES;
  288. self.authView.sureButton.hidden = NO;
  289. }
  290. }
  291. - (void)showAuthView {
  292. [self configAuthDisplay];
  293. if ([self.subviews containsObject:self.authView]) {
  294. [self bringSubviewToFront:self.authView];
  295. }
  296. else {
  297. [self addSubview:self.authView];
  298. [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
  299. make.left.top.bottom.right.mas_equalTo(self);
  300. }];
  301. }
  302. }
  303. - (void)hideAuthView {
  304. if ([self.subviews containsObject:self.authView]) {
  305. [self.authView removeFromSuperview];
  306. self.authView = nil;
  307. }
  308. }
  309. - (AuthDisplayView *)authView {
  310. if (!_authView) {
  311. _authView = [AuthDisplayView shareInstance];
  312. [_authView.imageView setImage:[UIImage imageNamed:[self getAuthDisplayImage]]];
  313. [_authView configDisplayMessage:[self getAuthDisplayMessage]];
  314. MJWeakSelf;
  315. [_authView sureCallback:^{
  316. [weakSelf authAction];
  317. }];
  318. }
  319. return _authView;
  320. }
  321. - (NSString *)getAuthDisplayImage {
  322. return @"authTeacher_accompany";
  323. }
  324. - (NSString *)getAuthDisplayMessage {
  325. if ([self.teaherStatus isEqualToString:@"DOING"]) {
  326. return @"您已提交认证申请,请耐心等待审核结果~";
  327. }
  328. else {
  329. return @"您还没有完成老师认证,认证后才可创建直播课哦~";
  330. }
  331. }
  332. - (void)authAction {
  333. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  334. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  335. [self.naviController pushViewController:webCtrl animated:YES];
  336. }
  337. /*
  338. // Only override drawRect: if you perform custom drawing.
  339. // An empty implementation adversely affects performance during animation.
  340. - (void)drawRect:(CGRect)rect {
  341. // Drawing code
  342. }
  343. */
  344. @end