123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // HWToolViewController.m
- // Private-X
- //
- // Created by 余衡武 on 2022/3/21.
- //
- #import "HWToolViewController.h"
- #import "HWToolListCell.h"
- @interface HWToolViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (weak, nonatomic) IBOutlet UIView *bigBGView;
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
- @property (strong, nonatomic) NSMutableArray *dataSource;
- @end
- @implementation HWToolViewController
- #pragma mark 生命周期
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self drawView];
- [self getData];
- }
- #pragma mark UI布局
- - (void)drawView {
-
- self.bgView.backgroundColor = HW1C1C1EColor;
- self.bgView.layer.cornerRadius = 10;
- self.bgView.layer.masksToBounds = YES;
- [self.bigBGView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewClick)]];
-
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.backgroundColor = [UIColor clearColor];
- [self.collectionView registerNib:[UINib nibWithNibName:@"HWToolListCell" bundle:nil] forCellWithReuseIdentifier:@"HWToolListCell"];
-
- UICollectionViewFlowLayout *dataLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
- CGFloat W = (SCREEN_W - 12*2)*0.25;
- CGFloat H = 88;
- dataLayout.itemSize = CGSizeMake(W, H);
- dataLayout.minimumLineSpacing = 0;
- dataLayout.minimumInteritemSpacing = 0;
- dataLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- }
- #pragma mark 获取数据
- - (void)getData {
-
- [self.dataSource removeAllObjects];
-
- NSArray *nameArr;
- NSArray *iconArr;
- if (self.isSetUnavailable) {
- 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)];
- iconArr = @[@"tianjia_hui_icon", @"shuqian_icon", @"lishi_icon", @"shezhi_icon", @"wuheng_icon", @"shuaxin_hui_icon", @"fenxiang_hui_icon"];
- }else {
- 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)];
- iconArr = @[@"tianjia_icon", @"shuqian_icon", @"lishi_icon", @"shezhi_icon", @"wuheng_icon", @"shuaxin_icon", @"fenxiang_icon"];
- }
- for (int i = 0; i < nameArr.count; i++) {
- NSString *name = nameArr[i];
- NSString *icon = iconArr[i];
- BaseModel *model = [[BaseModel alloc] init];
- model.name = name;
- model.iconName = icon;
-
- if ([name isEqualToString:NSLocalizedString(@"more_add_bookmark",nil)] ||
- [name isEqualToString:NSLocalizedString(@"more_refresh",nil)] ||
- [name isEqualToString:NSLocalizedString(@"more_share",nil)]) {
- model.isSetUnavailable = self.isSetUnavailable;
- }else {
- model.isSetUnavailable = NO;
- }
-
- [self.dataSource addObject:model];
- }
-
- [self.collectionView reloadData];
- }
- #pragma mark UICollectionViewDelegate, UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- HWToolListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HWToolListCell" forIndexPath:indexPath];
- BaseModel *model = self.dataSource[indexPath.item];
- cell.model = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- BaseModel *model = self.dataSource[indexPath.item];
- // if ([model.name isEqualToString:@"添加书签"]) {
- // HLog(@"添加书签");
- // }else if ([model.name isEqualToString:@"书签"]) {
- // HLog(@"书签");
- // }else if ([model.name isEqualToString:@"历史"]) {
- // HLog(@"历史");
- // }else if ([model.name isEqualToString:@"设置"]) {
- // HLog(@"设置");
- // }else if ([model.name isEqualToString:@"无痕"]) {
- // HLog(@"无痕");
- // }else if ([model.name isEqualToString:@"刷新"]) {
- // HLog(@"刷新");
- // }else if ([model.name isEqualToString:@"分享"]) {
- // HLog(@"分享");
- // }
-
- if ([_delegate respondsToSelector:@selector(toolDidClickItem:)]) {
- [_delegate toolDidClickItem:model.name];
- }
-
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
- }
- #pragma mark 点击事件
- - (void)bgViewClick {
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
- }
- #pragma mark 懒加载
- - (NSMutableArray *)dataSource {
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- @end
|