More changes to AppIconOptionsController UI

This commit is contained in:
arichornlover 2024-04-14 13:20:12 -05:00 committed by GitHub
parent 0a6bbcabeb
commit 74d8510e7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,26 +14,26 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.selectedIconIndex = 0;
self.defaultIconIndex = 0;
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
self.navigationItem.leftBarButtonItem = closeButton;
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)];
self.navigationItem.rightBarButtonItem = saveButton;
self.iconPreview = [[UIImageView alloc] initWithFrame:CGRectMake(20, 150, 60, 60)];
self.iconPreview = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 80, self.view.bounds.size.height - 80, 60, 60)];
self.iconPreview.layer.cornerRadius = 10.0;
self.iconPreview.clipsToBounds = YES;
[self.view addSubview:self.iconPreview];
NSString *path = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"];
@ -52,17 +52,19 @@
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text = [self.appIcons[indexPath.row] lastPathComponent];
UIImage *iconImage = [UIImage imageWithContentsOfFile:self.appIcons[indexPath.row]];
cell.imageView.image = [self resizedImageWithImage:iconImage];
NSString *iconPath = self.appIcons[indexPath.row];
cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension];
UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath];
cell.imageView.image = [self resizedImageWithImage:iconImage];
if (indexPath.row == self.selectedIconIndex) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
if (indexPath.row == self.defaultIconIndex) {
cell.textLabel.text = @"Default";
}
@ -72,19 +74,23 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *previousSelectedCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIconIndex inSection:0]];
previousSelectedCell.accessoryType = UITableViewCellAccessoryNone;
self.selectedIconIndex = indexPath.row;
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
UIImage *selectedIconImage = [UIImage imageWithContentsOfFile:self.appIcons[self.selectedIconIndex]];
NSString *selectedIconPath = self.appIcons[self.selectedIconIndex];
UIImage *selectedIconImage = [UIImage imageWithContentsOfFile:selectedIconPath];
self.iconPreview.image = [self resizedImageWithImage:selectedIconImage];
}
- (void)saveIcon {
NSString *selectedIcon = self.appIcons[self.selectedIconIndex];
[[UIApplication sharedApplication] setAlternateIconName:selectedIcon completionHandler:^(NSError * _Nullable error){
NSString *selectedIconPath = self.appIcons[self.selectedIconIndex];
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];