1
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#define KB_API_CHARACTER_DETAIL @"/character/detail" // 人设详情
|
#define KB_API_CHARACTER_DETAIL @"/character/detail" // 人设详情
|
||||||
#define KB_API_CHARACTER_LISTBYUSER @"/character/listByUser" // 用户人设列表
|
#define KB_API_CHARACTER_LISTBYUSER @"/character/listByUser" // 用户人设列表
|
||||||
#define API_CHARACTER_UPDATE_USER_CHARTSORT @"/character/updateUserCharacterSort" // 更新用户人设排序
|
#define API_CHARACTER_UPDATE_USER_CHARTSORT @"/character/updateUserCharacterSort" // 更新用户人设排序
|
||||||
|
#define API_CHARACTER_DEL_USER_CHARACTER @"/character/delUserCharacter" // 删除用户人设
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
__weak typeof(self) weakSelf = self;
|
||||||
[self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray<KBCharacter *> * _Nonnull characterArray, NSError * _Nullable error) {
|
[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
|
#pragma mark - BMLongPressDragCellCollectionViewDataSource
|
||||||
|
|
||||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; }
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; }
|
||||||
@@ -148,6 +152,25 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
|||||||
if (!self) { return; }
|
if (!self) { return; }
|
||||||
NSIndexPath *tapIndexPath = [weakCV indexPathForCell:tappedCell];
|
NSIndexPath *tapIndexPath = [weakCV indexPathForCell:tappedCell];
|
||||||
if (!tapIndexPath) { return; }
|
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?")
|
[KBAlert confirmTitle:KBLocalized(@"Delete this tag?")
|
||||||
message:KBLocalized(@"This action cannot be undone")
|
message:KBLocalized(@"This action cannot be undone")
|
||||||
ok:KBLocalized(@"Confirm")
|
ok:KBLocalized(@"Confirm")
|
||||||
@@ -156,19 +179,37 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
|||||||
cancelColor:[UIColor blackColor]
|
cancelColor:[UIColor blackColor]
|
||||||
completion:^(BOOL ok) {
|
completion:^(BOOL ok) {
|
||||||
if (!ok) { return; }
|
if (!ok) { return; }
|
||||||
// 更新数据源并删除 item
|
|
||||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
// 若无法获取 id,仅做本地删除以保持 UI 一致
|
||||||
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
|
if (!characterId) {
|
||||||
if (tapIndexPath.item < section.count) {
|
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||||
[section removeObjectAtIndex:tapIndexPath.item];
|
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||||
[self.collectionView performBatchUpdates:^{
|
if (tapIndexPath.item < section.count) {
|
||||||
[self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]];
|
[section removeObjectAtIndex:tapIndexPath.item];
|
||||||
} completion:^(BOOL finished) {
|
[self.collectionView performBatchUpdates:^{
|
||||||
// 删除后同步最新排序到服务端
|
[self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]];
|
||||||
[self kb_updateUserCharacterSortWithShowHUD:NO];
|
} 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;
|
return cell;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray,
|
|||||||
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
|
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error);
|
typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
|
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
|
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
|
||||||
|
|
||||||
@interface KBMyVM : NSObject
|
@interface KBMyVM : NSObject
|
||||||
|
|
||||||
@@ -27,6 +28,9 @@ typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable
|
|||||||
/// 更新用户人设排序
|
/// 更新用户人设排序
|
||||||
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
||||||
completion:(KBUpdateCharacterSortCompletion)completion;
|
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{
|
- (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion{
|
||||||
KBWeakSelf;
|
KBWeakSelf;
|
||||||
|
|||||||
Reference in New Issue
Block a user