Files
keyboard/keyBoard/Class/Home/VC/HomeRankVC.m

200 lines
7.7 KiB
Mathematica
Raw Normal View History

2025-11-06 14:02:22 +08:00
//
// HomeRankVC.m
// keyBoard
//
// Created by Mac on 2025/11/6.
//
#import "HomeRankVC.h"
2025-11-06 19:19:12 +08:00
#import "HomeRankContentVC.h"
2025-11-09 21:05:03 +08:00
#import "KBCategoryTitleImageView.h"
2025-12-03 19:00:55 +08:00
#import "KBHomeVM.h"
#import "KBTag.h"
2025-11-06 14:02:22 +08:00
2025-11-06 19:19:12 +08:00
@interface HomeRankVC ()<JXCategoryViewDelegate>
2025-12-03 19:00:55 +08:00
@property (nonatomic, strong) NSArray<NSString *> *titles;
@property (nonatomic, strong) NSArray<KBTag *> *tags;
2025-11-06 19:19:12 +08:00
@property (nonatomic, strong) JXCategoryTitleImageView *myCategoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic, assign) JXCategoryTitleImageType currentType;
2025-12-03 19:00:55 +08:00
@property (nonatomic, strong) KBHomeVM *homeVM;
2025-11-06 14:02:22 +08:00
@end
@implementation HomeRankVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
2025-11-11 14:02:36 +08:00
self.view.backgroundColor = [UIColor clearColor];
2025-12-03 19:00:55 +08:00
self.titles = @[];
2025-11-06 19:19:12 +08:00
[self.view addSubview:self.myCategoryView];
[self.view addSubview:self.listContainerView];
2025-11-07 15:03:45 +08:00
self.listContainerView.scrollView.scrollEnabled = false;
2025-11-06 19:19:12 +08:00
2025-12-03 19:00:55 +08:00
//
self.myCategoryView.cellBackgroundSelectedColor = [UIColor blackColor];
self.myCategoryView.cellBackgroundUnselectedColor = [UIColor colorWithHex:0xEAF8F4];
2025-11-07 21:57:42 +08:00
self.myCategoryView.titleColor = [UIColor colorWithHex:0x1B1F1A];
self.myCategoryView.titleSelectedColor = [UIColor whiteColor];
self.myCategoryView.titleFont = [UIFont systemFontOfSize:12];
2025-11-09 17:07:43 +08:00
//
self.myCategoryView.titleLabelZoomEnabled = NO; //
self.myCategoryView.titleLabelZoomScale = 1.0;
self.myCategoryView.cellWidthZoomEnabled = NO; // cell
self.myCategoryView.cellWidthZoomScale = 1.0;
2025-11-07 21:57:42 +08:00
self.myCategoryView.imageZoomEnabled = false;
2025-11-06 19:19:12 +08:00
self.myCategoryView.imageZoomScale = 1.3;
self.myCategoryView.averageCellSpacingEnabled = NO;
self.myCategoryView.cellBackgroundColorGradientEnabled = true;
self.myCategoryView.cellWidthIncrement = 20;
2025-12-03 19:00:55 +08:00
//
self.homeVM = [KBHomeVM new];
KBWeakSelf
[self.homeVM fetchTagListWithParams:nil
needShow:YES
completion:^(NSArray<KBTag *> * _Nullable list, NSError * _Nullable error) {
if (error) {
return;
}
weakSelf.tags = list ?: @[];
// titles 使 tagName
NSMutableArray<NSString *> *titles = [NSMutableArray array];
for (KBTag *tag in weakSelf.tags) {
NSString *name = tag.tagName ?: @"";
[titles addObject:name];
}
weakSelf.titles = [titles copy];
//
NSMutableArray *imageNames = [NSMutableArray array];
NSMutableArray *selectedImageNames = [NSMutableArray array];
for (NSInteger i = 0; i < weakSelf.titles.count; i++) {
[imageNames addObject:@"home_item_normal"];
[selectedImageNames addObject:@"home_item_selected"];
}
weakSelf.myCategoryView.titles = weakSelf.titles;
weakSelf.myCategoryView.imageInfoArray = imageNames;
weakSelf.myCategoryView.selectedImageInfoArray = selectedImageNames;
weakSelf.myCategoryView.loadImageBlock = ^(UIImageView *imageView, id info) {
NSString *imageName = info;
imageView.image = [UIImage imageNamed:imageName];
};
[weakSelf.myCategoryView reloadData];
[weakSelf.listContainerView reloadData];
}];
2025-11-06 19:19:12 +08:00
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.myCategoryView.frame = CGRectMake(0, 0, self.view.bounds.size.width, [self preferredCategoryViewHeight]);
self.listContainerView.frame = CGRectMake(0, [self preferredCategoryViewHeight], self.view.bounds.size.width, self.view.bounds.size.height - [self preferredCategoryViewHeight]);
}
//- (JXCategoryBaseView *)preferredCategoryView {
// return [[JXCategoryBaseView alloc] init];
//}
- (CGFloat)preferredCategoryViewHeight {
return 30;
2025-11-06 19:19:12 +08:00
}
- (void)configCategoryViewWithType:(JXCategoryTitleImageType)imageType {
self.currentType = imageType;
if ((NSInteger)imageType == 100) {
NSMutableArray *types = [NSMutableArray array];
for (int i = 0; i < self.titles.count; i++) {
if (i == 2) {
[types addObject:@(JXCategoryTitleImageType_OnlyImage)];
}else if (i == 4) {
[types addObject:@(JXCategoryTitleImageType_LeftImage)];
}else {
[types addObject:@(JXCategoryTitleImageType_OnlyTitle)];
}
}
self.myCategoryView.imageTypes = types;
}else {
NSMutableArray *types = [NSMutableArray array];
for (int i = 0; i < self.titles.count; i++) {
[types addObject:@(imageType)];
}
self.myCategoryView.imageTypes = types;
}
[self.myCategoryView reloadData];
}
//
- (JXCategoryTitleImageView *)myCategoryView {
if (!_myCategoryView) {
2025-11-09 21:05:03 +08:00
// Use our subclass so cells get a 4pt rounded background locally
_myCategoryView = (JXCategoryTitleImageView *)[[KBCategoryTitleImageView alloc] init];
2025-11-06 19:19:12 +08:00
_myCategoryView.delegate = self;
2025-11-09 21:05:03 +08:00
2025-11-06 19:19:12 +08:00
// !!!: categoryView
_myCategoryView.listContainer = self.listContainerView;
}
return _myCategoryView;
2025-11-06 14:02:22 +08:00
}
2025-11-06 19:19:12 +08:00
//
- (JXCategoryListContainerView *)listContainerView {
if (!_listContainerView) {
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
}
return _listContainerView;
}
#pragma mark - JXCategoryViewDelegate
//
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
NSLog(@"%@", NSStringFromSelector(_cmd));
2025-11-09 16:05:42 +08:00
// VC/ validListDict
id<JXCategoryListContentViewDelegate> list = self.listContainerView.validListDict[@(index)];
if ([list isKindOfClass:[HomeRankContentVC class]]) {
HomeRankContentVC *currentVC = (HomeRankContentVC *)list;
// collectionView
self.collectionView = currentVC.collectionView;
// TODO: currentVC
}
2025-11-06 19:19:12 +08:00
//
self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
//
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
NSLog(@"%@", NSStringFromSelector(_cmd));
}
#pragma mark - JXCategoryListContainerViewDelegate
//
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
// <JXCategoryListContentViewDelegate>
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
2025-12-03 19:19:20 +08:00
NSString *tagId = nil;
if (index >= 0 && index < self.tags.count) {
KBTag *tag = self.tags[index];
tagId = tag.tagId;
}
HomeRankContentVC *list = [[HomeRankContentVC alloc] initWithTagId:tagId];
2025-11-06 19:51:50 +08:00
self.collectionView = list.collectionView;
2025-11-06 19:19:12 +08:00
return list;
}
#pragma mark - TitleImageSettingViewControllerDelegate
2025-11-06 14:02:22 +08:00
2025-11-06 19:19:12 +08:00
- (void)titleImageSettingVCDidSelectedImageType:(JXCategoryTitleImageType)imageType {
[self configCategoryViewWithType:imageType];
2025-11-06 14:02:22 +08:00
}
@end