HWToolViewController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // HWToolViewController.m
  3. // Private-X
  4. //
  5. // Created by 余衡武 on 2022/3/21.
  6. //
  7. #import "HWToolViewController.h"
  8. #import "HWToolListCell.h"
  9. @interface HWToolViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  10. @property (weak, nonatomic) IBOutlet UIView *bigBGView;
  11. @property (weak, nonatomic) IBOutlet UIView *bgView;
  12. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  13. @property (strong, nonatomic) NSMutableArray *dataSource;
  14. @end
  15. @implementation HWToolViewController
  16. #pragma mark 生命周期
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self drawView];
  20. [self getData];
  21. }
  22. #pragma mark UI布局
  23. - (void)drawView {
  24. self.bgView.backgroundColor = HW1C1C1EColor;
  25. self.bgView.layer.cornerRadius = 10;
  26. self.bgView.layer.masksToBounds = YES;
  27. [self.bigBGView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewClick)]];
  28. self.collectionView.delegate = self;
  29. self.collectionView.dataSource = self;
  30. self.collectionView.backgroundColor = [UIColor clearColor];
  31. [self.collectionView registerNib:[UINib nibWithNibName:@"HWToolListCell" bundle:nil] forCellWithReuseIdentifier:@"HWToolListCell"];
  32. UICollectionViewFlowLayout *dataLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
  33. CGFloat W = (SCREEN_W - 12*2)*0.25;
  34. CGFloat H = 88;
  35. dataLayout.itemSize = CGSizeMake(W, H);
  36. dataLayout.minimumLineSpacing = 0;
  37. dataLayout.minimumInteritemSpacing = 0;
  38. dataLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  39. }
  40. #pragma mark 获取数据
  41. - (void)getData {
  42. [self.dataSource removeAllObjects];
  43. NSArray *nameArr;
  44. NSArray *iconArr;
  45. if (self.isSetUnavailable) {
  46. nameArr = @[NSLocalizedString(@"more_add_bookmark",nil), NSLocalizedString(@"more_bookmark",nil), NSLocalizedString(@"more_history",nil), NSLocalizedString(@"more_set",nil), NSLocalizedString(@"more_traceless",nil), NSLocalizedString(@"more_refresh",nil), NSLocalizedString(@"more_share",nil)];
  47. iconArr = @[@"tianjia_hui_icon", @"shuqian_icon", @"lishi_icon", @"shezhi_icon", @"wuheng_icon", @"shuaxin_hui_icon", @"fenxiang_hui_icon"];
  48. }else {
  49. nameArr = @[NSLocalizedString(@"more_add_bookmark",nil), NSLocalizedString(@"more_bookmark",nil), NSLocalizedString(@"more_history",nil), NSLocalizedString(@"more_set",nil), NSLocalizedString(@"more_traceless",nil), NSLocalizedString(@"more_refresh",nil), NSLocalizedString(@"more_share",nil)];
  50. iconArr = @[@"tianjia_icon", @"shuqian_icon", @"lishi_icon", @"shezhi_icon", @"wuheng_icon", @"shuaxin_icon", @"fenxiang_icon"];
  51. }
  52. for (int i = 0; i < nameArr.count; i++) {
  53. NSString *name = nameArr[i];
  54. NSString *icon = iconArr[i];
  55. BaseModel *model = [[BaseModel alloc] init];
  56. model.name = name;
  57. model.iconName = icon;
  58. if ([name isEqualToString:NSLocalizedString(@"more_add_bookmark",nil)] ||
  59. [name isEqualToString:NSLocalizedString(@"more_refresh",nil)] ||
  60. [name isEqualToString:NSLocalizedString(@"more_share",nil)]) {
  61. model.isSetUnavailable = self.isSetUnavailable;
  62. }else {
  63. model.isSetUnavailable = NO;
  64. }
  65. [self.dataSource addObject:model];
  66. }
  67. [self.collectionView reloadData];
  68. }
  69. #pragma mark UICollectionViewDelegate, UICollectionViewDataSource
  70. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  71. return self.dataSource.count;
  72. }
  73. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  74. HWToolListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HWToolListCell" forIndexPath:indexPath];
  75. BaseModel *model = self.dataSource[indexPath.item];
  76. cell.model = model;
  77. return cell;
  78. }
  79. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  80. BaseModel *model = self.dataSource[indexPath.item];
  81. // if ([model.name isEqualToString:@"添加书签"]) {
  82. // HLog(@"添加书签");
  83. // }else if ([model.name isEqualToString:@"书签"]) {
  84. // HLog(@"书签");
  85. // }else if ([model.name isEqualToString:@"历史"]) {
  86. // HLog(@"历史");
  87. // }else if ([model.name isEqualToString:@"设置"]) {
  88. // HLog(@"设置");
  89. // }else if ([model.name isEqualToString:@"无痕"]) {
  90. // HLog(@"无痕");
  91. // }else if ([model.name isEqualToString:@"刷新"]) {
  92. // HLog(@"刷新");
  93. // }else if ([model.name isEqualToString:@"分享"]) {
  94. // HLog(@"分享");
  95. // }
  96. if ([_delegate respondsToSelector:@selector(toolDidClickItem:)]) {
  97. [_delegate toolDidClickItem:model.name];
  98. }
  99. [self dismissViewControllerAnimated:YES completion:^{
  100. }];
  101. }
  102. #pragma mark 点击事件
  103. - (void)bgViewClick {
  104. [self dismissViewControllerAnimated:YES completion:^{
  105. }];
  106. }
  107. #pragma mark 懒加载
  108. - (NSMutableArray *)dataSource {
  109. if (!_dataSource) {
  110. _dataSource = [NSMutableArray array];
  111. }
  112. return _dataSource;
  113. }
  114. @end