This commit is contained in:
2025-12-08 16:39:47 +08:00
parent 0a1c30f669
commit fd8c08316b
30 changed files with 306 additions and 85 deletions

View File

@@ -0,0 +1,20 @@
//
// KBMyMainModel.h
// keyBoard
//
// Created by Mac on 2025/12/8.
//
#import <Foundation/Foundation.h>
#import "KBTagItemModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface KBMyMainModel : NSObject
@property (nonatomic, copy) NSString *message;
@property (nonatomic, assign) NSInteger code;
@property (nonatomic, strong) NSArray <KBTagItemModel *>*data;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,16 @@
//
// KBMyMainModel.m
// keyBoard
//
// Created by Mac on 2025/12/8.
//
#import "KBMyMainModel.h"
@implementation KBMyMainModel
+ (NSDictionary *)mj_objectClassInArray {
// JSON: { "id": 0, "tagName": "xxx" }
// Model: tagId / tagName
return @{@"data":[KBTagItemModel class]};
}
@end

View File

@@ -0,0 +1,20 @@
//
// KBTagItemModel.h
// keyBoard
//
// Created by Mac on 2025/12/8.
// 键盘里的model
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface KBTagItemModel : NSObject
@property (nonatomic, assign) NSInteger tagId; // 对应 JSON 里的 id
@property (nonatomic, assign) NSInteger characterId; // 对应 JSON 里的 id
@property (nonatomic, copy) NSString *characterName;
@property (nonatomic, copy) NSString *emoji;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,36 @@
//
// KBTagItemModel.m
// keyBoard
//
// Created by Mac on 2025/12/8.
//
#import "KBTagItemModel.h"
#import <MJExtension/MJExtension.h>
@implementation KBTagItemModel
// null -> @""
//- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
// if (oldValue == nil || [oldValue isKindOfClass:[NSNull class]]) {
// return @""; // null ""
// }
// return oldValue;
//}
- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property{
if (oldValue == nil || [oldValue isKindOfClass:[NSNull class]]) {
return @""; // null ""
}
return oldValue;
}
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
// JSON: { "id": 0, "tagName": "xxx" }
// Model: tagId / tagName
return @{
@"tagId" : @"id",
};
}
@end

View File

@@ -45,7 +45,7 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
self.viewModel = [[KBMyVM alloc] init];
self.view.backgroundColor = [UIColor colorWithHex:0xF6F8F9];
self.kb_navView.backgroundColor = [UIColor clearColor];
self.kb_titleLabel.text = @"My KeyBoard";
self.kb_titleLabel.text = KBLocalized(@"My Keyboard");
//
[self.view insertSubview:self.bgImageView belowSubview:self.kb_navView];
[self.view addSubview:self.sheetView];

View File

@@ -10,6 +10,8 @@
#import "KBNetworkManager.h"
#import "KBUser.h"
#import "KBAPI.h"
//#import <MJExtension/MJExtension.h>
#import "KBMyMainModel.h"
NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNotification";
@@ -62,6 +64,15 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
}
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
if ([jsonOrData isKindOfClass:[NSDictionary class]]) {
/// MJNull 💥
KBMyMainModel *mainModel = [KBMyMainModel mj_objectWithKeyValues:jsonOrData];
NSDictionary *dict = [mainModel mj_keyValues];
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
[sharedDefaults setObject:dict forKey:AppGroup_MyKbJson];
[sharedDefaults synchronize];
KBLOG(@"[MainApp] 写入完成");
}
if (![dataObj isKindOfClass:[NSArray class]]) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
code:KBNetworkErrorInvalidResponse