Просмотр исходного кода

Create function to get current text color

master
lint 3 лет назад
Родитель
Сommit
50366559da
2 измененных файлов: 85 добавлений и 149 удалений
  1. +2
    -1
      tweak/Reddit.h
  2. +83
    -148
      tweak/Reddit.xm

+ 2
- 1
tweak/Reddit.h Просмотреть файл

@@ -58,6 +58,7 @@
@interface CommentTreeHeaderNode
@property(strong, nonatomic) id commentTreeNode;
- (void)updateContentViewsForData:(id)arg1;
- (void)configureNodes;
@end
@interface CommentTreeCommandBarNode
@@ -156,7 +157,7 @@
- (id)initWithConfig:(id)arg1;
@end
@interface ThemeManager
@interface ThemeManager : NSObject
+ (id)sharedManager;

+ 83
- 148
tweak/Reddit.xm Просмотреть файл

@@ -12,6 +12,87 @@ int secondVersionPart = 0;
%group Reddit_v4_current
UIColor * getCurrentTextColor() {
ThemeManager *themeManager;
id isNightMode;
UIColor *textColor;
if (firstVersionPart == 2020) {
if (secondVersionPart <= 40) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AppSettings *appSettings = [%c(AppSettings) sharedSettings];
AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
if (sysInterfaceStyle == UIUserInterfaceStyleDark){
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
} else {
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
}
[themeManager release];
} else {
RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
textColor = [[themeGuidance currentTheme] bodyTextColor];
}
} else {
if (secondVersionPart >= 45) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (secondVersionPart >= 37) {
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
}
return textColor;
}
%hook CommentTreeNode
%property(assign,nonatomic)id commentTreeHeaderNode;
%property(assign,nonatomic)id commentTreeCommandBarNode;
@@ -95,83 +176,9 @@ int secondVersionPart = 0;
NSString *author = data[@"author"];
NSString *body = data[@"body"];
UIColor *textColor = getCurrentTextColor();
NSMutableAttributedString *bodyMutableAttributedText;
id themeManager;
id isNightMode;
id textColor;
if (firstVersionPart == 2020) {
if (secondVersionPart <= 40) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AppSettings *appSettings = [%c(AppSettings) sharedSettings];
AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
if (sysInterfaceStyle == UIUserInterfaceStyleDark){
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
} else {
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
}
[themeManager release];
} else {
RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
textColor = [[themeGuidance currentTheme] bodyTextColor];
}
} else {
if (secondVersionPart >= 45) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (secondVersionPart >= 37) {
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
}
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
@@ -292,79 +299,7 @@ int secondVersionPart = 0;
NSString *author = data[@"author"];
NSString *body = data[@"body"];
id themeManager;
id isNightMode;
id textColor;
if (firstVersionPart == 2020) {
if (secondVersionPart <= 40) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else {
RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
textColor = [[themeGuidance currentTheme] bodyTextColor];
}
} else {
if (secondVersionPart >= 45) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (secondVersionPart >= 37) {
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
}
/*
NSMutableAttributedString *bodyMutableAttributedText;
if ((firstVersionPart == 2020 && secondVersionPart <= 41) || firstVersionPart != 2020) {
bodyMutableAttributedText = [[post previewFeedPostTextString] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
} else {
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
}
*/
UIColor *textColor = getCurrentTextColor();
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];

Загрузка…
Отмена
Сохранить