CommonHomeVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. //
  2. // CommonHomeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/10/15.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "CommonHomeVC.h"
  9. #import "MyTDGroupView.h"
  10. #import "GHRefreshCollectionView.h"
  11. #import "CommomSearchVC.h"
  12. #import "CommonNoteVC.h"
  13. #import "ChatMsgCollectionCell.h"
  14. #import "CommonWorkVC.h"
  15. #import "CommonToolVC.h"
  16. #import "MyFavoriteVC.h"
  17. #import "NoteBookVC.h"
  18. #import "CommonNoteVC.h"
  19. #import "CommonCollectVC.h"
  20. #import "My_CenterVC.h"
  21. @interface CommonHomeVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
  22. @property (nonatomic, strong) UIView *IconView;
  23. @property (nonatomic, strong) UIImageView *IconImageV;
  24. @property (nonatomic, strong) UILabel *NameL;
  25. @property (nonatomic, strong) UIView *headView;
  26. @property (strong, nonatomic) NSMutableArray *collectionDataSource;
  27. @property (strong, nonatomic) MyTDGroupView *SearchView;
  28. @property (strong, nonatomic) GHRefreshCollectionView *collectionView;
  29. @end
  30. @implementation CommonHomeVC
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.fd_prefersNavigationBarHidden = YES;
  34. [self loadStatusBarColor:[UIColor whiteColor]];
  35. [self addIconView];
  36. [self addHeadView];
  37. [self setCusPageVC];
  38. [self setBarData];
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PushSettingVC:) name:DRAWERPUSHVC object:nil];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updataIcon) name:UPDATAUSERICON object:nil];
  41. }
  42. - (void)dealloc
  43. {
  44. [[NSNotificationCenter defaultCenter] removeObserver:self];
  45. }
  46. - (void)updataIcon
  47. {
  48. [UserManager getUserInfoDetail];
  49. [self.IconImageV sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl] placeholderImage:kPlaceHolderImage];
  50. }
  51. - (void)PushSettingVC:(NSNotification *)notification
  52. {
  53. NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue];
  54. My_CenterVC * vc = [[My_CenterVC alloc] init];
  55. if (index == 4) {
  56. vc.hidesBottomBarWhenPushed = YES;
  57. [self.navigationController pushViewController:vc animated:YES];
  58. }else{
  59. if (index > 4) {
  60. vc.barIndex = index;
  61. vc.systemNar = YES;
  62. vc.hidesBottomBarWhenPushed = YES;
  63. [self.navigationController pushViewController:vc animated:NO];
  64. }
  65. }
  66. }
  67. - (BOOL)hidesBottomBarWhenPushed
  68. {
  69. [self.tabBarController.tabBar setHidden:NO];
  70. return NO;
  71. }
  72. - (void)addIconView
  73. {
  74. [self.view addSubview:self.IconView];
  75. [self.IconView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.top.equalTo(self.statusBar.mas_bottom);
  77. make.left.right.equalTo(self.view);
  78. make.height.equalTo(@44);
  79. }];
  80. [self.IconView addSubview:self.IconImageV];
  81. [self.IconView addSubview:self.NameL];
  82. UIImageView * rightV = [UIImageView new];
  83. rightV.image = IMG(@"icon_arrowRight");
  84. [self.IconView addSubview:rightV];
  85. [self.IconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.centerY.mas_equalTo(self.IconView);
  87. make.left.mas_offset(15);
  88. make.size.mas_offset(CGSizeMake(29, 29));
  89. }];
  90. [self.NameL mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.centerY.mas_equalTo(self.IconView);
  92. make.left.mas_equalTo(self.IconImageV.mas_right).offset(9);
  93. }];
  94. [rightV mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.centerY.mas_equalTo(self.IconView);
  96. make.right.mas_offset(-15);
  97. }];
  98. self.NameL.text = [AppUserModel sharedAppUserModel].Name;
  99. [self.IconImageV sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl] placeholderImage:kPlaceHolderImage];
  100. WS(weakSelf);
  101. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  102. My_CenterVC * vc = [[My_CenterVC alloc] init];
  103. vc.hidesBottomBarWhenPushed = YES;
  104. [weakSelf.navigationController pushViewController:vc animated:YES];
  105. }];
  106. [self.IconView addGestureRecognizer:tap];
  107. }
  108. - (void)addHeadView
  109. {
  110. [self.headView addSubview:self.SearchView];
  111. [self.headView addSubview:self.collectionView];
  112. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.right.bottom.mas_equalTo(self.headView);
  114. make.height.mas_offset(78);
  115. }];
  116. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.top.mas_offset(5);
  118. make.left.right.mas_equalTo(self.headView);
  119. make.bottom.mas_equalTo(self.collectionView.mas_top);
  120. }];
  121. WS(weakSelf);
  122. [self.SearchView.button setAction:^{
  123. CommomSearchVC * vc = [[CommomSearchVC alloc] init];
  124. vc.hidesBottomBarWhenPushed = YES;
  125. [weakSelf.navigationController pushViewController:vc animated:YES];
  126. }];
  127. }
  128. - (UIView *)IconView
  129. {
  130. if (!_IconView) {
  131. _IconView = [UIView new];
  132. }
  133. return _IconView;
  134. }
  135. - (UIImageView *)IconImageV
  136. {
  137. if (!_IconImageV) {
  138. _IconImageV = [UIImageView new];
  139. _IconImageV.layer.cornerRadius = 4.f;
  140. _IconImageV.layer.masksToBounds = YES;
  141. }
  142. return _IconImageV;
  143. }
  144. - (UILabel *)NameL
  145. {
  146. if (!_NameL) {
  147. _NameL = [UILabel new];
  148. _NameL.textColor = UIColorHex(0x0A0A0A);
  149. _NameL.font = Kfont(15);
  150. }
  151. return _NameL;
  152. }
  153. - (UIView *)headView
  154. {
  155. if (!_headView) {
  156. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 124)];
  157. _headView.backgroundColor = [UIColor whiteColor];
  158. }
  159. return _headView;
  160. }
  161. - (MyTDGroupView *)SearchView
  162. {
  163. if (!_SearchView) {
  164. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  165. }
  166. return _SearchView;
  167. }
  168. -(NSMutableArray *)collectionDataSource{
  169. if(!_collectionDataSource){
  170. _collectionDataSource = [[NSMutableArray alloc] init];
  171. }
  172. return _collectionDataSource;
  173. }
  174. - (GHRefreshCollectionView *)collectionView {
  175. if (!_collectionView) {
  176. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  177. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  178. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  179. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  180. _collectionView.delegate = self;
  181. _collectionView.dataSource = self;
  182. _collectionView.showsHorizontalScrollIndicator = NO;
  183. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  184. _collectionView.backgroundColor = [UIColor whiteColor];
  185. }
  186. return _collectionView;
  187. }
  188. - (void)setCusPageVC
  189. {
  190. CGFloat height = SCREEN_HEIGHT - NAVH - self.tabBarController.tabBar.frame.size.height;
  191. WS(weakSelf);
  192. NSMutableArray * data = [NSMutableArray array];
  193. NSMutableArray * vcArr = [NSMutableArray array];
  194. CommonCollectVC * cvc = [[CommonCollectVC alloc] init];
  195. CommonNoteVC * nvc = [[CommonNoteVC alloc] init];
  196. [data addObject:@"最新收藏"];
  197. [data addObject:@"最新笔记"];
  198. [vcArr addObject:cvc];
  199. [vcArr addObject:nvc];
  200. WMZPageParam *param = PageParam()
  201. .wTitleArrSet(data)
  202. .wControllersSet(vcArr)
  203. //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子
  204. .wFixFirstSet(YES)
  205. //悬浮开启
  206. .wTopSuspensionSet(YES)
  207. //等分
  208. .wTopOffsetSet(NAVH)
  209. .wFromNaviSet(YES)
  210. .wMenuAnimalSet(PageTitleMenuNone)
  211. .wMenuTitleFontSet(15.f)
  212. .wMenuTitleSelectColorSet(UIColorHex(0x3979D3))
  213. .wMenuIndicatorYSet(0.f)
  214. .wMenuIndicatorColorSet(UIColorHex(0x3979D3))
  215. .wMenuTitleColorSet(UIColorHex(0x888888))
  216. .wMenuTitleSelectFontSet(15.f)
  217. .wMenuFixShadowSet(NO)
  218. .wMenuFixRightDataSet(@{@"image":@"common_edit"})
  219. .wMenuFixWidthSet(52)
  220. .wMenuCellMarginSet(11)
  221. .wMenuCellPaddingSet(15)
  222. .wMenuBgColorSet(UIColorHex(0xF4F4F4))
  223. .wScrollCanTransferSet(NO)
  224. //头部
  225. .wEventFixedClickSet(^(id anyID, NSInteger index) {
  226. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  227. vc.type = CollectModel_NoteBook;
  228. vc.FolderId = 0;
  229. vc.FolderName = @"根目录";
  230. [weakSelf.navigationController pushViewController:vc animated:YES];
  231. })
  232. .wMenuHeadViewSet(^UIView *{
  233. return self.headView;
  234. });
  235. self.param = param;
  236. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  237. dispatch_async(dispatch_get_main_queue(), ^{
  238. for (UIView * view in weakSelf.view.subviews) {
  239. if ([view isKindOfClass:[WMZPageScroller class]]) {
  240. [view setFrame:CGRectMake(0, NAVH, SCREEN_WIDTH, height)];
  241. }
  242. if ([view isKindOfClass:[UIScrollView class]]) {
  243. UIScrollView * sView = (UIScrollView *)view;
  244. sView.showsVerticalScrollIndicator = NO;
  245. }
  246. }
  247. });
  248. });
  249. }
  250. #pragma mark UICollectionView
  251. - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{
  252. return 1;
  253. }
  254. /**********************************************************************/
  255. #pragma mark -UICollectionViewDataSource
  256. /**********************************************************************/
  257. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  258. return self.collectionDataSource.count;
  259. }
  260. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  261. {
  262. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  263. ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  264. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  265. cell.cell0TitleLabel.text = bean.title;
  266. cell.imagH.constant = 25.f;
  267. cell.imagW.constant = 25.f;
  268. cell.titleConstant.constant = 8.f;
  269. switch (indexPath.item) {
  270. case 0:
  271. {
  272. cell.cell0ReadNumLabel.hidden = YES;
  273. NSString * count = @"0";
  274. cell.cell0ReadNumLabel.text = count;
  275. UILabel * label = [UILabel new];
  276. label.font = [UIFont systemFontOfSize:12];
  277. label.text = count;
  278. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  279. if ((width + 5) < 16) {
  280. cell.constant.constant = 16;
  281. }else{
  282. cell.constant.constant = width + 8;
  283. }
  284. }
  285. break;
  286. case 1:
  287. {
  288. cell.cell0ReadNumLabel.hidden = YES;
  289. NSString * count = @"0";
  290. cell.cell0ReadNumLabel.text = count;
  291. UILabel * label = [UILabel new];
  292. label.font = [UIFont systemFontOfSize:12];
  293. label.text = count;
  294. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  295. if ((width + 5) < 16) {
  296. cell.constant.constant = 16;
  297. }else{
  298. cell.constant.constant = width + 8;
  299. }
  300. }
  301. break;
  302. case 2:
  303. {
  304. cell.cell0ReadNumLabel.hidden = YES;
  305. NSString * count = @"0";
  306. cell.cell0ReadNumLabel.text = count;
  307. UILabel * label = [UILabel new];
  308. label.font = [UIFont systemFontOfSize:12];
  309. label.text = count;
  310. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  311. if ((width + 5) < 16) {
  312. cell.constant.constant = 16;
  313. }else{
  314. cell.constant.constant = width + 8;
  315. }
  316. }
  317. break;
  318. case 3:
  319. {
  320. cell.cell0ReadNumLabel.hidden = YES;
  321. NSString * count = @"0";
  322. cell.cell0ReadNumLabel.text = count;
  323. UILabel * label = [UILabel new];
  324. label.font = [UIFont systemFontOfSize:12];
  325. label.text = count;
  326. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  327. if ((width + 5) < 16) {
  328. cell.constant.constant = 16;
  329. }else{
  330. cell.constant.constant = width + 8;
  331. }
  332. }
  333. break;
  334. default:
  335. {
  336. cell.cell0ReadNumLabel.hidden = YES ;
  337. }
  338. break;
  339. }
  340. cell.cell0MengCengView.hidden = YES;
  341. return cell;
  342. }
  343. /****************************************************/
  344. #pragma mark --UICollectionViewDelegateFlowLayout
  345. /****************************************************/
  346. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  347. {
  348. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  349. CGFloat height = 78;
  350. return CGSizeMake(width, height);
  351. }
  352. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  353. {
  354. CGFloat W = 10;
  355. return UIEdgeInsetsMake(0,W,0,W);
  356. }
  357. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  358. return 0;
  359. }
  360. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  361. return 0;
  362. }
  363. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  364. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  365. switch (indexPath.item) {
  366. case 0:
  367. {
  368. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  369. vc.listType = MyFavoriteListLevelTypeA;
  370. vc.FolderId = 0;
  371. vc.operationStateEnum = OperationStateEnum0;
  372. vc.myTitle = @"我的收藏";
  373. vc.hidesBottomBarWhenPushed = YES;
  374. [self.navigationController pushViewController:vc animated:YES];
  375. }
  376. break;
  377. case 1:
  378. {
  379. NoteBookVC *vc = [NoteBookVC initNoteBookVC];
  380. vc.listType = MyFavoriteListLevelTypeA;
  381. vc.myTitle = @"我的笔记";
  382. vc.hidesBottomBarWhenPushed = YES;
  383. [self.navigationController pushViewController:vc animated:YES];
  384. }
  385. break;
  386. case 2:
  387. {
  388. CommonToolVC * vc = [CommonToolVC initCommonToolVC];
  389. vc.hidesBottomBarWhenPushed = YES;
  390. [self.navigationController pushViewController:vc animated:YES];
  391. }
  392. break;
  393. default:
  394. {
  395. CommonWorkVC * vc = [CommonWorkVC initCommonWorkVC];
  396. vc.hidesBottomBarWhenPushed = YES;
  397. [self.navigationController pushViewController:vc animated:YES];
  398. }
  399. break;
  400. }
  401. }
  402. - (void)setBarData
  403. {
  404. [self.collectionDataSource removeAllObjects];
  405. NSArray * titleArray = @[@"收藏夹",@"笔记本",@"工具箱",@"工作台"];
  406. NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"];
  407. for (NSInteger i = 0; i < titleArray.count; i ++) {
  408. MoreAppInfoModel * model = [[MoreAppInfoModel alloc] init];
  409. model.title = titleArray[i];
  410. model.imgName = imageArray[i];
  411. [self.collectionDataSource addObject:model];
  412. }
  413. }
  414. @end