SourceHomeVC.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. //
  2. // SourceHomeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/6.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "SourceHomeVC.h"
  9. #import "GHRefreshCollectionView.h"
  10. #import "MyTDGroupView.h"
  11. #import "MenuListView.h"
  12. #import "ShowBtn.h"
  13. #import "ChatMsgCollectionCell.h"
  14. #import "ChatMsgListVC.h"
  15. #import "TopicGroupManageModel.h"
  16. #import "MyTDTopicGroupManageVC.h"
  17. #import "MyTDTopicSearchVC.h"
  18. #import "MyTDTopicBookVC.h"
  19. #import "MyTDGroupViewController.h"
  20. #import "MyTDTopicBookVC.h"
  21. #import "GroupSquareVC.h"
  22. #import "SourceListVC.h"
  23. @interface SourceHomeVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
  24. @property (nonatomic, strong) UIView *NavBar;
  25. @property (nonatomic, strong) ShowBtn *showBtn;
  26. @property (nonatomic, strong) UIButton *addBtn;
  27. @property (nonatomic, strong) UIView *headView;
  28. @property (nonatomic, strong) GHRefreshCollectionView *collectionView;
  29. @property (strong, nonatomic) MyTDGroupView *SearchView;
  30. @property (strong, nonatomic) NSMutableArray *collectionDataSource;
  31. @property (strong, nonatomic) NSMutableArray *selectGIdArray;
  32. @property (strong, nonatomic) NSMutableArray *groupListArray;
  33. @property (copy, nonatomic) NSString *listName;
  34. @property (strong, nonatomic) SourceListVC *listVC;
  35. @property (strong, nonatomic) MenuListView *menuListView;
  36. @property (assign, nonatomic) BOOL menuIsShow;
  37. @end
  38. @implementation SourceHomeVC
  39. - (void)viewWillAppear:(BOOL)animated
  40. {
  41. [super viewWillAppear:animated];
  42. }
  43. - (void)viewWillDisappear:(BOOL)animated
  44. {
  45. [super viewWillDisappear:animated];
  46. [self.showBtn dismissCom];
  47. self.menuIsShow = NO;
  48. [self.menuListView dismiss];
  49. }
  50. - (BOOL)hidesBottomBarWhenPushed
  51. {
  52. [self.tabBarController.tabBar setHidden:NO];
  53. return NO;
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. self.fd_prefersNavigationBarHidden = YES;
  58. [self loadStatusBarColor:[UIColor whiteColor]];
  59. [self.view addSubview:self.NavBar];
  60. [self.NavBar addSubview:self.showBtn];
  61. [self.NavBar addSubview:self.addBtn];
  62. [self.NavBar mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.statusBar.mas_bottom);
  64. make.left.right.equalTo(self.view);
  65. make.height.equalTo(@44);
  66. }];
  67. [self.showBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.center.mas_equalTo(self.NavBar);
  69. }];
  70. [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.top.mas_equalTo(self.statusBar.mas_bottom);
  72. make.right.mas_offset(-10);
  73. make.size.mas_offset(CGSizeMake(44, 44));
  74. }];
  75. WS(weakSelf);
  76. [self setShowData];
  77. [self.addBtn setAction:^{
  78. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  79. vc.type = CollectModel_NewTopic;
  80. vc.hidesBottomBarWhenPushed = YES;
  81. [weakSelf.navigationController pushViewController:vc animated:YES];
  82. }];
  83. [self addHeadView];
  84. [self setCusPageVC];
  85. [self initCollectionData];
  86. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PushSettingVC:) name:DRAWERPUSHVC object:nil];
  87. }
  88. - (void)PushSettingVC:(NSNotification *)notification
  89. {
  90. NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue];
  91. if (index == 1) {
  92. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  93. vc.hidesBottomBarWhenPushed = YES;
  94. [self.navigationController pushViewController:vc animated:NO];
  95. }
  96. }
  97. - (void)dealloc
  98. {
  99. [[NSNotificationCenter defaultCenter] removeObserver:self];
  100. }
  101. - (void)addHeadView
  102. {
  103. UIView * lineV = [UIView new];
  104. lineV.backgroundColor = UIColorHex(0xEAEAEA);
  105. [self.headView addSubview:lineV];
  106. [self.headView addSubview:self.SearchView];
  107. [self.headView addSubview:self.collectionView];
  108. [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.left.right.bottom.mas_equalTo(self.headView);
  110. make.height.mas_offset(0.5);
  111. }];
  112. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.right.mas_equalTo(self.headView);
  114. make.bottom.mas_equalTo(lineV.mas_top);
  115. make.height.mas_offset(69);
  116. }];
  117. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.top.mas_offset(5);
  119. make.left.right.mas_equalTo(self.headView);
  120. make.bottom.mas_equalTo(self.collectionView.mas_top);
  121. }];
  122. WS(weakSelf);
  123. [self.SearchView.button setAction:^{
  124. MyTDTopicSearchVC * vc = [[MyTDTopicSearchVC alloc] init];
  125. vc.hidesBottomBarWhenPushed = YES;
  126. [weakSelf.navigationController pushViewController:vc animated:YES];
  127. }];
  128. }
  129. -(NSMutableArray *)collectionDataSource{
  130. if(!_collectionDataSource){
  131. _collectionDataSource = [[NSMutableArray alloc] init];
  132. }
  133. return _collectionDataSource;
  134. }
  135. -(NSMutableArray *)selectGIdArray{
  136. if(!_selectGIdArray){
  137. _selectGIdArray = [[NSMutableArray alloc] init];
  138. }
  139. return _selectGIdArray;
  140. }
  141. -(NSMutableArray *)groupListArray{
  142. if(!_groupListArray){
  143. _groupListArray = [[NSMutableArray alloc] init];
  144. }
  145. return _groupListArray;
  146. }
  147. - (UIView *)NavBar
  148. {
  149. if (!_NavBar) {
  150. _NavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
  151. _NavBar.backgroundColor = [UIColor whiteColor];
  152. }
  153. return _NavBar;
  154. }
  155. - (ShowBtn *)showBtn
  156. {
  157. if (!_showBtn) {
  158. _showBtn = [ShowBtn new];
  159. }
  160. return _showBtn;
  161. }
  162. - (UIButton *)addBtn
  163. {
  164. if (!_addBtn) {
  165. _addBtn = [UIButton new];
  166. [_addBtn setImage:IMG(@"detailsEditor") forState:UIControlStateNormal];
  167. }
  168. return _addBtn;
  169. }
  170. - (UIView *)headView
  171. {
  172. if (!_headView) {
  173. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115.5)];
  174. _headView.backgroundColor = [UIColor whiteColor];
  175. }
  176. return _headView;
  177. }
  178. - (MyTDGroupView *)SearchView
  179. {
  180. if (!_SearchView) {
  181. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  182. }
  183. return _SearchView;
  184. }
  185. - (void)setCusPageVC
  186. {
  187. CGFloat height = SCREEN_HEIGHT - NAVH - self.tabBarController.tabBar.frame.size.height;
  188. WS(weakSelf);
  189. NSMutableArray * data = [NSMutableArray array];
  190. NSMutableArray * vcArr = [NSMutableArray array];
  191. self.listVC = [[SourceListVC alloc] init];
  192. [data addObject:@""];
  193. [vcArr addObject:self.listVC];
  194. WMZPageParam *param = PageParam()
  195. .wTitleArrSet(data)
  196. .wControllersSet(vcArr)
  197. //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子
  198. .wFixFirstSet(YES)
  199. //悬浮开启
  200. .wTopSuspensionSet(YES)
  201. //等分
  202. .wTopOffsetSet(NAVH)
  203. .wFromNaviSet(YES)
  204. .wMenuAnimalSet(PageTitleMenuNone)
  205. .wMenuTitleFontSet(15.f)
  206. .wMenuTitleSelectColorSet(UIColorHex(0x3979D3))
  207. .wMenuIndicatorYSet(0.f)
  208. .wMenuIndicatorColorSet(UIColorHex(0x3979D3))
  209. .wMenuTitleColorSet(UIColorHex(0x666666))
  210. .wMenuTitleSelectFontSet(15.f)
  211. .wMenuFixShadowSet(NO)
  212. .wMenuFixRightDataSet(@" ")
  213. .wMenuFixWidthSet(0)
  214. .wNoMenuSet(YES)
  215. .wScrollCanTransferSet(NO)
  216. //头部
  217. .wMenuHeadViewSet(^UIView *{
  218. return self.headView;
  219. });
  220. self.param = param;
  221. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  222. dispatch_async(dispatch_get_main_queue(), ^{
  223. for (UIView * view in weakSelf.view.subviews) {
  224. if ([view isKindOfClass:[WMZPageScroller class]]) {
  225. [view setFrame:CGRectMake(0, NAVH, SCREEN_WIDTH, height)];
  226. }
  227. if ([view isKindOfClass:[UIScrollView class]]) {
  228. UIScrollView * sView = (UIScrollView *)view;
  229. sView.showsVerticalScrollIndicator = NO;
  230. }
  231. }
  232. });
  233. });
  234. }
  235. - (GHRefreshCollectionView *)collectionView {
  236. if (!_collectionView) {
  237. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  238. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  239. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  240. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  241. _collectionView.delegate = self;
  242. _collectionView.dataSource = self;
  243. _collectionView.showsHorizontalScrollIndicator = NO;
  244. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  245. _collectionView.backgroundColor = [UIColor whiteColor];
  246. }
  247. return _collectionView;
  248. }
  249. -(void)initCollectionData
  250. {
  251. [self.collectionDataSource removeAllObjects];
  252. NSMutableArray * array = [NSMutableArray array];
  253. for (int i= 0;i < 3; i++) {
  254. MoreAppInfoModel *model = [[MoreAppInfoModel alloc] init];
  255. switch (i) {
  256. case 0:{
  257. model.title = @"话题本";
  258. model.imgName = @"Soucre_topicBook";
  259. model.notImgName = @"Soucre_topicBook";
  260. model.type = ChatMenuTopicBookType;
  261. model.readNum = 0;
  262. model.showEditFlag = YES;
  263. }break;
  264. case 1:{
  265. model.title = @"我的小组";
  266. model.imgName = @"Soucre_group";
  267. model.notImgName = @"Soucre_group";
  268. model.type = ChatMenuGroupType;
  269. model.readNum = 0;
  270. model.showEditFlag = YES;
  271. }break;
  272. default:{
  273. model.title = @"小组广场";
  274. model.imgName = @"Soucre_square";
  275. model.notImgName = @"Soucre_square";
  276. model.type = ChatMenuSquareType;
  277. model.readNum = 0;
  278. model.showEditFlag = YES;
  279. }break;
  280. }
  281. [array addObject:model];
  282. }
  283. self.collectionDataSource = array;
  284. [self.collectionView reloadData];
  285. }
  286. #pragma mark -UICollectionViewDataSource
  287. /**********************************************************************/
  288. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  289. return self.collectionDataSource.count;
  290. }
  291. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  292. {
  293. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  294. ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  295. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  296. cell.cell0TitleLabel.text = bean.title;
  297. cell.imagH.constant = 25.f;
  298. cell.imagW.constant = 25.f;
  299. cell.cell0MengCengView.hidden = YES;
  300. cell.cell0ReadNumLabel.hidden = YES;
  301. return cell;
  302. }
  303. /****************************************************/
  304. #pragma mark --UICollectionViewDelegateFlowLayout
  305. /****************************************************/
  306. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  307. {
  308. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  309. CGFloat height = 69;
  310. return CGSizeMake(width, height);
  311. }
  312. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  313. {
  314. CGFloat W = 10;
  315. return UIEdgeInsetsMake(0,W,0,W);
  316. }
  317. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  318. return 0;
  319. }
  320. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  321. return 0;
  322. }
  323. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  324. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  325. MoreAppInfoModel * model = [self.collectionDataSource objectAtIndex:indexPath.item];
  326. switch (model.type) {
  327. case ChatMenuTopicBookType:{
  328. MyTDTopicBookVC * vc = [MyTDTopicBookVC initMyTDTopicBookVC];
  329. vc.hidesBottomBarWhenPushed = YES;
  330. [self.navigationController pushViewController:vc animated:YES];
  331. }break;
  332. case ChatMenuGroupType:{
  333. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  334. vc.hidesBottomBarWhenPushed = YES;
  335. [self.navigationController pushViewController:vc animated:YES];
  336. }break;
  337. default:{
  338. GroupSquareVC *vc = [GroupSquareVC initGroupSquareVC];
  339. vc.hidesBottomBarWhenPushed = YES;
  340. [self.navigationController pushViewController:vc animated:YES];
  341. }break;
  342. }
  343. }
  344. - (void)autoSizeBtn:(NSString *)title
  345. {
  346. [self.showBtn setcomTitle:title];
  347. }
  348. - (void)setShowData
  349. {
  350. [self getGroupList];
  351. self.menuIsShow = NO;
  352. WS(weakSelf);
  353. [self.showBtn setAction:^{
  354. if (!weakSelf.menuIsShow) {
  355. [weakSelf.menuListView show];
  356. [weakSelf.showBtn showCom];
  357. weakSelf.menuListView.SelectBtnblock = ^(NSArray * _Nonnull array) {
  358. [weakSelf.showBtn dismissCom];
  359. [weakSelf.selectGIdArray removeAllObjects];
  360. NSMutableString * showName = [[NSMutableString alloc] init];
  361. for (NSArray * subArray in array) {
  362. for (TopicGroupManageModel * model in subArray) {
  363. if (model.isSelect) {
  364. weakSelf.listVC.GroupNoUser = model.IncludeCount == 0 ? YES : NO;
  365. [showName appendString:model.Name];
  366. [weakSelf.selectGIdArray addObject:@(model.Id)];
  367. }
  368. }
  369. }
  370. weakSelf.listName = showName;
  371. if (weakSelf.selectGIdArray.count > 0) {
  372. [weakSelf.listVC headRefresh];
  373. }
  374. };
  375. weakSelf.menuListView.dismissBlock = ^{
  376. [weakSelf.showBtn dismissCom];
  377. };
  378. weakSelf.menuListView.SelectGroupblock = ^{
  379. [weakSelf.showBtn dismissCom];
  380. weakSelf.menuIsShow = NO;
  381. [weakSelf.menuListView dismiss];
  382. MyTDTopicGroupManageVC * vc = [MyTDTopicGroupManageVC initMyTDTopicGroupManageVC];
  383. vc.RefreshListBlock = ^{
  384. [weakSelf getGroupList];
  385. };
  386. vc.hidesBottomBarWhenPushed = YES;
  387. [weakSelf.navigationController pushViewController:vc animated:YES];
  388. };
  389. weakSelf.menuIsShow = YES;
  390. }else{
  391. weakSelf.menuIsShow = NO;
  392. [weakSelf.showBtn dismissCom];
  393. [weakSelf.menuListView dismiss];
  394. }
  395. }];
  396. [self autoSizeBtn:self.listName.length > 0 ? self.listName : @"全部"];
  397. }
  398. - (void)getGroupList
  399. {
  400. WS(weakSelf);
  401. [[HttpManager sharedHttpManager] GETUrl:Host(APP_Topic_Group) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  402. NSLog(@"======%@",responseObject);
  403. [weakSelf.groupListArray removeAllObjects];
  404. NSArray * array = responseObject;
  405. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  406. NSDictionary * dict = (NSDictionary *)obj;
  407. TopicGroupManageModel * model = [TopicGroupManageModel modelWithDictionary:dict];
  408. [weakSelf.groupListArray addObject:model];
  409. }];
  410. dispatch_async(dispatch_get_main_queue(), ^{
  411. weakSelf.menuListView = [MenuListView MenuListViewaddArray:@[weakSelf.groupListArray] height:NAVH MenuType:MenuMoreSelectType];
  412. });
  413. } failure:^(NSError * _Nonnull error) {
  414. }];
  415. }
  416. @end