Update AppIconOptionsController.m

This commit is contained in:
arichornlover 2024-04-30 17:23:38 -05:00 committed by GitHub
parent acac562975
commit 8b51733087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,12 +1,12 @@
#import "AppIconOptionsController.h" #import "AppIconOptionsController.h"
#import <YouTubeHeader/YTAssetLoader.h>
@interface AppIconOptionsController () <UITableViewDataSource, UITableViewDelegate> @interface AppIconOptionsController () <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *tableView; @property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) UIButton *backButton;
@property (strong, nonatomic) NSArray<NSString *> *appIcons; @property (strong, nonatomic) NSArray<NSString *> *appIcons;
@property (assign, nonatomic) NSInteger selectedIconIndex; @property (assign, nonatomic) NSInteger selectedIconIndex;
@property (strong, nonatomic) UIImageView *backButton;
@property (assign, nonatomic) UIUserInterfaceStyle pageStyle;
@end @end
@ -23,17 +23,20 @@
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self; self.tableView.dataSource = self;
self.tableView.delegate = self; self.tableView.delegate = self;
self.tableView.backgroundColor = (self.pageStyle == UIUserInterfaceStyleLight) ? [UIColor whiteColor] : [UIColor blackColor];
[self.view addSubview:self.tableView]; [self.view addSubview:self.tableView];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Back.png" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(back)]; self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:20]} forState:UIControlStateNormal]; [self.backButton setImage:[UIImage imageNamed:@"Back.png" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = backButton; [self.backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[self.backButton setFrame:CGRectMake(0, 0, 24, 24)];
UIBarButtonItem *customBackButton = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
self.navigationItem.leftBarButtonItem = customBackButton;
UIColor *buttonColor = [UIColor colorWithRed:203.0/255.0 green:22.0/255.0 blue:51.0/255.0 alpha:1.0];
UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"arrow.clockwise.circle.fill"] style:UIBarButtonItemStylePlain target:self action:@selector(resetIcon)]; UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"arrow.clockwise.circle.fill"] style:UIBarButtonItemStylePlain target:self action:@selector(resetIcon)];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)]; UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)];
[saveButton setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:203.0/255.0 green:22.0/255.0 blue:51.0/255.0 alpha:1.0], NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:20]} forState:UIControlStateNormal]; [saveButton setTitleTextAttributes:@{NSForegroundColorAttributeName: buttonColor, NSFontAttributeName: [UIFont fontWithName:@"YTSans-Medium" size:17]} forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItems = @[saveButton, resetButton]; self.navigationItem.rightBarButtonItems = @[saveButton, resetButton];
@ -50,6 +53,10 @@
return self.appIcons.count; return self.appIcons.count;
} }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) { if (!cell) {
@ -57,21 +64,14 @@
} }
NSString *iconPath = self.appIcons[indexPath.row]; NSString *iconPath = self.appIcons[indexPath.row];
cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension];
UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath];
cell.imageView.image = iconImage;
cell.backgroundColor = [UIColor whiteColor]; cell.imageView.layer.cornerRadius = 10.0;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.imageView.clipsToBounds = YES;
cell.imageView.frame = CGRectMake(10, 10, 40, 40);
UIImageView *iconImageView = [[UIImageView alloc] initWithImage:iconImage]; cell.textLabel.frame = CGRectMake(60, 10, self.view.frame.size.width - 70, 40);
iconImageView.contentMode = UIViewContentModeScaleAspectFit;
iconImageView.frame = CGRectMake(16, 10, 30, 30);
[cell.contentView addSubview:iconImageView];
UILabel *iconNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, 5, self.view.frame.size.width - 56, 30)];
iconNameLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension];
iconNameLabel.textColor = [UIColor blackColor];
iconNameLabel.font = [UIFont systemFontOfSize:16.0 weight:UIFontWeightMedium];
[cell.contentView addSubview:iconNameLabel];
if (indexPath.row == self.selectedIconIndex) { if (indexPath.row == self.selectedIconIndex) {
cell.accessoryType = UITableViewCellAccessoryCheckmark; cell.accessoryType = UITableViewCellAccessoryCheckmark;
@ -79,10 +79,6 @@
cell.accessoryType = UITableViewCellAccessoryNone; cell.accessoryType = UITableViewCellAccessoryNone;
} }
UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1, cell.contentView.frame.size.width, 1)];
separatorView.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:separatorView];
return cell; return cell;
} }
@ -107,6 +103,7 @@
} }
- (void)saveIcon { - (void)saveIcon {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *selectedIcon = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil; NSString *selectedIcon = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil;
if (selectedIcon) { if (selectedIcon) {
NSString *iconName = [selectedIcon.lastPathComponent stringByDeletingPathExtension]; NSString *iconName = [selectedIcon.lastPathComponent stringByDeletingPathExtension];
@ -131,6 +128,10 @@
} else { } else {
NSLog(@"Alternate icon set successfully"); NSLog(@"Alternate icon set successfully");
[self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"]; [self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
} }
}]; }];
} else { } else {
@ -139,6 +140,7 @@
} else { } else {
NSLog(@"Selected icon path is nil"); NSLog(@"Selected icon path is nil");
} }
});
} }
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {