This commit is contained in:
2025-12-03 19:19:20 +08:00
parent b00283cd96
commit 716f91bdd0
8 changed files with 147 additions and 47 deletions

View File

@@ -12,35 +12,55 @@
// Cell
#import "HomeRankCardCell.h"
#import "KBHomeVM.h"
#import "KBCharacter.h"
@interface HomeRankContentVC ()
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; //
@property (nonatomic, copy, nullable) NSString *tagId; // id
@property (nonatomic, strong) KBHomeVM *homeVM;
@property (nonatomic, strong) NSArray<KBCharacter *> *characters; //
@end
@implementation HomeRankContentVC
- (instancetype)initWithTagId:(NSString *)tagId {
if (self = [super init]) {
_tagId = [tagId copy];
}
return self;
}
- (instancetype)init {
return [self initWithTagId:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = COLOR_WITH_RGB(246/255.0, 253/255.0, 249/255.0, 1.0); // 绿
//
self.dataSource = @[
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)}
];
self.characters = @[];
self.homeVM = [KBHomeVM new];
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// tag
[self loadCharactersForCurrentTag];
}
- (void)loadCharactersForCurrentTag {
KBWeakSelf
[self.homeVM fetchRankListByTagId:self.tagId
needShow:YES
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
if (error) {
return;
}
weakSelf.characters = list ?: @[];
[weakSelf.collectionView reloadData];
}];
}
- (UICollectionView *)collectionView{
@@ -66,26 +86,21 @@
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSource.count;
return self.characters.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
HomeRankCardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeRankCardCell" forIndexPath:indexPath];
NSDictionary *d = self.dataSource[indexPath.item];
BOOL added = [d[@"added"] boolValue];
[cell configureWithTitle:d[@"title"]
desc:d[@"desc"]
people:d[@"people"]
added:added];
KBCharacter *c = self.characters[indexPath.item];
// cell cell
cell.character = c;
KBWeakSelf
cell.onTapAction = ^{
// /
NSMutableArray *m = [weakSelf.dataSource mutableCopy];
NSMutableDictionary *md = [m[indexPath.item] mutableCopy];
BOOL cur = [md[@"added"] boolValue];
md[@"added"] = @(!cur);
m[indexPath.item] = md;
weakSelf.dataSource = [m copy];
// / UI
NSMutableArray *m = [weakSelf.characters mutableCopy];
KBCharacter *mc = m[indexPath.item];
mc.added = !mc.added;
weakSelf.characters = [m copy];
[weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]];
};
return cell;
@@ -105,13 +120,13 @@
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// ->
NSDictionary *d = self.dataSource[indexPath.item];
KBCharacter *c = self.characters[indexPath.item];
//
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
NSString *title = d[@"title"] ?: @"High EQ";
NSString *people = d[@"people"] ?: @"Download: 1 Million";
NSString *title = c.characterName ?: @"High EQ";
NSString *people = c.download ?: @"Download: 1 Million";
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; //
[content configWithAvatar:nil title:title download:people desc:desc];