1
This commit is contained in:
@@ -74,6 +74,27 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
}];
|
||||
|
||||
// 使用后端真实数据初始化列表
|
||||
[self kb_reloadUserCharacters];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
// 隐藏系统导航栏
|
||||
// [self.navigationController setNavigationBarHidden:YES animated:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
// if (self.isMovingFromParentViewController || self.isBeingDismissed) {
|
||||
// [self.navigationController setNavigationBarHidden:NO animated:animated];
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
- (void)kb_reloadUserCharacters {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray<KBCharacter *> * _Nonnull characterArray, NSError * _Nullable error) {
|
||||
// 请求失败或无数据时,不再使用本地测试数据,直接清空展示
|
||||
@@ -112,23 +133,6 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
// 隐藏系统导航栏
|
||||
// [self.navigationController setNavigationBarHidden:YES animated:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
// if (self.isMovingFromParentViewController || self.isBeingDismissed) {
|
||||
// [self.navigationController setNavigationBarHidden:NO animated:animated];
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
#pragma mark - BMLongPressDragCellCollectionViewDataSource
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; }
|
||||
@@ -148,6 +152,25 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
if (!self) { return; }
|
||||
NSIndexPath *tapIndexPath = [weakCV indexPathForCell:tappedCell];
|
||||
if (!tapIndexPath) { return; }
|
||||
|
||||
// 取出将要删除的人设 id
|
||||
NSNumber *characterId = nil;
|
||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||
NSArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||
if (tapIndexPath.item < section.count) {
|
||||
NSDictionary *item = section[tapIndexPath.item];
|
||||
id cid = item[@"id"];
|
||||
if ([cid isKindOfClass:[NSNumber class]]) {
|
||||
characterId = (NSNumber *)cid;
|
||||
} else if ([cid isKindOfClass:[NSString class]]) {
|
||||
NSString *cidStr = (NSString *)cid;
|
||||
if (cidStr.length > 0) {
|
||||
characterId = @([cidStr integerValue]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[KBAlert confirmTitle:KBLocalized(@"Delete this tag?")
|
||||
message:KBLocalized(@"This action cannot be undone")
|
||||
ok:KBLocalized(@"Confirm")
|
||||
@@ -156,19 +179,37 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
cancelColor:[UIColor blackColor]
|
||||
completion:^(BOOL ok) {
|
||||
if (!ok) { return; }
|
||||
// 更新数据源并删除 item
|
||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||
if (tapIndexPath.item < section.count) {
|
||||
[section removeObjectAtIndex:tapIndexPath.item];
|
||||
[self.collectionView performBatchUpdates:^{
|
||||
[self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]];
|
||||
} completion:^(BOOL finished) {
|
||||
// 删除后同步最新排序到服务端
|
||||
[self kb_updateUserCharacterSortWithShowHUD:NO];
|
||||
}];
|
||||
|
||||
// 若无法获取 id,仅做本地删除以保持 UI 一致
|
||||
if (!characterId) {
|
||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||
if (tapIndexPath.item < section.count) {
|
||||
[section removeObjectAtIndex:tapIndexPath.item];
|
||||
[self.collectionView performBatchUpdates:^{
|
||||
[self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]];
|
||||
} completion:nil];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用删除接口,成功后刷新界面
|
||||
__weak typeof(self) weakSelf2 = self;
|
||||
[self.viewModel deleteUserCharacterWithId:characterId
|
||||
completion:^(BOOL success, NSError * _Nullable error) {
|
||||
__strong typeof(weakSelf2) strongSelf = weakSelf2;
|
||||
if (!strongSelf) { return; }
|
||||
|
||||
if (!success) {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
return;
|
||||
}
|
||||
|
||||
// 重新拉取用户人设列表,刷新 UI
|
||||
[strongSelf kb_reloadUserCharacters];
|
||||
}];
|
||||
}];
|
||||
};
|
||||
return cell;
|
||||
|
||||
@@ -16,6 +16,7 @@ typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray,
|
||||
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
|
||||
|
||||
@interface KBMyVM : NSObject
|
||||
|
||||
@@ -27,6 +28,9 @@ typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable
|
||||
/// 更新用户人设排序
|
||||
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
||||
completion:(KBUpdateCharacterSortCompletion)completion;
|
||||
/// 删除用户人设(/character/delUserCharacter)
|
||||
- (void)deleteUserCharacterWithId:(NSNumber *)characterId
|
||||
completion:(KBDeleteUserCharacterCompletion)completion;
|
||||
|
||||
|
||||
/// 上传头像
|
||||
|
||||
@@ -97,6 +97,35 @@
|
||||
}];
|
||||
}
|
||||
|
||||
/// 删除用户人设
|
||||
- (void)deleteUserCharacterWithId:(NSNumber *)characterId
|
||||
completion:(KBDeleteUserCharacterCompletion)completion {
|
||||
if (!characterId) {
|
||||
if (completion) {
|
||||
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||
code:KBNetworkErrorInvalidResponse
|
||||
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid parameter")}];
|
||||
completion(NO, e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *params = @{@"id": characterId};
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER
|
||||
parameters:params
|
||||
headers:nil
|
||||
autoShowBusinessError:YES
|
||||
completion:^(NSDictionary *jsonOrData,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
if (completion) {
|
||||
completion(error == nil, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/// 上传头像
|
||||
- (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion{
|
||||
KBWeakSelf;
|
||||
|
||||
Reference in New Issue
Block a user