From 50366559da76cf10ea27f9a3cc12c8f59d2c4985 Mon Sep 17 00:00:00 2001 From: lint <47455468+lint@users.noreply.github.com> Date: Mon, 8 Feb 2021 14:33:18 -0500 Subject: [PATCH] Create function to get current text color --- tweak/Reddit.h | 3 +- tweak/Reddit.xm | 231 +++++++++++++++++------------------------------- 2 files changed, 85 insertions(+), 149 deletions(-) diff --git a/tweak/Reddit.h b/tweak/Reddit.h index 371659f..6cb3377 100755 --- a/tweak/Reddit.h +++ b/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; diff --git a/tweak/Reddit.xm b/tweak/Reddit.xm index 2c58e6f..8b80902 100755 --- a/tweak/Reddit.xm +++ b/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];