CommonHomeVC.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 (strong, nonatomic) 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. - (UIView *)HeadView
  31. {
  32. if (!_HeadView) {
  33. _HeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 46)];
  34. _HeadView.backgroundColor = [UIColor whiteColor];
  35. }
  36. return _HeadView;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.fd_prefersNavigationBarHidden = YES;
  41. self.view.backgroundColor = UIColorHex(0xffffff);
  42. if (@available(iOS 11.0, *)) {
  43. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  44. } else {
  45. self.automaticallyAdjustsScrollViewInsets = NO;
  46. }
  47. [self.HeadView addSubview:self.SearchView];
  48. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.mas_offset(5);
  50. make.left.right.mas_equalTo(self.HeadView);
  51. make.height.mas_offset(36);
  52. }];
  53. [self.view addSubview:self.tableView];
  54. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.right.mas_equalTo(self.view);
  56. make.top.mas_equalTo(self.NavBar.mas_bottom);
  57. if (@available(iOS 11.0, *)) {
  58. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  59. } else {
  60. make.bottom.equalTo(self.view.mas_bottom);
  61. }
  62. }];
  63. self.tableView.tableHeaderView = self.HeadView;
  64. [self setBarData];
  65. [self.SearchView.button setAction:^{
  66. NSLog(@"点击搜索");
  67. }];
  68. self.tableView.delegate = self;
  69. self.tableView.dataSource = self;
  70. self.tableView.backgroundColor = [UIColor clearColor];
  71. CommonListModel * model = [[CommonListModel alloc] init];
  72. model.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  73. model.Name = @"钱颖一";
  74. model.Des = @"中国前沿计算机教育观察周刊";
  75. [self.dataArray addObject:model];
  76. [self.dataArray addObject:model];
  77. [self.dataArray addObject:model];
  78. [self.dataArray addObject:model];
  79. [self.dataArray addObject:model];
  80. CommonListModel * amodel = [[CommonListModel alloc] init];
  81. amodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  82. amodel.Name = @"钱颖一";
  83. amodel.Des = @"中国前沿计算机教育观察周刊";
  84. [self.dataArray addObject:amodel];
  85. CommonListModel * bmodel = [[CommonListModel alloc] init];
  86. bmodel.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  87. bmodel.Name = @"钱颖一";
  88. bmodel.Des = @"中国前沿计算机教育观察周刊";
  89. [self.dataArray addObject:bmodel];
  90. CommonListModel * cmodel = [[CommonListModel alloc] init];
  91. cmodel.Title = @"大脑不擅长思考,那我们应该怎么学习?";
  92. cmodel.Name = @"周明鑫";
  93. cmodel.Des = @"北国教育论坛";
  94. [self.dataArray addObject:cmodel];
  95. [self.tableView reloadData];
  96. }
  97. - (BOOL)hidesBottomBarWhenPushed{
  98. return NO;
  99. }
  100. #pragma mark - UITableViewDelegate
  101. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  102. return 2;
  103. }
  104. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  105. switch (section) {
  106. case 0:{
  107. return 1;
  108. }break;
  109. default:{
  110. return self.dataArray.count;
  111. }break;
  112. }
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  115. switch (indexPath.section) {
  116. case 0:{
  117. return 74.f;
  118. }break;
  119. default:{
  120. return UITableViewAutomaticDimension;
  121. }break;
  122. }
  123. }
  124. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  125. {
  126. switch (section) {
  127. case 0:{
  128. return 0.f;
  129. }break;
  130. default:{
  131. return 36.f;
  132. }break;
  133. }
  134. }
  135. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  136. {
  137. switch (section) {
  138. case 0:{
  139. UIView * view = [UIView new];
  140. return view;
  141. }break;
  142. default:{
  143. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  144. view.backgroundColor = UIColorHex(0xF5F5F5);
  145. UILabel * label = [UILabel new];
  146. label.font = [UIFont systemFontOfSize:14];
  147. label.textColor = UIColorHex(0x888888);
  148. label.text = @"最新收藏";
  149. [view addSubview:label];
  150. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.left.mas_offset(15);
  152. make.centerY.mas_equalTo(view);
  153. }];
  154. return view;
  155. }break;
  156. }
  157. }
  158. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  159. switch (indexPath.section) {
  160. case 0:
  161. {
  162. ChatMsgListCell *cell = [ChatMsgListCell configCell1:tableView indexPath:indexPath];
  163. [cell.cell1ContentBgView addSubview:self.collectionView];
  164. self.collectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, cell.cell1ContentBgView.height);
  165. [self.collectionView reloadData];
  166. return cell;
  167. }
  168. break;
  169. default:
  170. {
  171. CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath];
  172. CommonListModel * model = [self.dataArray objectAtIndex:indexPath.row];
  173. [cell setCell1Data:model];
  174. return cell;
  175. }
  176. break;
  177. }
  178. }
  179. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  180. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  181. }
  182. #pragma mark - load
  183. - (UITableView *)tableView
  184. {
  185. if (!_tableView) {
  186. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  187. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  188. }
  189. return _tableView;
  190. }
  191. - (MyTDGroupView *)SearchView
  192. {
  193. if (!_SearchView) {
  194. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  195. }
  196. return _SearchView;
  197. }
  198. -(NSMutableArray *)dataArray{
  199. if(!_dataArray){
  200. _dataArray = [[NSMutableArray alloc] init];
  201. }
  202. return _dataArray;
  203. }
  204. -(NSMutableArray *)collectionDataSource{
  205. if(!_collectionDataSource){
  206. _collectionDataSource = [[NSMutableArray alloc] init];
  207. }
  208. return _collectionDataSource;
  209. }
  210. - (GHRefreshCollectionView *)collectionView {
  211. if (!_collectionView) {
  212. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  213. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  214. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  215. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  216. _collectionView.delegate = self;
  217. _collectionView.dataSource = self;
  218. _collectionView.showsHorizontalScrollIndicator = NO;
  219. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  220. _collectionView.backgroundColor = [UIColor whiteColor];
  221. }
  222. return _collectionView;
  223. }
  224. #pragma mark UICollectionView
  225. - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{
  226. return 1;
  227. }
  228. /**********************************************************************/
  229. #pragma mark -UICollectionViewDataSource
  230. /**********************************************************************/
  231. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  232. return self.collectionDataSource.count;
  233. }
  234. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  235. {
  236. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  237. ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  238. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  239. cell.cell0TitleLabel.text = bean.title;
  240. cell.imagH.constant = 25.f;
  241. cell.imagW.constant = 25.f;
  242. cell.titleConstant.constant = 8.f;
  243. switch (indexPath.item) {
  244. case 0:
  245. {
  246. cell.cell0ReadNumLabel.hidden = YES;
  247. NSString * count = @"0";
  248. cell.cell0ReadNumLabel.text = count;
  249. UILabel * label = [UILabel new];
  250. label.font = [UIFont systemFontOfSize:12];
  251. label.text = count;
  252. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  253. if ((width + 5) < 16) {
  254. cell.constant.constant = 16;
  255. }else{
  256. cell.constant.constant = width + 8;
  257. }
  258. }
  259. break;
  260. case 1:
  261. {
  262. cell.cell0ReadNumLabel.hidden = YES;
  263. NSString * count = @"0";
  264. cell.cell0ReadNumLabel.text = count;
  265. UILabel * label = [UILabel new];
  266. label.font = [UIFont systemFontOfSize:12];
  267. label.text = count;
  268. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  269. if ((width + 5) < 16) {
  270. cell.constant.constant = 16;
  271. }else{
  272. cell.constant.constant = width + 8;
  273. }
  274. }
  275. break;
  276. case 2:
  277. {
  278. cell.cell0ReadNumLabel.hidden = YES;
  279. NSString * count = @"0";
  280. cell.cell0ReadNumLabel.text = count;
  281. UILabel * label = [UILabel new];
  282. label.font = [UIFont systemFontOfSize:12];
  283. label.text = count;
  284. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  285. if ((width + 5) < 16) {
  286. cell.constant.constant = 16;
  287. }else{
  288. cell.constant.constant = width + 8;
  289. }
  290. }
  291. break;
  292. case 3:
  293. {
  294. cell.cell0ReadNumLabel.hidden = YES;
  295. NSString * count = @"0";
  296. cell.cell0ReadNumLabel.text = count;
  297. UILabel * label = [UILabel new];
  298. label.font = [UIFont systemFontOfSize:12];
  299. label.text = count;
  300. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  301. if ((width + 5) < 16) {
  302. cell.constant.constant = 16;
  303. }else{
  304. cell.constant.constant = width + 8;
  305. }
  306. }
  307. break;
  308. default:
  309. {
  310. cell.cell0ReadNumLabel.hidden = YES ;
  311. }
  312. break;
  313. }
  314. cell.cell0MengCengView.hidden = YES;
  315. return cell;
  316. }
  317. /****************************************************/
  318. #pragma mark --UICollectionViewDelegateFlowLayout
  319. /****************************************************/
  320. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  321. {
  322. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  323. CGFloat height = 80;
  324. return CGSizeMake(width, height);
  325. }
  326. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  327. {
  328. CGFloat W = 10;
  329. return UIEdgeInsetsMake(0,W,0,W);
  330. }
  331. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  332. return 0;
  333. }
  334. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  335. return 0;
  336. }
  337. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  338. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  339. switch (indexPath.item) {
  340. case 0:
  341. {
  342. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  343. vc.listType = MyFavoriteListLevelTypeA;
  344. vc.FolderId = 0;
  345. vc.operationStateEnum = OperationStateEnum0;
  346. vc.myTitle = @"我的收藏";
  347. vc.hidesBottomBarWhenPushed = YES;
  348. [self.navigationController pushViewController:vc animated:YES];
  349. }
  350. break;
  351. case 1:
  352. {
  353. CommonNoteVC * vc = [CommonNoteVC initCommonNoteVC];
  354. vc.hidesBottomBarWhenPushed = YES;
  355. [self.navigationController pushViewController:vc animated:YES];
  356. }
  357. break;
  358. case 2:
  359. {
  360. CommonToolVC * vc = [CommonToolVC initCommonToolVC];
  361. vc.hidesBottomBarWhenPushed = YES;
  362. [self.navigationController pushViewController:vc animated:YES];
  363. }
  364. break;
  365. default:
  366. {
  367. CommonWorkVC * vc = [CommonWorkVC initCommonWorkVC];
  368. vc.hidesBottomBarWhenPushed = YES;
  369. [self.navigationController pushViewController:vc animated:YES];
  370. }
  371. break;
  372. }
  373. }
  374. - (void)setBarData
  375. {
  376. [self.collectionDataSource removeAllObjects];
  377. NSArray * titleArray = @[@"收藏",@"笔记",@"工具箱",@"工作台"];
  378. NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"];
  379. for (NSInteger i = 0; i < titleArray.count; i ++) {
  380. MoreAppInfoModel * model = [[MoreAppInfoModel alloc] init];
  381. model.title = titleArray[i];
  382. model.imgName = imageArray[i];
  383. [self.collectionDataSource addObject:model];
  384. }
  385. }
  386. #pragma Mark 左滑按钮 iOS8以上
  387. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  388. - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){
  389. if (indexPath.section == 0) {
  390. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
  391. actions.performsFirstActionWithFullSwipe = NO;
  392. return actions;
  393. }else{
  394. WEAKSELF
  395. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"转发" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  396. [tableView setEditing:NO animated:YES];
  397. }];
  398. action1.backgroundColor = UIColorHex(#FF923A);
  399. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"置顶" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  400. [tableView setEditing:NO animated:YES];
  401. }];
  402. action2.backgroundColor = UIColorHex(#9BA9CB);
  403. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"移动" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  404. [tableView setEditing:NO animated:YES];
  405. }];
  406. action3.backgroundColor = UIColorHex(#589AF1);
  407. UIContextualAction *action4 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  408. [tableView setEditing:NO animated:YES];
  409. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:UIAlertControllerStyleAlert];
  410. UIAlertAction *ok = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  411. }];
  412. [ok setValue:k9 forKey:@"_titleTextColor"];
  413. UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  414. }];
  415. [alertVC addAction:ok];
  416. [alertVC addAction:noOk];
  417. completionHandler(YES);
  418. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  419. }];
  420. action4.backgroundColor = UIColorHex(#F64A33);
  421. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action4,action3,action2,action1]];
  422. actions.performsFirstActionWithFullSwipe = NO;
  423. return actions;
  424. }
  425. }
  426. #else
  427. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  428. if (indexPath.section == 0) {
  429. return @[];
  430. }else{
  431. WEAKSELF
  432. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"转发" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  433. }];
  434. action1.backgroundColor = UIColorHex(#FF923A);
  435. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  436. }];
  437. action2.backgroundColor = UIColorHex(#9BA9CB);
  438. UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  439. }];
  440. action3.backgroundColor = UIColorHex(#589AF1);
  441. UITableViewRowAction *action4 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  442. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:UIAlertControllerStyleAlert];
  443. UIAlertAction *ok = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  444. }];
  445. [ok setValue:k9 forKey:@"_titleTextColor"];
  446. UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  447. }];
  448. [alertVC addAction:ok];
  449. [alertVC addAction:noOk];
  450. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  451. }];
  452. action4.backgroundColor = UIColorHex(#F64A33);
  453. return @[action4, action3, action2,action1];
  454. }
  455. }
  456. #endif
  457. @end