CommonHomeVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 80.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. switch (indexPath.item) {
  231. case 0:
  232. {
  233. cell.cell0ReadNumLabel.hidden = YES;
  234. NSString * count = @"0";
  235. cell.cell0ReadNumLabel.text = count;
  236. UILabel * label = [UILabel new];
  237. label.font = [UIFont systemFontOfSize:12];
  238. label.text = count;
  239. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  240. if ((width + 5) < 16) {
  241. cell.constant.constant = 16;
  242. }else{
  243. cell.constant.constant = width + 8;
  244. }
  245. }
  246. break;
  247. case 1:
  248. {
  249. cell.cell0ReadNumLabel.hidden = YES;
  250. NSString * count = @"0";
  251. cell.cell0ReadNumLabel.text = count;
  252. UILabel * label = [UILabel new];
  253. label.font = [UIFont systemFontOfSize:12];
  254. label.text = count;
  255. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  256. if ((width + 5) < 16) {
  257. cell.constant.constant = 16;
  258. }else{
  259. cell.constant.constant = width + 8;
  260. }
  261. }
  262. break;
  263. case 2:
  264. {
  265. cell.cell0ReadNumLabel.hidden = YES;
  266. NSString * count = @"0";
  267. cell.cell0ReadNumLabel.text = count;
  268. UILabel * label = [UILabel new];
  269. label.font = [UIFont systemFontOfSize:12];
  270. label.text = count;
  271. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  272. if ((width + 5) < 16) {
  273. cell.constant.constant = 16;
  274. }else{
  275. cell.constant.constant = width + 8;
  276. }
  277. }
  278. break;
  279. case 3:
  280. {
  281. cell.cell0ReadNumLabel.hidden = YES;
  282. NSString * count = @"0";
  283. cell.cell0ReadNumLabel.text = count;
  284. UILabel * label = [UILabel new];
  285. label.font = [UIFont systemFontOfSize:12];
  286. label.text = count;
  287. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  288. if ((width + 5) < 16) {
  289. cell.constant.constant = 16;
  290. }else{
  291. cell.constant.constant = width + 8;
  292. }
  293. }
  294. break;
  295. default:
  296. {
  297. cell.cell0ReadNumLabel.hidden = YES ;
  298. }
  299. break;
  300. }
  301. cell.cell0MengCengView.hidden = YES;
  302. return cell;
  303. }
  304. /****************************************************/
  305. #pragma mark --UICollectionViewDelegateFlowLayout
  306. /****************************************************/
  307. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  308. {
  309. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  310. CGFloat height = 80;
  311. return CGSizeMake(width, height);
  312. }
  313. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  314. {
  315. CGFloat W = 10;
  316. return UIEdgeInsetsMake(0,W,0,W);
  317. }
  318. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  319. return 0;
  320. }
  321. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  322. return 0;
  323. }
  324. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  325. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  326. switch (indexPath.item) {
  327. case 0:
  328. {
  329. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  330. vc.listType = MyFavoriteListLevelTypeA;
  331. vc.FolderId = 0;
  332. vc.operationStateEnum = OperationStateEnum0;
  333. vc.myTitle = @"我的收藏";
  334. vc.hidesBottomBarWhenPushed = YES;
  335. [self.navigationController pushViewController:vc animated:YES];
  336. }
  337. break;
  338. case 1:
  339. {
  340. CommonNoteVC * vc = [CommonNoteVC initCommonNoteVC];
  341. vc.hidesBottomBarWhenPushed = YES;
  342. [self.navigationController pushViewController:vc animated:YES];
  343. }
  344. break;
  345. case 2:
  346. {
  347. CommonToolVC * vc = [CommonToolVC initCommonToolVC];
  348. vc.hidesBottomBarWhenPushed = YES;
  349. [self.navigationController pushViewController:vc animated:YES];
  350. }
  351. break;
  352. default:
  353. {
  354. CommonWorkVC * vc = [CommonWorkVC initCommonWorkVC];
  355. vc.hidesBottomBarWhenPushed = YES;
  356. [self.navigationController pushViewController:vc animated:YES];
  357. }
  358. break;
  359. }
  360. }
  361. - (void)setBarData
  362. {
  363. [self.collectionDataSource removeAllObjects];
  364. NSArray * titleArray = @[@"收藏",@"笔记",@"工具箱",@"工作台"];
  365. NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"];
  366. for (NSInteger i = 0; i < titleArray.count; i ++) {
  367. MoreAppInfoModel * model = [[MoreAppInfoModel alloc] init];
  368. model.title = titleArray[i];
  369. model.imgName = imageArray[i];
  370. [self.collectionDataSource addObject:model];
  371. }
  372. }
  373. @end