CommonHomeVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. //
  2. // CommonHomeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/4/28.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "CommonHomeVC.h"
  9. #import "CommonListCell.h"
  10. #import "MyTDGroupView.h"
  11. #import "GHRefreshCollectionView.h"
  12. #import "CommonBarCell.h"
  13. #import "CommonBarModel.h"
  14. #import "CommonWorkVC.h"
  15. #import "CommonToolVC.h"
  16. #import "MyFavoriteVC.h"
  17. #import "CommonNoteVC.h"
  18. #import "ChatMsgListCell.h"
  19. #import "ChatMsgCollectionCell.h"
  20. @interface CommonHomeVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
  21. @property (weak, nonatomic) IBOutlet UIView *NavBar;
  22. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  23. @property (strong, nonatomic) UITableView *tableView;
  24. @property (strong, nonatomic) MyTDGroupView *SearchView;
  25. @property (strong, nonatomic) GHRefreshCollectionView *collectionView;
  26. @property (strong, nonatomic) NSMutableArray *collectionDataSource;
  27. @property (strong, nonatomic) NSMutableArray *dataArray;
  28. @end
  29. @implementation CommonHomeVC
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.fd_prefersNavigationBarHidden = YES;
  33. self.view.backgroundColor = UIColorHex(0xffffff);
  34. if (@available(iOS 11.0, *)) {
  35. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  36. } else {
  37. self.automaticallyAdjustsScrollViewInsets = NO;
  38. }
  39. [self.HeadView addSubview:self.SearchView];
  40. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.top.right.mas_equalTo(self.HeadView);
  42. make.height.mas_offset(36);
  43. }];
  44. [self.view addSubview:self.tableView];
  45. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.right.mas_equalTo(self.view);
  47. make.top.mas_equalTo(self.HeadView.mas_bottom);
  48. if (@available(iOS 11.0, *)) {
  49. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  50. } else {
  51. make.bottom.equalTo(self.view.mas_bottom);
  52. }
  53. }];
  54. [self setBarData];
  55. [self.SearchView.button setAction:^{
  56. NSLog(@"点击搜索");
  57. }];
  58. self.tableView.delegate = self;
  59. self.tableView.dataSource = self;
  60. self.tableView.backgroundColor = [UIColor clearColor];
  61. CommonListModel * model = [[CommonListModel alloc] init];
  62. model.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  63. model.Name = @"钱颖一";
  64. model.Des = @"中国前沿计算机教育观察周刊";
  65. [self.dataArray addObject:model];
  66. [self.dataArray addObject:model];
  67. [self.dataArray addObject:model];
  68. [self.dataArray addObject:model];
  69. [self.dataArray addObject:model];
  70. CommonListModel * amodel = [[CommonListModel alloc] init];
  71. amodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  72. amodel.Name = @"钱颖一";
  73. amodel.Des = @"中国前沿计算机教育观察周刊";
  74. [self.dataArray addObject:amodel];
  75. CommonListModel * bmodel = [[CommonListModel alloc] init];
  76. bmodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  77. bmodel.Name = @"钱颖一";
  78. bmodel.Des = @"中国前沿计算机教育观察周刊";
  79. [self.dataArray addObject:bmodel];
  80. CommonListModel * cmodel = [[CommonListModel alloc] init];
  81. cmodel.Title = @"大脑不擅长思考,那我们应该怎么学习?";
  82. cmodel.Name = @"周明鑫";
  83. cmodel.Des = @"北国教育论坛";
  84. [self.dataArray addObject:cmodel];
  85. [self.tableView reloadData];
  86. }
  87. - (BOOL)hidesBottomBarWhenPushed{
  88. return NO;
  89. }
  90. #pragma mark - UITableViewDelegate
  91. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  92. return 2;
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  95. switch (section) {
  96. case 0:{
  97. return 1;
  98. }break;
  99. default:{
  100. return self.dataArray.count;
  101. }break;
  102. }
  103. }
  104. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  105. switch (indexPath.section) {
  106. case 0:{
  107. return 74.f;
  108. }break;
  109. default:{
  110. return UITableViewAutomaticDimension;
  111. }break;
  112. }
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  115. {
  116. switch (section) {
  117. case 0:{
  118. return 0.f;
  119. }break;
  120. default:{
  121. return 36.f;
  122. }break;
  123. }
  124. }
  125. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  126. {
  127. switch (section) {
  128. case 0:{
  129. UIView * view = [UIView new];
  130. return view;
  131. }break;
  132. default:{
  133. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  134. view.backgroundColor = UIColorHex(0xF5F5F5);
  135. UILabel * label = [UILabel new];
  136. label.font = [UIFont systemFontOfSize:15];
  137. label.textColor = UIColorHex(0x666666);
  138. label.text = @"最新收藏";
  139. [view addSubview:label];
  140. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.left.mas_offset(15);
  142. make.centerY.mas_equalTo(view);
  143. }];
  144. return view;
  145. }break;
  146. }
  147. }
  148. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  149. switch (indexPath.section) {
  150. case 0:
  151. {
  152. ChatMsgListCell *cell = [ChatMsgListCell configCell1:tableView indexPath:indexPath];
  153. [cell.cell1ContentBgView addSubview:self.collectionView];
  154. self.collectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, cell.cell1ContentBgView.height);
  155. [self.collectionView reloadData];
  156. return cell;
  157. }
  158. break;
  159. default:
  160. {
  161. CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath];
  162. CommonListModel * model = [self.dataArray objectAtIndex:indexPath.row];
  163. [cell setCell1Data:model];
  164. return cell;
  165. }
  166. break;
  167. }
  168. }
  169. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  170. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  171. }
  172. #pragma mark - load
  173. - (UITableView *)tableView
  174. {
  175. if (!_tableView) {
  176. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  177. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  178. }
  179. return _tableView;
  180. }
  181. - (MyTDGroupView *)SearchView
  182. {
  183. if (!_SearchView) {
  184. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  185. }
  186. return _SearchView;
  187. }
  188. -(NSMutableArray *)dataArray{
  189. if(!_dataArray){
  190. _dataArray = [[NSMutableArray alloc] init];
  191. }
  192. return _dataArray;
  193. }
  194. -(NSMutableArray *)collectionDataSource{
  195. if(!_collectionDataSource){
  196. _collectionDataSource = [[NSMutableArray alloc] init];
  197. }
  198. return _collectionDataSource;
  199. }
  200. - (GHRefreshCollectionView *)collectionView {
  201. if (!_collectionView) {
  202. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  203. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  204. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  205. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  206. _collectionView.delegate = self;
  207. _collectionView.dataSource = self;
  208. _collectionView.showsHorizontalScrollIndicator = NO;
  209. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  210. _collectionView.backgroundColor = [UIColor whiteColor];
  211. }
  212. return _collectionView;
  213. }
  214. #pragma mark UICollectionView
  215. - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{
  216. return 1;
  217. }
  218. /**********************************************************************/
  219. #pragma mark -UICollectionViewDataSource
  220. /**********************************************************************/
  221. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  222. return self.collectionDataSource.count;
  223. }
  224. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  225. {
  226. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  227. ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  228. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  229. cell.cell0TitleLabel.text = bean.title;
  230. cell.imagH.constant = 25.f;
  231. cell.imagW.constant = 25.f;
  232. cell.titleConstant.constant = 8.f;
  233. switch (indexPath.item) {
  234. case 0:
  235. {
  236. cell.cell0ReadNumLabel.hidden = YES;
  237. NSString * count = @"0";
  238. cell.cell0ReadNumLabel.text = count;
  239. UILabel * label = [UILabel new];
  240. label.font = [UIFont systemFontOfSize:12];
  241. label.text = count;
  242. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  243. if ((width + 5) < 16) {
  244. cell.constant.constant = 16;
  245. }else{
  246. cell.constant.constant = width + 8;
  247. }
  248. }
  249. break;
  250. case 1:
  251. {
  252. cell.cell0ReadNumLabel.hidden = YES;
  253. NSString * count = @"0";
  254. cell.cell0ReadNumLabel.text = count;
  255. UILabel * label = [UILabel new];
  256. label.font = [UIFont systemFontOfSize:12];
  257. label.text = count;
  258. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  259. if ((width + 5) < 16) {
  260. cell.constant.constant = 16;
  261. }else{
  262. cell.constant.constant = width + 8;
  263. }
  264. }
  265. break;
  266. case 2:
  267. {
  268. cell.cell0ReadNumLabel.hidden = YES;
  269. NSString * count = @"0";
  270. cell.cell0ReadNumLabel.text = count;
  271. UILabel * label = [UILabel new];
  272. label.font = [UIFont systemFontOfSize:12];
  273. label.text = count;
  274. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  275. if ((width + 5) < 16) {
  276. cell.constant.constant = 16;
  277. }else{
  278. cell.constant.constant = width + 8;
  279. }
  280. }
  281. break;
  282. case 3:
  283. {
  284. cell.cell0ReadNumLabel.hidden = YES;
  285. NSString * count = @"0";
  286. cell.cell0ReadNumLabel.text = count;
  287. UILabel * label = [UILabel new];
  288. label.font = [UIFont systemFontOfSize:12];
  289. label.text = count;
  290. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  291. if ((width + 5) < 16) {
  292. cell.constant.constant = 16;
  293. }else{
  294. cell.constant.constant = width + 8;
  295. }
  296. }
  297. break;
  298. default:
  299. {
  300. cell.cell0ReadNumLabel.hidden = YES ;
  301. }
  302. break;
  303. }
  304. cell.cell0MengCengView.hidden = YES;
  305. return cell;
  306. }
  307. /****************************************************/
  308. #pragma mark --UICollectionViewDelegateFlowLayout
  309. /****************************************************/
  310. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  311. {
  312. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  313. CGFloat height = 80;
  314. return CGSizeMake(width, height);
  315. }
  316. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  317. {
  318. CGFloat W = 10;
  319. return UIEdgeInsetsMake(0,W,0,W);
  320. }
  321. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  322. return 0;
  323. }
  324. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  325. return 0;
  326. }
  327. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  328. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  329. switch (indexPath.item) {
  330. case 0:
  331. {
  332. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  333. vc.listType = MyFavoriteListLevelTypeA;
  334. vc.FolderId = 0;
  335. vc.operationStateEnum = OperationStateEnum0;
  336. vc.myTitle = @"我的收藏";
  337. vc.hidesBottomBarWhenPushed = YES;
  338. [self.navigationController pushViewController:vc animated:YES];
  339. }
  340. break;
  341. case 1:
  342. {
  343. CommonNoteVC * vc = [CommonNoteVC initCommonNoteVC];
  344. vc.hidesBottomBarWhenPushed = YES;
  345. [self.navigationController pushViewController:vc animated:YES];
  346. }
  347. break;
  348. case 2:
  349. {
  350. CommonToolVC * vc = [CommonToolVC initCommonToolVC];
  351. vc.hidesBottomBarWhenPushed = YES;
  352. [self.navigationController pushViewController:vc animated:YES];
  353. }
  354. break;
  355. default:
  356. {
  357. CommonWorkVC * vc = [CommonWorkVC initCommonWorkVC];
  358. vc.hidesBottomBarWhenPushed = YES;
  359. [self.navigationController pushViewController:vc animated:YES];
  360. }
  361. break;
  362. }
  363. }
  364. - (void)setBarData
  365. {
  366. [self.collectionDataSource removeAllObjects];
  367. NSArray * titleArray = @[@"收藏",@"笔记",@"工具箱",@"工作台"];
  368. NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"];
  369. for (NSInteger i = 0; i < titleArray.count; i ++) {
  370. MoreAppInfoModel * model = [[MoreAppInfoModel alloc] init];
  371. model.title = titleArray[i];
  372. model.imgName = imageArray[i];
  373. [self.collectionDataSource addObject:model];
  374. }
  375. }
  376. @end