mirror of
				https://github.com/SoPat712/YTLitePlus.git
				synced 2025-10-29 20:10:41 -04:00 
			
		
		
		
	Update AppIconOptionsController (Better Interface)
This commit is contained in:
		| @@ -6,6 +6,7 @@ | |||||||
| @property (strong, nonatomic) UIImageView *iconPreview; | @property (strong, nonatomic) UIImageView *iconPreview; | ||||||
| @property (strong, nonatomic) NSArray<NSString *> *appIcons; | @property (strong, nonatomic) NSArray<NSString *> *appIcons; | ||||||
| @property (assign, nonatomic) NSInteger selectedIconIndex; | @property (assign, nonatomic) NSInteger selectedIconIndex; | ||||||
|  | @property (assign, nonatomic) NSInteger defaultIconIndex; | ||||||
|  |  | ||||||
| @end | @end | ||||||
|  |  | ||||||
| @@ -13,35 +14,27 @@ | |||||||
|  |  | ||||||
| - (void)viewDidLoad { | - (void)viewDidLoad { | ||||||
|     [super viewDidLoad]; |     [super viewDidLoad]; | ||||||
|  |      | ||||||
|     self.selectedIconIndex = 0; |     self.selectedIconIndex = 0; | ||||||
|  |     self.defaultIconIndex = 0; | ||||||
|  |      | ||||||
|     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.view addSubview:self.tableView]; |     [self.view addSubview:self.tableView]; | ||||||
|  |      | ||||||
|     UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)]; |     UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)]; | ||||||
|     self.navigationItem.leftBarButtonItem = closeButton; |     self.navigationItem.leftBarButtonItem = closeButton; | ||||||
|  |  | ||||||
|     UIButton *defaultButton = [UIButton buttonWithType:UIButtonTypeSystem]; |  | ||||||
|     defaultButton.frame = CGRectMake(20, 100, 100, 40); |  | ||||||
|     [defaultButton setTitle:@"Default" forState:UIControlStateNormal]; |  | ||||||
|     [defaultButton addTarget:self action:@selector(setDefaultIcon) forControlEvents:UIControlEventTouchUpInside]; |  | ||||||
|     [self.view addSubview:defaultButton]; |  | ||||||
|      |      | ||||||
|     UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeSystem]; |     UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveIcon)]; | ||||||
|     saveButton.frame = CGRectMake(20, 100, 100, 40); |     self.navigationItem.rightBarButtonItem = saveButton; | ||||||
|     [saveButton setTitle:@"Save" forState:UIControlStateNormal]; |      | ||||||
|     [saveButton addTarget:self action:@selector(saveIcon) forControlEvents:UIControlEventTouchUpInside]; |     self.iconPreview = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 80, self.view.bounds.size.height - 80, 60, 60)]; | ||||||
|     [self.view addSubview:saveButton]; |  | ||||||
|  |  | ||||||
|     self.iconPreview = [[UIImageView alloc] initWithFrame:CGRectMake(20, 150, 60, 60)]; |  | ||||||
|     self.iconPreview.layer.cornerRadius = 10.0; |     self.iconPreview.layer.cornerRadius = 10.0; | ||||||
|     self.iconPreview.clipsToBounds = YES; |     self.iconPreview.clipsToBounds = YES; | ||||||
|     [self.view addSubview:self.iconPreview]; |     [self.view addSubview:self.iconPreview]; | ||||||
|          |      | ||||||
|     NSString *path = [[NSBundle mainBundle] pathForResource:@"YTLitePlus" ofType:@"bundle"]; |     NSString *path = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"]; | ||||||
|     NSBundle *bundle = [NSBundle bundleWithPath:path]; |     NSBundle *bundle = [NSBundle bundleWithPath:path]; | ||||||
|     self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"]; |     self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"]; | ||||||
|      |      | ||||||
| @@ -59,31 +52,45 @@ | |||||||
|     if (!cell) { |     if (!cell) { | ||||||
|         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; |         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; | ||||||
|     } |     } | ||||||
|     cell.textLabel.text = [self.appIcons[indexPath.row] lastPathComponent]; |      | ||||||
|  |     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) { |     if (indexPath.row == self.selectedIconIndex) { | ||||||
|         cell.accessoryType = UITableViewCellAccessoryCheckmark; |         cell.accessoryType = UITableViewCellAccessoryCheckmark; | ||||||
|     } else { |     } else { | ||||||
|         cell.accessoryType = UITableViewCellAccessoryNone; |         cell.accessoryType = UITableViewCellAccessoryNone; | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     if (indexPath.row == self.defaultIconIndex) { | ||||||
|  |         cell.textLabel.text = @"Default"; | ||||||
|  |     } | ||||||
|  |      | ||||||
|     return cell; |     return cell; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | ||||||
|     [tableView deselectRowAtIndexPath:indexPath animated:YES]; |     [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||||||
|  |      | ||||||
|     UITableViewCell *previousSelectedCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIconIndex inSection:0]]; |     UITableViewCell *previousSelectedCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIconIndex inSection:0]]; | ||||||
|     previousSelectedCell.accessoryType = UITableViewCellAccessoryNone; |     previousSelectedCell.accessoryType = UITableViewCellAccessoryNone; | ||||||
|  |      | ||||||
|     self.selectedIconIndex = indexPath.row; |     self.selectedIconIndex = indexPath.row; | ||||||
|  |      | ||||||
|     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; |     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; | ||||||
|     selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; |     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]; |     self.iconPreview.image = [self resizedImageWithImage:selectedIconImage]; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (void)saveIcon { | - (void)saveIcon { | ||||||
|     NSString *selectedIcon = self.appIcons[self.selectedIconIndex]; |     NSString *selectedIconPath = self.appIcons[self.selectedIconIndex]; | ||||||
|     [[UIApplication sharedApplication] setAlternateIconName:selectedIcon completionHandler:^(NSError * _Nullable error){ |     [[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) { | ||||||
|         if (error) { |         if (error) { | ||||||
|             NSLog(@"Error setting alternate icon: %@", error.localizedDescription); |             NSLog(@"Error setting alternate icon: %@", error.localizedDescription); | ||||||
|             [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; |             [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 arichornlover
					arichornlover