mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-05-16 04:52:33 +00:00
Redesign RootOptionsController.m
Made it so it’ll have better maintainability.
This commit is contained in:
parent
7b1a1a78b7
commit
fa2847dddf
1 changed files with 62 additions and 61 deletions
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
@interface RootOptionsController ()
|
@interface RootOptionsController ()
|
||||||
|
|
||||||
- (UIImage *)resizeImage:(UIImage *)image newSize:(CGSize)newSize;
|
|
||||||
@property (strong, nonatomic) UIButton *backButton;
|
@property (strong, nonatomic) UIButton *backButton;
|
||||||
@property (assign, nonatomic) UIUserInterfaceStyle pageStyle;
|
@property (assign, nonatomic) UIUserInterfaceStyle pageStyle;
|
||||||
|
|
||||||
|
|
@ -18,6 +17,11 @@
|
||||||
self.title = @"uYouEnhanced Extras Menu";
|
self.title = @"uYouEnhanced Extras Menu";
|
||||||
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"YTSans-Bold" size:22], NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"YTSans-Bold" size:22], NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
||||||
|
|
||||||
|
[self setupBackButton];
|
||||||
|
[self setupTableView];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setupBackButton {
|
||||||
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
NSBundle *backIcon = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"]];
|
NSBundle *backIcon = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"]];
|
||||||
UIImage *backImage = [UIImage imageNamed:@"Back.png" inBundle:backIcon compatibleWithTraitCollection:nil];
|
UIImage *backImage = [UIImage imageNamed:@"Back.png" inBundle:backIcon compatibleWithTraitCollection:nil];
|
||||||
|
|
@ -29,14 +33,10 @@
|
||||||
[self.backButton setFrame:CGRectMake(0, 0, 24, 24)];
|
[self.backButton setFrame:CGRectMake(0, 0, 24, 24)];
|
||||||
UIBarButtonItem *customBackButton = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
|
UIBarButtonItem *customBackButton = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
|
||||||
self.navigationItem.leftBarButtonItem = customBackButton;
|
self.navigationItem.leftBarButtonItem = customBackButton;
|
||||||
|
}
|
||||||
|
|
||||||
UITableViewStyle style;
|
- (void)setupTableView {
|
||||||
if (@available(iOS 13, *)) {
|
UITableViewStyle style = UITableViewStyleInsetGrouped;
|
||||||
style = UITableViewStyleInsetGrouped;
|
|
||||||
} else {
|
|
||||||
style = UITableViewStyleGrouped;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:style];
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:style];
|
||||||
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
|
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
self.tableView.dataSource = self;
|
self.tableView.dataSource = self;
|
||||||
|
|
@ -44,10 +44,10 @@
|
||||||
[self.view addSubview:self.tableView];
|
[self.view addSubview:self.tableView];
|
||||||
|
|
||||||
[NSLayoutConstraint activateConstraints:@[
|
[NSLayoutConstraint activateConstraints:@[
|
||||||
[self.tableView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
|
[self.tableView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||||
[self.tableView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor],
|
[self.tableView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||||||
[self.tableView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
|
[self.tableView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
||||||
[self.tableView.heightAnchor constraintEqualToAnchor:self.view.heightAnchor]
|
[self.tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,13 +64,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||||
if (section == 0) {
|
return (section == 0) ? 2 : 1;
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if (section == 1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
|
@ -78,55 +72,62 @@
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
||||||
|
|
||||||
if (cell == nil) {
|
if (cell == nil) {
|
||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
|
||||||
cell.textLabel.adjustsFontSizeToFitWidth = YES;
|
[self configureCell:cell atIndexPath:indexPath];
|
||||||
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
|
|
||||||
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
|
|
||||||
cell.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
|
|
||||||
cell.textLabel.textColor = [UIColor blackColor];
|
|
||||||
cell.detailTextLabel.textColor = [UIColor blackColor];
|
|
||||||
} else {
|
|
||||||
cell.backgroundColor = [UIColor colorWithRed:0.110 green:0.110 blue:0.118 alpha:1.0];
|
|
||||||
cell.textLabel.textColor = [UIColor whiteColor];
|
|
||||||
cell.textLabel.shadowColor = [UIColor blackColor];
|
|
||||||
cell.textLabel.shadowOffset = CGSizeMake(1.0, 1.0);
|
|
||||||
cell.detailTextLabel.textColor = [UIColor whiteColor];
|
|
||||||
}
|
|
||||||
if (indexPath.section == 0) {
|
|
||||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
||||||
if (indexPath.row == 0) {
|
|
||||||
cell.textLabel.text = @"Custom Theme Color";
|
|
||||||
cell.imageView.image = [UIImage systemImageNamed:@"slider.horizontal.3"];
|
|
||||||
cell.imageView.tintColor = cell.textLabel.textColor;
|
|
||||||
}
|
|
||||||
if (indexPath.row == 1) {
|
|
||||||
cell.textLabel.text = @"Custom Tint Color";
|
|
||||||
cell.imageView.image = [UIImage systemImageNamed:@"drop.fill"];
|
|
||||||
cell.imageView.tintColor = cell.textLabel.textColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (indexPath.section == 1) {
|
|
||||||
if (indexPath.row == 0) {
|
|
||||||
cell.textLabel.text = @"Clear Cache";
|
|
||||||
UILabel *cache = [[UILabel alloc] init];
|
|
||||||
cache.text = [self getCacheSize];
|
|
||||||
cache.textColor = [UIColor secondaryLabelColor];
|
|
||||||
cache.font = [UIFont systemFontOfSize:16];
|
|
||||||
cache.textAlignment = NSTextAlignmentRight;
|
|
||||||
[cache sizeToFit];
|
|
||||||
cell.accessoryView = cache;
|
|
||||||
cell.imageView.image = [UIImage systemImageNamed:@"trash"];
|
|
||||||
cell.imageView.tintColor = cell.textLabel.textColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
cell.textLabel.adjustsFontSizeToFitWidth = YES;
|
||||||
|
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
|
||||||
|
|
||||||
|
if (indexPath.section == 0) {
|
||||||
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||||
|
if (indexPath.row == 0) {
|
||||||
|
cell.textLabel.text = @"Custom Theme Color";
|
||||||
|
cell.detailTextLabel.text = @"You must go to uYouEnhanced settings and then go to 'Dark Mode' and set it to 'Custom Dark Mode' for it to work.";
|
||||||
|
cell.imageView.image = [UIImage systemImageNamed:@"slider.horizontal.3"];
|
||||||
|
}
|
||||||
|
if (indexPath.row == 1) {
|
||||||
|
cell.textLabel.text = @"Custom Tint Color";
|
||||||
|
cell.detailTextLabel.text = @"You must go to uYouEnhanced settings and have LowContrastMode enabled and then go to 'LowContrastMode Selector' and set it to 'Custom' for it to work.";
|
||||||
|
cell.imageView.image = [UIImage systemImageNamed:@"drop.fill"];
|
||||||
|
}
|
||||||
|
} else if (indexPath.section == 1) {
|
||||||
|
if (indexPath.row == 0) {
|
||||||
|
cell.textLabel.text = @"Clear Cache";
|
||||||
|
UILabel *cache = [[UILabel alloc] init];
|
||||||
|
cache.text = [self getCacheSize];
|
||||||
|
cache.textColor = [UIColor secondaryLabelColor];
|
||||||
|
cache.font = [UIFont systemFontOfSize:16];
|
||||||
|
cache.textAlignment = NSTextAlignmentRight;
|
||||||
|
[cache sizeToFit];
|
||||||
|
cell.accessoryView = cache;
|
||||||
|
cell.imageView.image = [UIImage systemImageNamed:@"trash"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[self applyColorSchemeForCell:cell];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applyColorSchemeForCell:(UITableViewCell *)cell {
|
||||||
|
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
|
||||||
|
cell.backgroundColor = [UIColor whiteColor];
|
||||||
|
cell.textLabel.textColor = [UIColor blackColor];
|
||||||
|
cell.detailTextLabel.textColor = [UIColor blackColor];
|
||||||
|
} else {
|
||||||
|
cell.backgroundColor = [UIColor colorWithRed:0.110 green:0.110 blue:0.118 alpha:1.0];
|
||||||
|
cell.textLabel.textColor = [UIColor whiteColor];
|
||||||
|
cell.detailTextLabel.textColor = [UIColor whiteColor];
|
||||||
|
}
|
||||||
|
cell.imageView.tintColor = cell.textLabel.textColor;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSString *)getCacheSize {
|
- (NSString *)getCacheSize {
|
||||||
NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
|
NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
|
||||||
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:cachePath error:nil];
|
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:cachePath error:nil];
|
||||||
|
|
||||||
unsigned long long int folderSize = 0;
|
unsigned long long int folderSize = 0;
|
||||||
for (NSString *fileName in filesArray) {
|
for (NSString *fileName in filesArray) {
|
||||||
NSString *filePath = [cachePath stringByAppendingPathComponent:fileName];
|
NSString *filePath = [cachePath stringByAppendingPathComponent:fileName];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue