123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // IndexSubVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/9/17.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "IndexSubVC.h"
- #import "HomeWeiCousreCell.h"
- #import "BookSubArticeCell.h"
- #import "HomeTeacherCell.h"
- #import "HomeMusicCell.h"
- #import "HomeSchoolCell.h"
- #import "IndexGoodBookCell.h"
- #import "HomeSubItemModel.h"
- #import "BookTeacherDetailVC.h"
- #import "BookWCDetailVC.h"
- #import "BookListenVC.h"
- #import "BookListDetailVC.h"
- @interface IndexSubVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView * tableView;
- @property (nonatomic, strong) NSMutableArray * dataArray;
- @property (nonatomic, assign) NSInteger currentPage;
- @property (nonatomic, assign) NSInteger Total;
- @end
- @implementation IndexSubVC
- - (NSMutableArray *)dataArray
- {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = UIColorHex(0xF8F8F8);
- [self.view addSubview:self.tableView];
- self.tableView.showsVerticalScrollIndicator = NO;
- self.tableView.backgroundColor = [UIColor clearColor];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.layer.cornerRadius = 8.f;
- self.tableView.layer.masksToBounds = YES;
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_offset(UIEdgeInsetsMake(20,15,(IS_IPHONEX ? 40 : 20) + EMVIEWBOTTOMMARGIN + 50,15));
- }];
- WS(weakSelf);
- self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
- }
- - (void)footerRefresh
- {
- self.currentPage += 1;
- if (self.dataArray.count == self.Total) {
- self.tableView.mj_footer.hidden = YES;
- [self.tableView.mj_footer resetNoMoreData];
- return;
- }
- [self getDataNetWork];
- }
- - (void)getDataNetWork
- {
- WS(weakSelf);
- SHOWLOADING
- NSDictionary * paraDict = @{@"MediaType":@(self.type),
- @"Page":@(self.currentPage),
- @"PerPage":@(10),
- @"KeyWord":self.searchText
- };
- [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_Media_Search) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
- [weakSelf.dataArray addObject:model];
- }
- }
- weakSelf.Total = [responseObject[@"Total"] integerValue];
- [weakSelf.tableView.mj_footer endRefreshing];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }
- - (void)getData
- {
- [self.dataArray removeAllObjects];
- self.currentPage = 1;
- self.Total = 0;
- [self getDataNetWork];
- }
- - (UITableView *)tableView
- {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- }
- return _tableView;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return self.dataArray.count == 0 ? 0.01f : 15.f;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return self.dataArray.count == 0 ? 0.01f : 15.f;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.dataArray.count == 0 ? 0.01f : 15.f)];
- // view.backgroundColor = UIColorHex(0xFFFFFF);
- // return view;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.dataArray.count == 0 ? 0.01f : 15.f)];
- // view.backgroundColor = UIColorHex(0xFFFFFF);
- // return view;
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
- switch ((CollectModelType)model.MediaType) {
- case CollectModel_StoreBook:
- {
- IndexGoodBookCell * cell = [IndexGoodBookCell configCell0:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- case CollectModel_StoreVideo:
- {
- HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
- [cell setDataWithIndexModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- case CollectModel_StoreSound:
- {
- HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- case CollectModel_Teacher:
- {
- HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- case CollectModel_Organization:
- {
- HomeSchoolCell * cell = [HomeSchoolCell configCell1:tableView indexPath:indexPath];
- [cell setDataIndexModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- default:
- {
- IndexGoodBookCell * cell = [IndexGoodBookCell configCell1:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:self.searchText];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:YES];
- }else{
- cell.lineV.hidden = NO;
- [self setupRoundedCornersWithView:cell cutCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight isMask:NO];
- }
- return cell;
- }
- break;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- switch ((CollectModelType)model.MediaType) {
- case CollectModel_StoreBook:
- {
- BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_StoreVideo:
- {
- BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_StoreSound:
- {
- BookListenVC * vc = [BookListenVC initBookListenVC];
- vc.Id = model.Id;
- vc.MediaType = MediaMusicType;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_Teacher:
- {
- BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_Organization:
- {
- }
- break;
- default:
- {
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = (CollectModelType)model.MediaType;
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- }
- }
- - (void)setupRoundedCornersWithView:(UITableViewCell *)cell cutCorners:(UIRectCorner)rectCorner isMask:(BOOL)isMask{
- CAShapeLayer *mask = [CAShapeLayer layer];
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 30, cell.bounds.size.height) byRoundingCorners:rectCorner cornerRadii:CGSizeMake(isMask ? 8 : 0, isMask ? 8 : 0)];
- mask.path = path.CGPath;
- mask.frame = cell.bounds;
- CAShapeLayer *borderLayer = [CAShapeLayer layer];
- borderLayer.path = path.CGPath;
- borderLayer.fillColor = [UIColor clearColor].CGColor;
- borderLayer.strokeColor = [UIColor whiteColor].CGColor;
- borderLayer.lineWidth = 0;
- borderLayer.frame = cell.bounds;
- cell.layer.mask = mask;
- [cell.layer addSublayer:borderLayer];
- }
- @end
|