代码整理
This commit is contained in:
@@ -45,22 +45,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, copy) NSString *zipMd5;
|
||||
@property (nonatomic, strong) NSURL *zipUrl;
|
||||
|
||||
///添加心跳定时器
|
||||
- (void)addHeartBratTimer;
|
||||
///重置心跳定时器
|
||||
- (void)resetHeartBratTimer;
|
||||
|
||||
|
||||
- (UIColor *)bgColor;
|
||||
- (NSString *)tabName:(NSInteger)tabIndex;
|
||||
|
||||
|
||||
- (NSString *)_tabNormalImage:(NSInteger)tabIndex;
|
||||
- (NSString *)_tabSelectedImage:(NSInteger)tabIndex;
|
||||
- (NSString *)tabNormalImage:(NSInteger)tabIndex;
|
||||
- (NSString *)tabSelectedImage:(NSInteger)tabIndex;
|
||||
- (UIImage *)tabNormalImageImage:(NSInteger)tabIndex;
|
||||
- (UIImage *)tabSelectedImageImage:(NSInteger)tabIndex;
|
||||
- (NSString *)loadDefaultNormalTabImageName:(NSInteger)tabIndex;
|
||||
- (NSString *)loadDefaultSelectedTabImageName:(NSInteger)tabIndex;
|
||||
- (NSString *)loadConfigNormalTabImagePath:(NSInteger)tabIndex;
|
||||
- (NSString *)loadConfigSelectedTabImagePath:(NSInteger)tabIndex;
|
||||
|
||||
@property (nonatomic, copy) NSString *reloadNavigationAreaImageKey;
|
||||
@property (nonatomic, copy) NSString *reloadViewBackgroundColorKey;
|
||||
@@ -68,11 +59,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, strong) UIImage *navigationAreaBG;
|
||||
@property (nonatomic, strong) UIImage *tabbarBGImage;
|
||||
|
||||
- (void)loadTabImages;
|
||||
|
||||
@property (nonatomic, copy) void(^updateTabbarBG)(UIImage *image);
|
||||
@property (nonatomic, copy) void(^updateNormalTabImage)(UIImage *normalImage, NSInteger index);
|
||||
@property (nonatomic, copy) void(^updateSelectedTabImage)(UIImage *selectImage, NSInteger index);
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -17,10 +17,7 @@
|
||||
#import "XPWeakTimer.h"
|
||||
#import "Api+Main.h"
|
||||
|
||||
@interface ClientConfig ()
|
||||
{
|
||||
NSTimer * timer;
|
||||
}
|
||||
@interface ClientConfig ()
|
||||
///重试的次数 10次 如果你还是失败的话 那就算了 没办法了
|
||||
@property (nonatomic,assign) int retryCount;
|
||||
|
||||
@@ -31,9 +28,6 @@
|
||||
@property (nonatomic, strong) NetImageView *tabbarBGImageLoader;
|
||||
@property (nonatomic, strong) NetImageView *navigationAreaBGImageLoader;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *downloadedTabNormalImages;
|
||||
@property (nonatomic, strong) NSMutableArray *downloadedTabSelectedImage;
|
||||
|
||||
@property (nonatomic, assign) BOOL isLoading;
|
||||
|
||||
@end
|
||||
@@ -48,9 +42,6 @@
|
||||
config.isTF = [ClientConfig isTestFlight];
|
||||
config.reloadNavigationAreaImageKey = @"今天光线很好";
|
||||
config.reloadViewBackgroundColorKey = @"年轻人买不起:美国买房平均年龄飙升至56岁";
|
||||
|
||||
config.downloadedTabNormalImages = @[].mutableCopy;
|
||||
config.downloadedTabSelectedImage = @[].mutableCopy;
|
||||
});
|
||||
return config;
|
||||
}
|
||||
@@ -116,8 +107,10 @@
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadAfterLoadConfig" object:nil];
|
||||
} else {
|
||||
if (self.retryCount < 10) {
|
||||
[self clientInit];
|
||||
self.retryCount+=1;
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
self.retryCount+=1;
|
||||
[self clientInit];
|
||||
});
|
||||
}
|
||||
}
|
||||
}];
|
||||
@@ -130,6 +123,7 @@
|
||||
if (code == 200) {
|
||||
self.uiSetting = [AppUISetting modelWithJSON:data.data[@"appUiSetting"]];
|
||||
}
|
||||
// 无论如何都开始构建 tab image path 数组并进入首页
|
||||
[self prepareCustomUI];
|
||||
if (finish) {
|
||||
finish();
|
||||
@@ -137,15 +131,6 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadTabImages {
|
||||
if (self.isLoading) {
|
||||
return;
|
||||
}
|
||||
self.isLoading = YES;
|
||||
[self loadNormalTabImage:0];
|
||||
[self loadSelectedTabImage:0];
|
||||
}
|
||||
|
||||
- (void)prepareCustomUI {
|
||||
NSArray *defaultArray = @[@"", @"", @"", @"", @""];
|
||||
self.normalTabImageSource = defaultArray.mutableCopy;
|
||||
@@ -225,124 +210,11 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadNormalTabImage:(NSInteger)index {
|
||||
NSLog(@" ------------------ 666 ---------------, %ld, %s", (long)index, __FUNCTION__);
|
||||
if (index >= self.normalTabImageSource.count || index == 5) {
|
||||
self.isLoading = NO;
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *normalURLString = self.normalTabImageSource[index];
|
||||
if ([NSString isEmpty:normalURLString] && self.updateNormalTabImage) {
|
||||
UIImage *image = [UIImage imageNamed:[self _tabNormalImage:index]];
|
||||
self.updateNormalTabImage([image resizeTo:CGSizeMake(40, 40)], index);
|
||||
[self loadNormalTabImage:index + 1];
|
||||
return;
|
||||
}
|
||||
__block UIImage *normalImage = nil;
|
||||
|
||||
if (!_normalTabImageLoader) {
|
||||
_normalTabImageLoader = [[NetImageView alloc] init];
|
||||
}
|
||||
@kWeakify(self);
|
||||
[self.normalTabImageLoader loadImageWithUrl:normalURLString
|
||||
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
|
||||
NSLog(@" ------------------ 777 ---------------, %ld", (long)index);
|
||||
normalImage = [image resizeTo:CGSizeMake(40, 40)];
|
||||
@kStrongify(self);
|
||||
[self.downloadedTabNormalImages addObject:normalImage];
|
||||
if (normalImage && self.updateNormalTabImage) {
|
||||
self.updateNormalTabImage(normalImage,
|
||||
index);
|
||||
}
|
||||
[self loadNormalTabImage:index + 1];
|
||||
}
|
||||
fail:^(NSError * _Nonnull error) {
|
||||
NSLog(@" ------------------ 999 ---------------, %ld", (long)index);
|
||||
@kStrongify(self);
|
||||
if (self.updateNormalTabImage) {
|
||||
if (self.downloadedTabNormalImages.count >= index-1) {
|
||||
self.updateNormalTabImage([self.downloadedTabNormalImages xpSafeObjectAtIndex:index], index);
|
||||
} else {
|
||||
UIImage *image = [UIImage imageNamed:[self _tabNormalImage:index]];
|
||||
self.updateNormalTabImage([image resizeTo:CGSizeMake(40, 40)], index);
|
||||
}
|
||||
}
|
||||
[self loadNormalTabImage:index + 1];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadSelectedTabImage:(NSInteger)index {
|
||||
if (index >= self.selectedTabImageSource.count || index == 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.updateSelectedTabImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *selectedURLString = self.selectedTabImageSource[index];
|
||||
if ([NSString isEmpty:selectedURLString] && self.updateSelectedTabImage) {
|
||||
UIImage *image = [UIImage imageNamed:[self _tabSelectedImage:index]];
|
||||
self.updateSelectedTabImage([image resizeTo:CGSizeMake(40, 40)], index);
|
||||
[self loadSelectedTabImage:index + 1];
|
||||
return;
|
||||
}
|
||||
|
||||
__block UIImage *selectedImage = nil;
|
||||
|
||||
if (!_selectedTabImageLoader ) {
|
||||
_selectedTabImageLoader = [[NetImageView alloc] init];
|
||||
}
|
||||
|
||||
@kWeakify(self);
|
||||
[self.selectedTabImageLoader loadImageWithUrl:selectedURLString
|
||||
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
|
||||
@kStrongify(self);
|
||||
selectedImage = [image resizeTo:CGSizeMake(40, 40)];
|
||||
[self.downloadedTabSelectedImage addObject:selectedImage];
|
||||
if (selectedImage && self.updateSelectedTabImage) {
|
||||
self.updateSelectedTabImage(selectedImage,
|
||||
index);
|
||||
}
|
||||
[self loadSelectedTabImage:index + 1];
|
||||
}
|
||||
fail:^(NSError * _Nonnull error) {
|
||||
@kStrongify(self);
|
||||
if (self.updateSelectedTabImage) {
|
||||
if (self.downloadedTabSelectedImage.count >= index-1) {
|
||||
self.updateSelectedTabImage([self.downloadedTabSelectedImage xpSafeObjectAtIndex:index], index);
|
||||
} else {
|
||||
UIImage *image = [UIImage imageNamed:[self _tabSelectedImage:index]];
|
||||
self.updateSelectedTabImage([image resizeTo:CGSizeMake(40, 40)], index);
|
||||
}
|
||||
}
|
||||
[self loadSelectedTabImage:index + 1];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadBGColor {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:self.reloadNavigationAreaImageKey
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)addHeartBratTimer {
|
||||
if (timer) {
|
||||
return;
|
||||
}
|
||||
timer = [XPWeakTimer scheduledTimerWithTimeInterval:30 block:^(id userInfo) {
|
||||
[Api requestClientHeartBrat:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
}];
|
||||
} userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)resetHeartBratTimer {
|
||||
if (timer) {
|
||||
timer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIColor *)bgColor {
|
||||
if (self.uiSetting && ![NSString isEmpty:self.uiSetting.backgroundColor]) {
|
||||
return [DJDKMIMOMColor colorWithHexString:self.uiSetting.backgroundColor];
|
||||
@@ -359,7 +231,7 @@
|
||||
YMLocalizedString(@"TabbarViewController5")][tabIndex];
|
||||
}
|
||||
|
||||
- (NSString *)_tabNormalImage:(NSInteger)tabIndex {
|
||||
- (NSString *)loadDefaultNormalTabImageName:(NSInteger)tabIndex {
|
||||
return @[@"tab_gameHome_normal",
|
||||
@"tab_gameHome_game_normal",
|
||||
@"tab_monents_normal",
|
||||
@@ -367,7 +239,7 @@
|
||||
@"tab_mine_normal"][tabIndex];
|
||||
}
|
||||
|
||||
- (NSString *)_tabSelectedImage:(NSInteger)tabIndex {
|
||||
- (NSString *)loadDefaultSelectedTabImageName:(NSInteger)tabIndex {
|
||||
return @[@"tab_gameHome_selected",
|
||||
@"tab_gameHome_game_selected",
|
||||
@"tab_monents_select",
|
||||
@@ -375,20 +247,12 @@
|
||||
@"tab_mine_selected"][tabIndex];
|
||||
}
|
||||
|
||||
- (NSString *)tabNormalImage:(NSInteger)tabIndex {
|
||||
- (NSString *)loadConfigNormalTabImagePath:(NSInteger)tabIndex {
|
||||
return [self.normalTabImageSource xpSafeObjectAtIndex:tabIndex];
|
||||
}
|
||||
|
||||
- (NSString *)tabSelectedImage:(NSInteger)tabIndex {
|
||||
- (NSString *)loadConfigSelectedTabImagePath:(NSInteger)tabIndex {
|
||||
return [self.selectedTabImageSource xpSafeObjectAtIndex:tabIndex];
|
||||
}
|
||||
|
||||
- (UIImage *)tabNormalImageImage:(NSInteger)tabIndex {
|
||||
return [self.downloadedTabNormalImages xpSafeObjectAtIndex:tabIndex];
|
||||
}
|
||||
|
||||
- (UIImage *)tabSelectedImageImage:(NSInteger)tabIndex {
|
||||
return [self.downloadedTabSelectedImage xpSafeObjectAtIndex:tabIndex];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -183,18 +183,6 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAnchorCardKey:) name:kTabShowAnchorCardKey object:nil];
|
||||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(switchLanguage:) name:@"kSwitchLanguage" object:nil];
|
||||
|
||||
[[ClientConfig shareConfig] setUpdateNormalTabImage:^(UIImage * _Nonnull normalImage, NSInteger index) {
|
||||
@kStrongify(self);
|
||||
BaseNavigationController *vc = [self.viewControllers xpSafeObjectAtIndex:index];
|
||||
vc.tabBarItem.image = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||
}];
|
||||
|
||||
[[ClientConfig shareConfig] setUpdateSelectedTabImage:^(UIImage * _Nonnull selectImage, NSInteger index) {
|
||||
// @kStrongify(self);
|
||||
// BaseNavigationController *vc = [self.viewControllers xpSafeObjectAtIndex:index];
|
||||
// vc.tabBarItem.selectedImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||
}];
|
||||
|
||||
[[ClientConfig shareConfig] setUpdateTabbarBG:^(UIImage * _Nonnull image) {
|
||||
@kStrongify(self);
|
||||
[self configTheme:image];
|
||||
@@ -798,8 +786,8 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
// 创建并设置标签栏项
|
||||
[viewControllers addObject:[self createTabBarItem:viewController
|
||||
title:[[ClientConfig shareConfig] tabName:i]
|
||||
image:[[ClientConfig shareConfig] _tabNormalImage:i]
|
||||
selectedImage:[[ClientConfig shareConfig] _tabSelectedImage:i]
|
||||
image:[[ClientConfig shareConfig] loadDefaultNormalTabImageName:i]
|
||||
selectedImage:[[ClientConfig shareConfig] loadDefaultSelectedTabImageName:i]
|
||||
index:i]];
|
||||
}
|
||||
// 设置视图控制器数组和默认选择项
|
||||
@@ -810,7 +798,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
if (isLogin) {
|
||||
for (int i = 0; i < self.viewControllers.count; i++) {
|
||||
UIViewController *itemVc = self.viewControllers[i];
|
||||
NSString *urlString = [[ClientConfig shareConfig] tabNormalImage:i];
|
||||
NSString *urlString = [[ClientConfig shareConfig] loadConfigNormalTabImagePath:i];
|
||||
if (![urlString hasPrefix:@"http"]) {
|
||||
continue;
|
||||
}
|
||||
@@ -839,7 +827,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
|
||||
for (int i = 0; i < self.viewControllers.count; i++) {
|
||||
UIViewController *itemVc = self.viewControllers[i];
|
||||
NSString *urlString = [[ClientConfig shareConfig] tabSelectedImage:i];
|
||||
NSString *urlString = [[ClientConfig shareConfig] loadConfigSelectedTabImagePath:i];
|
||||
if (![urlString hasPrefix:@"http"]) {
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user