1
This commit is contained in:
@@ -41,7 +41,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
/// 排名序号(1、2、3...)
|
/// 排名序号(1、2、3...)
|
||||||
@property (nonatomic, assign) NSInteger rank;
|
@property (nonatomic, assign) NSInteger rank;
|
||||||
|
|
||||||
/// 本地字段:是否已添加到键盘(仅客户端使用)
|
|
||||||
@property (nonatomic, assign) BOOL added;
|
@property (nonatomic, assign) BOOL added;
|
||||||
|
|
||||||
@property (nonatomic, copy) NSString *emoji;
|
@property (nonatomic, copy) NSString *emoji;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#import "HomeRankDetailPopView.h"
|
#import "HomeRankDetailPopView.h"
|
||||||
#import "LSTPopView.h"
|
#import "LSTPopView.h"
|
||||||
#import <HWPanModal/HWPanModal.h>
|
#import <HWPanModal/HWPanModal.h>
|
||||||
|
#import "KBMyVM.h" // 用户人设变更通知
|
||||||
|
|
||||||
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
|
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
|
||||||
|
|
||||||
@@ -53,9 +54,24 @@
|
|||||||
|
|
||||||
// 请求排行榜数据
|
// 请求排行榜数据
|
||||||
self.homeVM = [KBHomeVM new];
|
self.homeVM = [KBHomeVM new];
|
||||||
|
[self kb_reloadRankListWithShowHUD:YES];
|
||||||
|
|
||||||
|
// 监听“用户人设删除”通知,用于同步更新加号按钮状态
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(kb_onUserCharacterDeleted:)
|
||||||
|
name:KBUserCharacterDeletedNotification
|
||||||
|
object:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 拉取首页排行榜数据
|
||||||
|
- (void)kb_reloadRankListWithShowHUD:(BOOL)needShow {
|
||||||
KBWeakSelf
|
KBWeakSelf
|
||||||
[self.homeVM fetchRankListWithParams:nil
|
[self.homeVM fetchRankListWithParams:nil
|
||||||
needShow:YES
|
needShow:needShow
|
||||||
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
// 错误提示已经在 VM 内部通过 HUD 处理,这里不再重复提示
|
// 错误提示已经在 VM 内部通过 HUD 处理,这里不再重复提示
|
||||||
@@ -104,6 +120,26 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 收到“用户人设删除”通知:如果当前列表包含该 id,则刷新接口数据
|
||||||
|
- (void)kb_onUserCharacterDeleted:(NSNotification *)note {
|
||||||
|
NSNumber *cid = note.userInfo[@"characterId"];
|
||||||
|
if (!cid) { return; }
|
||||||
|
NSInteger targetId = cid.integerValue;
|
||||||
|
if (targetId <= 0) { return; }
|
||||||
|
|
||||||
|
BOOL contains = NO;
|
||||||
|
for (KBCharacter *c in self.allCharacters) {
|
||||||
|
if (c.characterId.integerValue == targetId) {
|
||||||
|
contains = YES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!contains) { return; }
|
||||||
|
|
||||||
|
// 刷新首页排行榜数据(不需要 HUD)
|
||||||
|
[self kb_reloadRankListWithShowHUD:NO];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - UITableViewDataSource
|
#pragma mark - UITableViewDataSource
|
||||||
|
|
||||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#import "HomeRankCardCell.h"
|
#import "HomeRankCardCell.h"
|
||||||
#import "KBHomeVM.h"
|
#import "KBHomeVM.h"
|
||||||
#import "KBCharacter.h"
|
#import "KBCharacter.h"
|
||||||
|
#import "KBMyVM.h" // 引入用户人设变更通知
|
||||||
|
|
||||||
@interface HomeRankContentVC ()
|
@interface HomeRankContentVC ()
|
||||||
@property (nonatomic, copy, nullable) NSString *tagId; // 当前标签 id
|
@property (nonatomic, copy, nullable) NSString *tagId; // 当前标签 id
|
||||||
@@ -46,14 +47,29 @@
|
|||||||
make.edges.equalTo(self.view);
|
make.edges.equalTo(self.view);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
// 监听“用户人设删除”通知,用于同步更新加号按钮状态
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(kb_onUserCharacterDeleted:)
|
||||||
|
name:KBUserCharacterDeletedNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
// 加载当前 tag 下的角色列表
|
// 加载当前 tag 下的角色列表
|
||||||
[self loadCharactersForCurrentTag];
|
[self loadCharactersForCurrentTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)loadCharactersForCurrentTag {
|
- (void)loadCharactersForCurrentTag {
|
||||||
|
[self kb_requestCharactersWithShowHUD:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内部通用方法:根据 tag 请求角色列表
|
||||||
|
- (void)kb_requestCharactersWithShowHUD:(BOOL)needShow {
|
||||||
KBWeakSelf
|
KBWeakSelf
|
||||||
[self.homeVM fetchRankListByTagId:self.tagId
|
[self.homeVM fetchRankListByTagId:self.tagId
|
||||||
needShow:YES
|
needShow:needShow
|
||||||
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return;
|
return;
|
||||||
@@ -63,6 +79,26 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 收到“用户人设删除”通知:如果当前列表包含该 id,则刷新接口数据
|
||||||
|
- (void)kb_onUserCharacterDeleted:(NSNotification *)note {
|
||||||
|
NSNumber *cid = note.userInfo[@"characterId"];
|
||||||
|
if (!cid) { return; }
|
||||||
|
NSInteger targetId = cid.integerValue;
|
||||||
|
if (targetId <= 0) { return; }
|
||||||
|
|
||||||
|
BOOL contains = NO;
|
||||||
|
for (KBCharacter *c in self.characters) {
|
||||||
|
if (c.characterId.integerValue == targetId) {
|
||||||
|
contains = YES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!contains) { return; }
|
||||||
|
|
||||||
|
// 后端会根据最新的人设状态返回 added 字段,刷新本页 UI
|
||||||
|
[self kb_requestCharactersWithShowHUD:NO];
|
||||||
|
}
|
||||||
|
|
||||||
- (UICollectionView *)collectionView{
|
- (UICollectionView *)collectionView{
|
||||||
if (!_collectionView) {
|
if (!_collectionView) {
|
||||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/// 用户人设发生变更(例如从“我的键盘”中删除)时的进程内通知。
|
||||||
|
/// userInfo:
|
||||||
|
/// @"characterId" : NSNumber(NSInteger) 被删除或变更的人设 id
|
||||||
|
extern NSString * const KBUserCharacterDeletedNotification;
|
||||||
|
|
||||||
typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error);
|
typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error);
|
||||||
typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray, NSError *_Nullable error);
|
typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray, NSError *_Nullable error);
|
||||||
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
|
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#import "KBUser.h"
|
#import "KBUser.h"
|
||||||
#import "KBAPI.h"
|
#import "KBAPI.h"
|
||||||
|
|
||||||
|
NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNotification";
|
||||||
|
|
||||||
@implementation KBMyVM
|
@implementation KBMyVM
|
||||||
|
|
||||||
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion {
|
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion {
|
||||||
@@ -111,7 +113,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *params = @{@"id": characterId};
|
NSDictionary *params = @{@"id": characterId};
|
||||||
[KBHUD show];
|
|
||||||
[[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER
|
[[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER
|
||||||
parameters:params
|
parameters:params
|
||||||
headers:nil
|
headers:nil
|
||||||
@@ -119,9 +120,20 @@
|
|||||||
completion:^(NSDictionary *jsonOrData,
|
completion:^(NSDictionary *jsonOrData,
|
||||||
NSURLResponse * _Nullable response,
|
NSURLResponse * _Nullable response,
|
||||||
NSError * _Nullable error) {
|
NSError * _Nullable error) {
|
||||||
[KBHUD dismiss];
|
BOOL success = (error == nil);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
// 通知 App 内其他页面(如 HomeRankContentVC / HomeHotVC)该人设已被删除
|
||||||
|
NSDictionary *info = @{@"characterId": characterId ?: @0};
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:KBUserCharacterDeletedNotification
|
||||||
|
object:nil
|
||||||
|
userInfo:info];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (completion) {
|
if (completion) {
|
||||||
completion(error == nil, error);
|
completion(success, error);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user